//nefariousplan

CVE-2026-11417: AWS CDK NodejsFunction Built An Esbuild Command Line With Three Theories Of Escape. None Named The Shell.

vendor

patterns

cve

proof of concept

aws-cdk-lib's aws-lambda-nodejs/lib/bundling.ts builds the esbuild command line for the NodejsFunction construct by interpolating five attacker-controllable property sets, externalModules, loader, define, inject, and esbuildArgs, into an array of strings, joining the array on space, and passing the joined line to bash -c (or cmd /c on Windows). The five slots are visible in createBundlingCommand between lines 247 and 269 of v2.244.0. The author tried to keep the line safe in three different ways across those slots: by typing nothing, by calling JSON.stringify, and by wrapping the interpolation between two literal " characters typed into the TypeScript source. Amazon's bulletin AWS-2026-041 calls the result CVE-2026-11417 and CVSS 7.3. Hesham Ashraf's PoC, published on 2026-06-13, reaches for the slot that used the first theory. The 2.245.0 patch (PR #37292) removes the second and third.

The five slots and the three theories

The pre-patch createBundlingCommand builds the esbuild invocation as an array literal in TypeScript, then joins it with ' ', then feeds the joined string to a shell. The slots are at the end of the array, between lines 247 and 269 of packages/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts in v2.244.0:

const esbuildCommand: string[] = [
  options.esbuildRunner,
  '--bundle', `"${relativeEntryPath}"`,
  `--target=${this.props.target ?? toTarget(scope, this.props.runtime)}`,
  '--platform=node',
  // ...
  ...this.externals.map(external => `--external:${external}`),
  ...loaders.map(([ext, name]) => `--loader:${ext}=${name}`),
  ...defines.map(([key, value]) => `--define:${key}=${JSON.stringify(value)}`),
  // ...
  ...this.props.inject ? this.props.inject.map(i => `--inject:"${i}"`) : [],
  ...this.props.esbuildArgs ? [toCliArgs(this.props.esbuildArgs)] : [],
];

Five slots. Five attacker-controllable property sets reaching one shell. Three different sanitization theories visible to the reader:

Slot What the source does The theory
externalModules (line 257) `--external:${external}` Type nothing.
loader keys/values (line 258) `--loader:${ext}=${name}` Type nothing.
define keys (line 259) `--define:${key}=...` Type nothing.
define values (line 259) `...=${JSON.stringify(value)}` Call JSON.stringify.
inject (line 267) `--inject:"${i}"` Type two literal " characters around the interpolation.
esbuildArgs (line 268) toCliArgs(...) returns ${key}="${value}" Type two literal " characters around the interpolation.

Then createBundlingCommand joins the array with single spaces, chains it with the user's commandHooks, and getLocalBundlingProvider hands the entire string to bash:

exec(
  osPlatform === 'win32' ? 'cmd' : 'bash',
  [
    osPlatform === 'win32' ? '/c' : '-c',
    localCommand,
  ],
  // ...
);

bash -c <string> evaluates <string> under the shell's command grammar. Every byte in that string is read as either a token, an operator, or a quoted region. Whether the original TypeScript author meant for a particular byte to be an operator is not a question the shell asks.

The PoC reaches for the slot that used no theory

Hesham Ashraf's app.ts, the PoC at HeshamASH/CVE-2026-11417-AWS-CDK-RCE, uses the externalModules slot:

new NodejsFunction(this, 'VulnerableFunction', {
  entry: path.join(__dirname, 'lambda', 'handler.ts'),
  runtime: Runtime.NODEJS_20_X,
  bundling: {
    externalModules: ['foo & echo CVE-2026-11417 PWNED > ../pwned.txt'],
  },
});

The pre-patch's line 257 reads each element of this.externals and produces `--external:${external}`. For this PoC, the produced token is the 56-character string:

--external:foo & echo CVE-2026-11417 PWNED > ../pwned.txt

That string is joined into the larger command line and handed to bash. Bash reads --external:foo as a single token, reads the next byte as &, treats & as the asynchronous-background operator, terminates the first command, and begins parsing the rest of the line as a new statement. The new statement is echo CVE-2026-11417 PWNED > ../pwned.txt. Bash runs it. The file appears.

There is no escape function externalModules failed to call. The slot was wired straight from the user-controllable string array to a shell command line through a backtick template literal that interpolated the value with no transformation. The PoC's payload is a single byte: &.

The pre-patch supplied inject and esbuildArgs with a quote wrap and define values with JSON.stringify. The slot the PoC chose had neither.

JSON.stringify names JSON

The define slot's JSON.stringify(value) produces a JSON-encoded string. JSON's escape grammar covers ", \, control characters, and the unpaired Unicode noncharacters. JSON does not escape $, the backtick, ;, &, |, or >, because none of those characters has any meaning to a JSON parser.

The destination is bash. Bash inside a double-quoted region honors ", \\ (collapsing to \), \$ (collapsing to $), \``, and ", and treats $(...), ${...}, and backticks as command substitutions. ;, &, |, and >are literals inside double quotes. The coincidences between the two grammars are partial: JSON's"happens to read as bash's escaped double-quote, JSON's\` happens to read as bash's escaped backslash. The non-coincidences are the holes.

A pre-patch caller with define: { VERSION: '$(id)' } produced the token:

--define:VERSION="$(id)"

JSON.stringify("$(id)") returns the four-character JSON literal "$(id)". The shell sees --define:VERSION= followed by a double-quoted region containing $(id). The shell performs command substitution inside the double-quoted region. The id command runs. The output of id is interpolated into the argument bash hands esbuild.

JSON.stringify did exactly what its name encoded. The threat model the function name addresses is "produce a string the JSON parser will read back as the value I started with." The function's name does not encode shell metacharacters because JSON does not have shell metacharacters. The author called the function whose name described JSON. The bytes flowed through bash. The shell was not the sink the function name named, even though the shell was the sink the bytes reached.

The typed quote is not a function

The inject slot's pre-patch source is line 267:

...this.props.inject ? this.props.inject.map(i => `--inject:"${i}"`) : [],

The two " characters around ${i} are typed into a TypeScript template literal. They are not a function call. The TypeScript compiler emits them as two ASCII bytes in the resulting string. Bash reads those two bytes as the boundary characters of a double-quoted region. Whatever bytes lie between them are read inside that region. The shell's grammar for what closes a double-quoted region is "the next unescaped "". The TypeScript author's intent does not enter the shell's parser.

The same shape appears in toCliArgs, the helper that turns esbuildArgs into a CLI string:

function toCliArgs(esbuildArgs: { [key: string]: string | boolean }): string {
  const args = new Array<string>();
  const reSpecifiedKeys = ['--alias', '--drop', '--pure', '--log-override', '--out-extension'];

  for (const [key, value] of Object.entries(esbuildArgs)) {
    if (value === true || value === '') {
      args.push(key);
    } else if (reSpecifiedKeys.includes(key)) {
      args.push(`${key}:"${value}"`);
    } else if (value) {
      args.push(`${key}="${value}"`);
    }
  }

  return args.join(' ');
}

Two more typed " characters around ${value}. The pattern this catalog names quote-wrap-is-not-escape has prior exhibits in PHP, C, Node, and Elixir. The author typed apostrophes, the author typed double-quotes; the author did not call the function. In every prior exhibit the function existed elsewhere in the same project: AVideo had escapeshellarg forty-seven non-vendor call sites away, GL.iNet had execve in adjacent paths, browser-tools-mcp had spawn with array arguments one import away, Phoenix Storybook had inspect/2. aws-cdk's case is the same shape one more time, in TypeScript: the function existed nowhere in the pre-patch tree, but the team wrote it in the same PR that closed the CVE.

The character typed into the source string is not a function. The other six exhibits agree.

The fix names the shell

PR #37292 lands the missing function at the bottom of the file and gives it a name that encodes its destination:

/**
 * Converts a clean argv array into a single POSIX shell command string.
 * Each argument is escaped if it contains characters that have special
 * meaning in a shell. Safe characters (alphanumeric plus a few punctuation
 * marks commonly found in CLI flags) are left unquoted for readability.
 */
function preparePosixShellCommand(argv: string[]): string {
  return argv.map(posixShellEscape).join(' ');
}

/**
 * Escapes a single argument for safe inclusion in a POSIX shell command.
 * Every argument is single-quoted unconditionally (like Python's shlex.quote).
 */
function posixShellEscape(arg: string): string {
  return "'" + arg.replace(/'/g, "'\\''") + "'";
}

The function's name is posixShellEscape. The docstring names its model: Python's shlex.quote. The implementation is the canonical shlex.quote, single-quoting unconditionally and escaping any embedded single quote as '\''. The destination is the function's name.

The post-patch createBundlingCommand builds the esbuild argv as an array of bare strings, no quote characters typed anywhere:

const esbuildArgv: string[] = [
  options.esbuildRunner,
  '--bundle', relativeEntryPath,
  ...rawArgs,
  ...this.props.esbuildArgs ? toCliArgsArray(this.props.esbuildArgs) : [],
];
const esbuildCommand = preparePosixShellCommand(esbuildArgv);

Compare the post-patch --define line in buildEsbuildArgs to the pre-patch:

- ...defines.map(([key, value]) => `--define:${key}=${JSON.stringify(value)}`),
+ ...Object.entries(this.props.define ?? {}).map(([key, value]) => `--define:${key}=${value}`),

The JSON.stringify is gone. The patch took it out because JSON.stringify was sanitization that had named the wrong destination, and the wrap function that does name the right destination now runs at the boundary of every token. The same diff appears at --inject:

- ...this.props.inject ? this.props.inject.map(i => `--inject:"${i}"`) : [],
+ ...this.props.inject ? this.props.inject.map(i => `--inject:${i}`) : [],

And in the new toCliArgsArray (which replaces toCliArgs):

-     args.push(`${key}="${value}"`);
+     args.push(`${key}=${value}`);

Three sites lose three typed " pairs and one JSON.stringify call. The bytes those calls were trying to neutralize are now neutralized at exactly one place, the function whose name encodes the destination.

The Docker bundling path still hands bash -c a joined string at v2.245.0's line 201, byte-identical to v2.244.0's line 200. The difference is that bash -c now receives a string in which every token came through posixShellEscape. The shell is still the shell. The bytes that reach it no longer name a second command. Local-path bundling went further: PR #37292 redesigns getLocalBundlingProvider around a BundlingStep discriminated union (spawn, shell, callback), and the spawn variant calls exec(step.command[0], step.command.slice(1), ...) directly without a shell at all. shell steps remain for the user-supplied commandHooks, which the construct's documented contract has always told users run under a shell.

Supply chain calls this Local

NVD's CVSS 3.1 vector for CVE-2026-11417 is AV:L/AC:L/PR:L/UI:R/S:U/C:H/I:H/A:H. AV:L says the attack vector is Local. PR:L says the attacker needs Low privileges on the target. UI:R says user interaction is Required.

Hesham Ashraf's writeup describes a different threat. An attacker publishes a CDK construct package to npm or files a pull request against an open-source CDK app. The package's TypeScript spreads its bundling properties into the caller's NodejsFunction. The caller installs the package on their workstation or their CI runner, runs cdk synth, and the construct hits the v2.244.0 createBundlingCommand path with attacker-controlled externalModules. npm install --ignore-scripts does not help because the payload is not in a postinstall hook; it is in TypeScript source that runs at synth time. npm audit does not help because the malicious package has no advisory. Lockfile integrity does not help because the package is installed correctly; it is the construct's runtime behavior that ships the attack.

The CVSS vector calls the attacker's privilege level Low because the attacker's code is running, at the moment of exploitation, as the developer's user on the developer's host. The attacker reached that position by writing a TypeScript class and uploading it to a package registry. The "User Interaction" the vector requires is cdk synth, a command the developer runs continuously through the day as they edit infrastructure. The "Local" attack vector is the npm registry.

CVSS vectors describe the immediate executor. CVE records describe what the PoC author demonstrated. Neither describes the supply chain the construct's design admitted. The pre-patch's three theories named JSON and named the typist; the-shell-was-not-the-sink names the destination none of them named.

PoC: HeshamASH/CVE-2026-11417-AWS-CDK-RCE

The patch did not add an escape function where there was none. It removed three attempts at escape that named the wrong destination, and added one that named the right one.