-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The five slots and the three theories\n\nThe 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:\n\n```typescript\nconst esbuildCommand: string[] = [\n options.esbuildRunner,\n '--bundle', `\"${relativeEntryPath}\"`,\n `--target=${this.props.target ?? toTarget(scope, this.props.runtime)}`,\n '--platform=node',\n // ...\n ...this.externals.map(external => `--external:${external}`),\n ...loaders.map(([ext, name]) => `--loader:${ext}=${name}`),\n ...defines.map(([key, value]) => `--define:${key}=${JSON.stringify(value)}`),\n // ...\n ...this.props.inject ? this.props.inject.map(i => `--inject:\"${i}\"`) : [],\n ...this.props.esbuildArgs ? [toCliArgs(this.props.esbuildArgs)] : [],\n];\n```\n\nFive slots. Five attacker-controllable property sets reaching one shell. Three different sanitization theories visible to the reader:\n\n| Slot | What the source does | The theory |\n|------|----------------------|------------|\n| `externalModules` (line 257) | `` `--external:${external}` `` | Type nothing. |\n| `loader` keys/values (line 258) | `` `--loader:${ext}=${name}` `` | Type nothing. |\n| `define` keys (line 259) | `` `--define:${key}=...` `` | Type nothing. |\n| `define` values (line 259) | `` `...=${JSON.stringify(value)}` `` | Call `JSON.stringify`. |\n| `inject` (line 267) | `` `--inject:\"${i}\"` `` | Type two literal `\"` characters around the interpolation. |\n| `esbuildArgs` (line 268) | `toCliArgs(...)` returns ``${key}=\"${value}\"`` | Type two literal `\"` characters around the interpolation. |\n\nThen `createBundlingCommand` joins the array with single spaces, chains it with the user's `commandHooks`, and `getLocalBundlingProvider` hands the entire string to bash:\n\n```typescript\nexec(\n osPlatform === 'win32' ? 'cmd' : 'bash',\n [\n osPlatform === 'win32' ? '/c' : '-c',\n localCommand,\n ],\n // ...\n);\n```\n\n`bash -c ` evaluates `` 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.\n\n## The PoC reaches for the slot that used no theory\n\nHesham Ashraf's `app.ts`, the PoC at HeshamASH/CVE-2026-11417-AWS-CDK-RCE, uses the `externalModules` slot:\n\n```typescript\nnew NodejsFunction(this, 'VulnerableFunction', {\n entry: path.join(__dirname, 'lambda', 'handler.ts'),\n runtime: Runtime.NODEJS_20_X,\n bundling: {\n externalModules: ['foo & echo CVE-2026-11417 PWNED > ../pwned.txt'],\n },\n});\n```\n\nThe 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:\n\n```\n--external:foo & echo CVE-2026-11417 PWNED > ../pwned.txt\n```\n\nThat 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.\n\nThere 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: `&`.\n\nThe pre-patch supplied `inject` and `esbuildArgs` with a quote wrap and `define` values with `JSON.stringify`. The slot the PoC chose had neither.\n\n## JSON.stringify names JSON\n\nThe `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.\n\nThe 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.\n\nA pre-patch caller with `define: { VERSION: '$(id)' }` produced the token:\n\n```\n--define:VERSION=\"$(id)\"\n```\n\n`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.\n\n`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.\n\n## The typed quote is not a function\n\nThe `inject` slot's pre-patch source is line 267:\n\n```typescript\n...this.props.inject ? this.props.inject.map(i => `--inject:\"${i}\"`) : [],\n```\n\nThe 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.\n\nThe same shape appears in `toCliArgs`, the helper that turns `esbuildArgs` into a CLI string:\n\n```typescript\nfunction toCliArgs(esbuildArgs: { [key: string]: string | boolean }): string {\n const args = new Array();\n const reSpecifiedKeys = ['--alias', '--drop', '--pure', '--log-override', '--out-extension'];\n\n for (const [key, value] of Object.entries(esbuildArgs)) {\n if (value === true || value === '') {\n args.push(key);\n } else if (reSpecifiedKeys.includes(key)) {\n args.push(`${key}:\"${value}\"`);\n } else if (value) {\n args.push(`${key}=\"${value}\"`);\n }\n }\n\n return args.join(' ');\n}\n```\n\nTwo 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.\n\nThe character typed into the source string is not a function. The other six exhibits agree.\n\n## The fix names the shell\n\nPR #37292 lands the missing function at the bottom of the file and gives it a name that encodes its destination:\n\n```typescript\n/**\n * Converts a clean argv array into a single POSIX shell command string.\n * Each argument is escaped if it contains characters that have special\n * meaning in a shell. Safe characters (alphanumeric plus a few punctuation\n * marks commonly found in CLI flags) are left unquoted for readability.\n */\nfunction preparePosixShellCommand(argv: string[]): string {\n return argv.map(posixShellEscape).join(' ');\n}\n\n/**\n * Escapes a single argument for safe inclusion in a POSIX shell command.\n * Every argument is single-quoted unconditionally (like Python's shlex.quote).\n */\nfunction posixShellEscape(arg: string): string {\n return \"'\" + arg.replace(/'/g, \"'\\\\''\") + \"'\";\n}\n```\n\nThe 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.\n\nThe post-patch `createBundlingCommand` builds the esbuild argv as an array of bare strings, no quote characters typed anywhere:\n\n```typescript\nconst esbuildArgv: string[] = [\n options.esbuildRunner,\n '--bundle', relativeEntryPath,\n ...rawArgs,\n ...this.props.esbuildArgs ? toCliArgsArray(this.props.esbuildArgs) : [],\n];\nconst esbuildCommand = preparePosixShellCommand(esbuildArgv);\n```\n\nCompare the post-patch `--define` line in `buildEsbuildArgs` to the pre-patch:\n\n```diff\n- ...defines.map(([key, value]) => `--define:${key}=${JSON.stringify(value)}`),\n+ ...Object.entries(this.props.define ?? {}).map(([key, value]) => `--define:${key}=${value}`),\n```\n\nThe `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`:\n\n```diff\n- ...this.props.inject ? this.props.inject.map(i => `--inject:\"${i}\"`) : [],\n+ ...this.props.inject ? this.props.inject.map(i => `--inject:${i}`) : [],\n```\n\nAnd in the new `toCliArgsArray` (which replaces `toCliArgs`):\n\n```diff\n- args.push(`${key}=\"${value}\"`);\n+ args.push(`${key}=${value}`);\n```\n\nThree 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.\n\nThe 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.\n\n## Supply chain calls this Local\n\nNVD'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.\n\nHesham 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.\n\nThe 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.\n\nCVSS 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.\n\nPoC: [HeshamASH/CVE-2026-11417-AWS-CDK-RCE](https://github.com/HeshamASH/CVE-2026-11417-AWS-CDK-RCE)","closing_line":"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.","hook_md":"`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.","post_id":634,"slug":"aws-cdk-cve-2026-11417-three-theories-none-named-the-shell","title":"CVE-2026-11417: AWS CDK NodejsFunction Built An Esbuild Command Line With Three Theories Of Escape. None Named The Shell.","type":"initial","unreadable_sentence":"JSON.stringify names JSON. Two characters of `\"...\"` name the typist. `posixShellEscape` names the shell. The pre-patch shipped the first two on the same line, ten lines apart, and the third on no line at all."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCauJCqgAKCRDeZjl4jgkQ JmYRAQDEr/vxyZfe2UGzMlWxZreom2l+AMzUmkzv+QX703H1RAEAoh0O7lur0uUM KTMD8Ax5vZt7i9yAs/5trPcsv6oMJws= =SSui -----END PGP SIGNATURE-----