generator icon indicating copy to clipboard operation
generator copied to clipboard

**[SECURITY] Obfuscated malicious code injected into `lib/templates/config/validator.js` in v3.3.1**

Open askasmani opened this issue 4 months ago • 3 comments

Describe the bug.

The published npm tarball for @asyncapi/[email protected] contains obfuscated malicious JavaScript injected into lib/templates/config/validator.js. This code is NOT present in the GitHub source repository — it was injected into the npm-published artifact only.

Looks like all packages:

@asyncapi/[email protected] @asyncapi/[email protected] @asyncapi/[email protected] @asyncapi/[email protected]

Location

File: lib/templates/config/validator.js
Position: Injected on a single line (7,686 characters) between the legitimate isTemplateCompatible() function and the isRequiredParamProvided() function, hidden by excessive whitespace/padding.

What the injected code does

The obfuscated payload:

  1. Imports dangerous modules:

    const fs = require('fs');
    const path = require('path');
    const https = require('https');
    const { spawn } = require('child_process');
    const os = require('os');
    
  2. Spawns a hidden, detached child process:

    spawn(node, ['-e', <obfuscated_payload>], {
      'detached': true,
      'stdio': 'ignore',
      'windowsHide': true
    }).unref();
    
  3. Uses string array rotation obfuscation (_0x2d89, _0x1dd2, _0x1dd48b) with Base64-encoded strings to conceal its true behavior.

  4. The detached process is invisible to the user (windowsHide: true, stdio: 'ignore') and survives the parent process (.unref()).

Obfuscation details

  • Technique: Variable name mangling + string array rotation + Base64 encoding
  • Entry point function names: _0x1dd48b, _0x1dd2, _0x2d89
  • Payload size: 7,686 characters on a single line
  • String array: Contains ~180 Base64-encoded strings in the _0x2d89() function

Evidence snippet

// ... legitimate isTemplateCompatible() function ends ...

const _0x1dd48b=_0x1dd2;(function(_0x3aef98,_0x501ff1){const _0x1cd183=_0x1dd2,
_0x593225=_0x3aef98();while(!![]){try{const _0x268eb2=parseInt(_0x1cd183(0x17c))
/0x1*(parseInt(... [7,686 chars total] ...

// ... legitimate isRequiredParamProvided() function continues ...

Key extraction from the obfuscated code showing the spawn call:

{'detached':!0x0,'stdio':_0x18767a(0x18a),'windowsHide':!0x0})[_0x18767a(0x188)]()

This decodes to:

{ detached: true, stdio: 'ignore', windowsHide: true }).unref()

Verification

The GitHub source for this file does NOT contain the obfuscated code:

# npm tarball (COMPROMISED):
curl -sL https://registry.npmjs.org/@asyncapi/generator/-/generator-3.3.1.tgz \
  | tar -xzO package/lib/templates/config/validator.js \
  | grep -c "_0x"
# Output: 1

# GitHub source (CLEAN):
curl -sL "https://raw.githubusercontent.com/asyncapi/generator/refs/heads/master/packages/generator/lib/templates/config/validator.js" \
  | grep -c "_0x"
# Output: 0

Package details

Field Value
Package @asyncapi/generator
Version 3.3.1
Tarball https://registry.npmjs.org/@asyncapi/generator/-/generator-3.3.1.tgz
SHA 93d8cffab1171a115228808e526d9bd7fe935e4e
Integrity sha512-dEguq/olfuU6QQwKkKeg2N5wEpFIUTQR1uOk/S4GV6FWY4rh2IMp9hP9p5heRT1Z2JC6x1AAedC5yhKY/PQV2w==
Published by GitHub Actions (OIDC trusted publisher)
Compromised file lib/templates/config/validator.js
Payload size 7,686 characters (single obfuscated line)

Expected behavior

The file lib/templates/config/validator.js should contain only the template configuration validation logic as seen in the GitHub source repository — no obfuscated code, no child_process imports, no spawn calls, no hidden process execution.


Recommended immediate actions

  1. Unpublish or deprecate @asyncapi/[email protected] on npm
  2. Audit all versions currently on npm for similar injections
  3. Investigate the build/publish pipeline — the OIDC trusted publisher attestation suggests the compromise may be in the CI/CD workflow, a dependency used during build, or a compromised GitHub Action
  4. Notify downstream users via a security advisory
  5. Rotate all secrets used in the publishing pipeline
  6. File with npm security: npm report @asyncapi/generator

Environment

  • npm registry version inspected: 3.3.1
  • Date of analysis: 2026-07-14
  • Method: Direct tarball download and file extraction from npm registry

Expected behavior

clean package.

Screenshots

N/A

How to Reproduce

  1. I first did this
  2. I then did this
  3. And so on . . .

🖥️ Device Information [optional]

  • Operating System (OS):
  • Browser:
  • Browser Version:

👀 Have you checked for similar open issues?

  • [x] I checked and didn't find similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

None

askasmani avatar Jul 14 '26 08:07 askasmani

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

github-actions[bot] avatar Jul 14 '26 08:07 github-actions[bot]

Hi @askasmani! I'm Dosu and I'm helping the AsyncAPI team.

This has already been reported and is being actively addressed. A more detailed report was filed in issue #2184 by Lidor Machluf / Upwind Security, which includes a full breakdown of the attack chain (including the Stage 2 IPFS downloader and Stage 3 "Miasma RAT" credential stealer) [1].

Maintainer @derberg has confirmed the malicious versions have been reported to npm for removal [1].

Key additional details from the other report that complement your findings:

  • The compromise came via a push to the next branch (commit 3eab3ec9304aa26081358330491d3cfeb55cc245) using an unconfigured git identity ("Your Name" / [email protected]) — the release workflow then auto-published via OIDC.
  • The payload is a two-stage dropper: Stage 1 spawns the detached process you identified, which downloads an 8.25MB sync.js from IPFS and executes it. Stage 3 is a full credential-stealing RAT targeting browser profiles, SSH keys, npm tokens, AWS creds, GitHub CLI, and crypto wallets.
  • C2 server: 85.137.53.71:8081 (NL, AS43641)
  • Safe versions to pin to: @asyncapi/[email protected], @asyncapi/[email protected], @asyncapi/[email protected]

If you installed any affected version, check for and delete the dropped file:

  • Linux: ~/.local/share/NodeJS/sync.js
  • macOS: ~/Library/Application Support/NodeJS/sync.js
  • Windows: %LOCALAPPDATA%\NodeJS\sync.js

And rotate any credentials (npm, GitHub, SSH, AWS, browser passwords) as they should be considered compromised.

To reply, just mention @dosu.


Share context across your team and agents. Try Dosu.

Leave Feedback Learn about generator with Dosu Add Dosu to your team

dosubot[bot] avatar Jul 14 '26 08:07 dosubot[bot]

closing as all the work is tracked under https://github.com/asyncapi/generator/issues/2184

derberg avatar Jul 15 '26 14:07 derberg