From 7cb4e41c0e6c49cda6f13b648e479c11c62d0dd6 Mon Sep 17 00:00:00 2001 From: ogabasseyy Date: Mon, 5 Oct 2026 19:27:26 +0100 Subject: [PATCH 1/4] fix(security): pin busboy 3.2.1 and web_core 0.10.2 floors Transitive overrides for advisories published during #3583: - @fastify/busboy 3.2.1 for CVE-2026-19481 / CVE-2026-19484 (@whatwg-node/node-fetch transitive; alerts 456, 457). - @a2ui/web_core 0.10.2 for CVE-2026-10032 (@copilotkit/a2ui-renderer transitive; alert 455). --- pnpm-lock.yaml | 19 +++++++++++-------- pnpm-workspace.yaml | 6 ++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fefe0d21b02..0824e5ca2c2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -155,6 +155,8 @@ overrides: jsondiffpatch: 0.7.6 '@ai-sdk/provider-utils@>=3 <3.0.28': 3.0.28 '@ai-sdk/provider-utils@>=4 <4.0.33': 4.0.33 + '@fastify/busboy': 3.2.1 + '@a2ui/web_core': 0.10.2 patchedDependencies: '@react-native-community/datetimepicker@9.1.0': d6eebfc80eac2c44c597c97dcf20c6dfa6c2311b8904802b6a846db637e19196 @@ -1360,8 +1362,8 @@ packages: graphql: optional: true - '@a2ui/web_core@0.9.0': - resolution: {integrity: sha512-TsMWuEeuVDsScGIGPy/fWIZu+EOBRfhx6KwjKh3VwY1AwysRenQM8zDr8VrSk14Wck/aBgVxk2zWVrMCK2/s6A==} + '@a2ui/web_core@0.10.2': + resolution: {integrity: sha512-IfS4K7baTL9P9AzUOzKRWzL9A9/+Z7TCgMY2GPwsZ0H7LgY/9/uJnlbReNhpHsAfN12KZtW9iERWkw5HOf71GA==} '@acemir/cssom@0.9.31': resolution: {integrity: sha512-ZnR3GSaH+/vJ0YlHau21FjfLYjMpYVIzTD8M8vIEQvIGxeOXyXdzCI140rrCY862p/C/BbzWsjc1dgnM9mkoTA==} @@ -2744,8 +2746,8 @@ packages: resolution: {integrity: sha512-4aQzz9vgxcNXFfo/iyNgDDYfsU5XGKKxWxZopw0cVotHiW+U8IJbIxMaxsINs6bHhtkG3StKNPcOrn3eBuxKPw==} hasBin: true - '@fastify/busboy@3.2.0': - resolution: {integrity: sha512-m9FVDXU3GT2ITSe0UaMA5rU3QkfC/UXtCU8y0gSN/GugTqtVldOBWIB5V6V3sbmenVZUIpU6f+mPEO2+m5iTaA==} + '@fastify/busboy@3.2.1': + resolution: {integrity: sha512-tgK4O+57iz5ycYNGXE5ZWj1ES03lD2XnnBYWSbU/3wYZRMQzCUq7Ycds/RdyBZQeL5MU4fxBt6lzbIWf/Bickw==} '@firebase/ai@2.9.0': resolution: {integrity: sha512-NPvBBuvdGo9x3esnABAucFYmqbBmXvyTMimBq2PCuLZbdANZoHzGlx7vfzbwNDaEtCBq4RGGNMliLIv6bZ+PtA==} @@ -10532,6 +10534,7 @@ packages: path-dirname@1.0.2: resolution: {integrity: sha512-ALzNPpyNq9AqXMBjeymIjFDAkAFH06mHJH/cSBHAgU0s4vfpBn6b2nf8tiRLvagKD8RbTpq2FKTBg7cl9l3c7Q==} + deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. path-exists@3.0.0: resolution: {integrity: sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==} @@ -12991,7 +12994,7 @@ snapshots: optionalDependencies: graphql: 16.14.2 - '@a2ui/web_core@0.9.0': + '@a2ui/web_core@0.10.2': dependencies: '@preact/signals-core': 1.14.2 date-fns: 4.4.0 @@ -13971,7 +13974,7 @@ snapshots: '@copilotkit/a2ui-renderer@1.60.1(react-dom@19.2.3(react@19.2.3))(react@19.2.3)': dependencies: - '@a2ui/web_core': 0.9.0 + '@a2ui/web_core': 0.10.2 clsx: 2.1.1 react: 19.2.3 react-dom: 19.2.3(react@19.2.3) @@ -15208,7 +15211,7 @@ snapshots: chalk: 4.1.2 js-yaml: 4.3.2 - '@fastify/busboy@3.2.0': {} + '@fastify/busboy@3.2.1': {} '@firebase/ai@2.9.0(@firebase/app-types@0.9.3)(@firebase/app@0.14.9)': dependencies: @@ -19316,7 +19319,7 @@ snapshots: '@whatwg-node/node-fetch@0.8.6': dependencies: - '@fastify/busboy': 3.2.0 + '@fastify/busboy': 3.2.1 '@whatwg-node/disposablestack': 0.0.6 '@whatwg-node/promise-helpers': 1.3.2 tslib: 2.8.1 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 8c812501a35..a9d26f9945e 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -323,6 +323,12 @@ overrides: # uncontrolled-resource-consumption advisory. "@ai-sdk/provider-utils@>=3 <3.0.28": "3.0.28" "@ai-sdk/provider-utils@>=4 <4.0.33": "4.0.33" + # Pin @fastify/busboy 3.2.1 for CVE-2026-19481 / CVE-2026-19484 + # (@whatwg-node/node-fetch transitive). + "@fastify/busboy": "3.2.1" + # Pin @a2ui/web_core 0.10.2 for CVE-2026-10032 + # (@copilotkit/a2ui-renderer transitive). + "@a2ui/web_core": "0.10.2" patchedDependencies: # Backport the upstream 0.5.0 linear-time fallback decoder to CJS 0.2.2: fixes the # exponential-decoding DoS while keeping query-string@7 (expo-router) compatible. From 9a1e293fe28e73045217f4378b674b4419f1fb65 Mon Sep 17 00:00:00 2001 From: ogabasseyy Date: Tue, 6 Oct 2026 08:30:14 +0100 Subject: [PATCH 2/4] fix(deps): busboy 3.2.2 for CVE-2026-74866, add A2UI openUrl regression test - Bump @fastify/busboy override 3.2.1 -> 3.2.2 (GHSA-gxm5-99cw-xjw9: CRLF injection via multipart Content-Disposition filename/name affects all versions below 3.2.2) + regen lockfile. - Add apps/web/a2ui-openurl-integrity.test.ts: pins @a2ui/web_core >= 0.10.2 and behaviorally verifies openUrl rejects javascript:/ data:/vbscript:/file: URLs (CVE-2026-10032). Verified 2/2 fail on 0.10.1 and 2/2 pass on 0.10.2. Addresses Codex P1 threads on PR #3632. --- apps/web/a2ui-openurl-integrity.test.ts | 161 ++++++++++++++++++++++++ pnpm-lock.yaml | 10 +- pnpm-workspace.yaml | 5 +- 3 files changed, 169 insertions(+), 7 deletions(-) create mode 100644 apps/web/a2ui-openurl-integrity.test.ts diff --git a/apps/web/a2ui-openurl-integrity.test.ts b/apps/web/a2ui-openurl-integrity.test.ts new file mode 100644 index 00000000000..70625d5c5df --- /dev/null +++ b/apps/web/a2ui-openurl-integrity.test.ts @@ -0,0 +1,161 @@ +/** @vitest-environment node */ + +import { readFileSync } from 'node:fs'; +import { createRequire } from 'node:module'; +import { dirname, join } from 'node:path'; +import { pathToFileURL } from 'node:url'; +import { describe, expect, it } from 'vitest'; + +// Regression coverage for CVE-2026-10032: `@a2ui/web_core` `openUrl` permitted +// `javascript:` URI execution via agent-supplied button actions. Fixed in +// 0.10.2 (see the `pnpm-workspace.yaml` override). This mirrors the upstream +// package's own openUrl test through the installed dependency so a future +// override downgrade fails loudly instead of silently reintroducing the XSS. + +const require = createRequire(import.meta.url); +// Resolve through an exported subpath (the package's `exports` map hides +// `./package.json`): `@a2ui/web_core/v0_9` -> `/src/v0_9/index.js`. +const webCoreEntry = require.resolve('@a2ui/web_core/v0_9'); +const resolvedRoot = dirname(dirname(dirname(webCoreEntry))); +// Verification hook only: point at an unpacked @a2ui/web_core tarball to +// confirm this test fails on pre-fix releases. Unset in normal runs. +const webCoreRoot = process.env.A2UI_WEB_CORE_ROOT ?? resolvedRoot; +const webCorePackageJsonPath = join(webCoreRoot, 'package.json'); + +// First release containing the openUrl protocol allowlist. +const FIRST_FIXED = [0, 10, 2] as const; + +function parseVersion(version: string): [number, number, number] { + const parts = version.split('.').map((part) => Number.parseInt(part, 10)); + if (parts.length !== 3 || parts.some((part) => !Number.isInteger(part))) { + throw new Error(`Unexpected @a2ui/web_core version: ${version}`); + } + return parts as [number, number, number]; +} + +function isAtLeast( + actual: [number, number, number], + minimum: readonly [number, number, number] +): boolean { + for (let index = 0; index < 3; index += 1) { + if (actual[index] !== minimum[index]) { + return actual[index] > minimum[index]; + } + } + return true; +} + +interface TestCatalog { + invoker: ( + name: string, + args: Record, + context: unknown + ) => unknown; +} + +interface CatalogConstructor { + new (id: string, components: unknown[], functions: unknown[]): TestCatalog; +} + +interface DataModelConstructor { + new (initialData?: Record): unknown; +} + +interface DataContextConstructor { + new (surface: unknown, path: string): unknown; +} + +async function loadWebCore() { + const moduleUrl = (relativePath: string): string => + pathToFileURL(join(webCoreRoot, relativePath)).href; + const [functionsModule, dataModelModule, dataContextModule, catalogModule] = + (await Promise.all([ + import(moduleUrl('src/v0_9/basic_catalog/functions/basic_functions.js')), + import(moduleUrl('src/v0_9/state/data-model.js')), + import(moduleUrl('src/v0_9/rendering/data-context.js')), + import(moduleUrl('src/v0_9/catalog/types.js')), + ])) as [ + { BASIC_FUNCTIONS: unknown[] }, + { DataModel: DataModelConstructor }, + { DataContext: DataContextConstructor }, + { Catalog: CatalogConstructor }, + ]; + return { functionsModule, dataModelModule, dataContextModule, catalogModule }; +} + +describe('@a2ui/web_core openUrl integrity (CVE-2026-10032)', () => { + it('resolves a web_core release containing the openUrl fix', () => { + const webCorePackage = JSON.parse( + readFileSync(webCorePackageJsonPath, 'utf8') + ) as { version?: string }; + expect(typeof webCorePackage.version).toBe('string'); + const actual = parseVersion(webCorePackage.version as string); + expect(isAtLeast(actual, FIRST_FIXED)).toBe(true); + }); + + it('rejects javascript: and other non-http(s) action URLs', async () => { + const { + functionsModule, + dataModelModule, + dataContextModule, + catalogModule, + } = await loadWebCore(); + const catalog = new catalogModule.Catalog( + 'integrity', + [], + functionsModule.BASIC_FUNCTIONS + ); + const model = new dataModelModule.DataModel({}); + const context = new dataContextModule.DataContext( + { + dataModel: model, + catalog: { invoker: catalog.invoker }, + dispatchError: () => {}, + }, + '/' + ); + + const globalRef = globalThis as unknown as { window?: unknown }; + const originalWindow = globalRef.window; + let openedUrl = ''; + let openedSpecs = ''; + globalRef.window = { + location: { href: 'https://example.com/sub/page' }, + open: (url: string, _target: string, specs: string) => { + openedUrl = url; + openedSpecs = specs; + }, + }; + try { + const maliciousInputs = [ + 'javascript:alert(document.domain)', + ' javascript:alert(1)', + 'javascript://%0Aalert(1)', + 'data:text/html,', + 'vbscript:msgbox("hello")', + 'file:///etc/passwd', + ]; + for (const input of maliciousInputs) { + openedUrl = ''; + let thrown: unknown; + try { + catalog.invoker('openUrl', { url: input }, context); + } catch (error) { + thrown = error; + } + expect( + thrown instanceof Error && + thrown.message.includes('Unsupported URL scheme'), + `Expected "${input}" to throw an Unsupported URL scheme error` + ).toBe(true); + expect(openedUrl).toBe(''); + } + + catalog.invoker('openUrl', { url: 'https://example.com/' }, context); + expect(openedUrl).toBe('https://example.com/'); + expect(openedSpecs).toBe('noopener,noreferrer'); + } finally { + globalRef.window = originalWindow; + } + }); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cf2dd3013ce..6b9c67bf48c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -155,7 +155,7 @@ overrides: jsondiffpatch: 0.7.6 '@ai-sdk/provider-utils@>=3 <3.0.28': 3.0.28 '@ai-sdk/provider-utils@>=4 <4.0.33': 4.0.33 - '@fastify/busboy': 3.2.1 + '@fastify/busboy': 3.2.2 '@a2ui/web_core': 0.10.2 patchedDependencies: @@ -2758,8 +2758,8 @@ packages: resolution: {integrity: sha512-4aQzz9vgxcNXFfo/iyNgDDYfsU5XGKKxWxZopw0cVotHiW+U8IJbIxMaxsINs6bHhtkG3StKNPcOrn3eBuxKPw==} hasBin: true - '@fastify/busboy@3.2.1': - resolution: {integrity: sha512-tgK4O+57iz5ycYNGXE5ZWj1ES03lD2XnnBYWSbU/3wYZRMQzCUq7Ycds/RdyBZQeL5MU4fxBt6lzbIWf/Bickw==} + '@fastify/busboy@3.2.2': + resolution: {integrity: sha512-yXSS27qPExaXeuLvMRMXOLtpipzfQYNjG3FkunDWKGfMYjKuhFXko9CVzqxm8jcF+lmtS9Fd89QNdh9XDjnbNg==} '@firebase/ai@2.9.0': resolution: {integrity: sha512-NPvBBuvdGo9x3esnABAucFYmqbBmXvyTMimBq2PCuLZbdANZoHzGlx7vfzbwNDaEtCBq4RGGNMliLIv6bZ+PtA==} @@ -15227,7 +15227,7 @@ snapshots: chalk: 4.1.2 js-yaml: 4.3.2 - '@fastify/busboy@3.2.1': {} + '@fastify/busboy@3.2.2': {} '@firebase/ai@2.9.0(@firebase/app-types@0.9.3)(@firebase/app@0.14.9)': dependencies: @@ -19335,7 +19335,7 @@ snapshots: '@whatwg-node/node-fetch@0.8.6': dependencies: - '@fastify/busboy': 3.2.1 + '@fastify/busboy': 3.2.2 '@whatwg-node/disposablestack': 0.0.6 '@whatwg-node/promise-helpers': 1.3.2 tslib: 2.8.1 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index a9d26f9945e..9af348858b9 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -323,9 +323,10 @@ overrides: # uncontrolled-resource-consumption advisory. "@ai-sdk/provider-utils@>=3 <3.0.28": "3.0.28" "@ai-sdk/provider-utils@>=4 <4.0.33": "4.0.33" - # Pin @fastify/busboy 3.2.1 for CVE-2026-19481 / CVE-2026-19484 + # Pin @fastify/busboy 3.2.2 for CVE-2026-19481 / CVE-2026-19484 / + # CVE-2026-74866 (CRLF injection via Content-Disposition filename/name). # (@whatwg-node/node-fetch transitive). - "@fastify/busboy": "3.2.1" + "@fastify/busboy": "3.2.2" # Pin @a2ui/web_core 0.10.2 for CVE-2026-10032 # (@copilotkit/a2ui-renderer transitive). "@a2ui/web_core": "0.10.2" From 0945171ed72584867bcf5c59e57e55e3c0cecaa7 Mon Sep 17 00:00:00 2001 From: ogabasseyy Date: Tue, 6 Oct 2026 08:40:05 +0100 Subject: [PATCH 3/4] fix(security): add busboy CRLF regression test, harden A2UI test - Add apps/web/busboy-crlf-integrity.test.ts: pins @fastify/busboy >= 3.2.2 and mirrors the upstream 'rejects bare CR or LF' test (8 disposition vectors incl. RFC 5987 filename*/name* forms). Verified 2 fail + control passes on 3.2.1, 3/3 pass on 3.2.2. - A2UI test: document the deep-import coupling (fail-closed note) and assert throw + never-opened instead of exact error wording. Addresses Codex P1 + 2 low threads on PR #3632. --- apps/web/a2ui-openurl-integrity.test.ts | 17 ++- apps/web/busboy-crlf-integrity.test.ts | 145 ++++++++++++++++++++++++ 2 files changed, 157 insertions(+), 5 deletions(-) create mode 100644 apps/web/busboy-crlf-integrity.test.ts diff --git a/apps/web/a2ui-openurl-integrity.test.ts b/apps/web/a2ui-openurl-integrity.test.ts index 70625d5c5df..27be4f0cc05 100644 --- a/apps/web/a2ui-openurl-integrity.test.ts +++ b/apps/web/a2ui-openurl-integrity.test.ts @@ -66,6 +66,12 @@ interface DataContextConstructor { } async function loadWebCore() { + // NOTE: these deep imports intentionally bypass the package's `exports` + // map, which exposes only the v0_8/v0_9 entry points — the openUrl + // implementation is not reachable through the public surface. This couples + // the test to web_core's internal file layout: if a future release + // restructures these paths, the import fails loudly (fail-closed) and this + // test must be updated alongside the override bump. const moduleUrl = (relativePath: string): string => pathToFileURL(join(webCoreRoot, relativePath)).href; const [functionsModule, dataModelModule, dataContextModule, catalogModule] = @@ -143,11 +149,12 @@ describe('@a2ui/web_core openUrl integrity (CVE-2026-10032)', () => { } catch (error) { thrown = error; } - expect( - thrown instanceof Error && - thrown.message.includes('Unsupported URL scheme'), - `Expected "${input}" to throw an Unsupported URL scheme error` - ).toBe(true); + // Security property: the URL is rejected (throws) and never + // opened. Deliberately not asserting the exact upstream error + // wording so a message reword that keeps the allowlist stays green. + expect(thrown instanceof Error, `Expected "${input}" to throw`).toBe( + true + ); expect(openedUrl).toBe(''); } diff --git a/apps/web/busboy-crlf-integrity.test.ts b/apps/web/busboy-crlf-integrity.test.ts new file mode 100644 index 00000000000..57e58864cb2 --- /dev/null +++ b/apps/web/busboy-crlf-integrity.test.ts @@ -0,0 +1,145 @@ +/** @vitest-environment node */ + +import { readFileSync } from 'node:fs'; +import { createRequire } from 'node:module'; +import { dirname, join } from 'node:path'; +import { describe, expect, it } from 'vitest'; + +// Regression coverage for CVE-2026-74866 (GHSA-gxm5-99cw-xjw9): +// `@fastify/busboy` retained bare CR/LF characters in multipart +// Content-Disposition `filename`/`name` parameters (including RFC 5987 +// `filename*`/`name*` percent-encoded forms), enabling log, filesystem, or +// downstream-header injection. Fixed in 3.2.2 (see the +// `pnpm-workspace.yaml` override), which skips parts with bare line breaks. +// Mirrors the upstream `rejects bare CR or LF in disposition parameters` +// test so a future override downgrade fails loudly. + +const require = createRequire(import.meta.url); +const resolvedPackageJsonPath = require.resolve('@fastify/busboy/package.json'); +// Verification hook only: point at an unpacked @fastify/busboy tarball to +// confirm this test fails on pre-fix releases. Unset in normal runs. +const busboyRoot = process.env.BUSBOY_ROOT ?? dirname(resolvedPackageJsonPath); +const busboyPackageJsonPath = join(busboyRoot, 'package.json'); + +// First release that skips parts with bare CR/LF in name/filename. +const FIRST_FIXED = [3, 2, 2] as const; + +function parseVersion(version: string): [number, number, number] { + const parts = version.split('.').map((part) => Number.parseInt(part, 10)); + if (parts.length !== 3 || parts.some((part) => !Number.isInteger(part))) { + throw new Error(`Unexpected @fastify/busboy version: ${version}`); + } + return parts as [number, number, number]; +} + +function isAtLeast( + actual: [number, number, number], + minimum: readonly [number, number, number] +): boolean { + for (let index = 0; index < 3; index += 1) { + if (actual[index] !== minimum[index]) { + return actual[index] > minimum[index]; + } + } + return true; +} + +interface BusboyInstance { + on: (event: string, listener: (...args: never[]) => void) => void; + once: (event: string, listener: (...args: never[]) => void) => void; + end: (data?: unknown) => void; +} + +interface BusboyConstructor { + new (options: { headers: Record }): BusboyInstance; +} + +function loadBusboy(): BusboyConstructor { + const moduleExports = require(join(busboyRoot, 'index.js')) as unknown; + if (typeof moduleExports === 'function') { + return moduleExports as BusboyConstructor; + } + const named = moduleExports as { Busboy?: BusboyConstructor }; + if (typeof named.Busboy === 'function') { + return named.Busboy; + } + throw new Error(`Cannot load Busboy constructor from ${busboyRoot}`); +} + +function buildBody(parts: string[][], boundary: string): string { + const separator = `--${boundary}`; + return `${parts.map((part) => [separator, ...part].join('\r\n')).join('\r\n')}\r\n${separator}--\r\n`; +} + +async function parseDisposition( + Busboy: BusboyConstructor, + disposition: string +): Promise<{ emitted: boolean; names: string[] }> { + const boundary = 'integritycrlf'; + const body = buildBody( + [[`Content-Disposition: ${disposition}`, '', 'value']], + boundary + ); + const busboy = new Busboy({ + headers: { 'content-type': `multipart/form-data; boundary=${boundary}` }, + }); + let emitted = false; + const names: string[] = []; + busboy.on('field', (name: string) => { + emitted = true; + names.push(name); + }); + busboy.on('file', (name: string, stream: { resume: () => void }) => { + emitted = true; + names.push(name); + stream.resume(); + }); + busboy.end(Buffer.from(body, 'binary')); + await new Promise((resolve, reject) => { + busboy.once('finish', () => resolve()); + busboy.once('error', (error: Error) => reject(error)); + }); + return { emitted, names }; +} + +describe('@fastify/busboy CRLF integrity (CVE-2026-74866)', () => { + it('resolves a busboy release containing the CRLF fix', () => { + const busboyPackage = JSON.parse( + readFileSync(busboyPackageJsonPath, 'utf8') + ) as { version?: string }; + expect(typeof busboyPackage.version).toBe('string'); + const actual = parseVersion(busboyPackage.version as string); + expect(isAtLeast(actual, FIRST_FIXED)).toBe(true); + }); + + it('skips parts with bare CR or LF in name/filename', async () => { + const Busboy = loadBusboy(); + const maliciousDispositions = [ + 'form-data; name="field\rname"', + 'form-data; name="field\nname"', + 'form-data; name="field"; filename="file\rname.txt"', + 'form-data; name="field"; filename="file\nname.txt"', + "form-data; name*=utf-8''field%0Dname", + "form-data; name*=utf-8''field%0Aname", + "form-data; name=field; filename*=utf-8''file%0Dname.txt", + "form-data; name=field; filename*=utf-8''file%0Aname.txt", + ]; + for (const disposition of maliciousDispositions) { + const { emitted, names } = await parseDisposition(Busboy, disposition); + expect( + emitted, + `Expected no event for ${disposition} (got: ${names.join(', ')})` + ).toBe(false); + } + }); + + it('still parses well-formed parts', async () => { + const Busboy = loadBusboy(); + const { emitted, names } = await parseDisposition( + Busboy, + 'form-data; name="field"' + ); + expect(emitted).toBe(true); + expect(names).toEqual(['field']); + }); +}); From 77f8f72d63b29b8241431d3280378ac41aea79d8 Mon Sep 17 00:00:00 2001 From: ogabasseyy Date: Tue, 6 Oct 2026 08:53:40 +0100 Subject: [PATCH 4/4] fix(security): behavioral tests for busboy DoS CVEs, harden test guards - busboy-integrity.test.ts (renamed from -crlf-): add prototype-header case (CVE-2026-19481) and timeout-controlled child-process 252-byte boundary case (CVE-2026-19484), both mirroring upstream 3.2.1 tests; resolve the package entry via its own main field (3.2.0 uses lib/main). Matrix: 5/5 on 3.2.2; DoS pass + gate/CRLF fail on 3.2.1; gate + all behavioral fail (boundary hits the 2s kill) with control green on 3.2.0. - A2UI test: assert thrown instanceof A2uiExpressionError (precise, reword-safe) instead of any-throw. - Both suites: refuse the *_ROOT verification override under CI and warn when it is active locally. Addresses Codex P1 + 3 low threads on PR #3632. --- apps/web/a2ui-openurl-integrity.test.ts | 83 ++++++--- apps/web/busboy-crlf-integrity.test.ts | 145 --------------- apps/web/busboy-integrity.test.ts | 235 ++++++++++++++++++++++++ 3 files changed, 295 insertions(+), 168 deletions(-) delete mode 100644 apps/web/busboy-crlf-integrity.test.ts create mode 100644 apps/web/busboy-integrity.test.ts diff --git a/apps/web/a2ui-openurl-integrity.test.ts b/apps/web/a2ui-openurl-integrity.test.ts index 27be4f0cc05..4431c195849 100644 --- a/apps/web/a2ui-openurl-integrity.test.ts +++ b/apps/web/a2ui-openurl-integrity.test.ts @@ -17,10 +17,31 @@ const require = createRequire(import.meta.url); // `./package.json`): `@a2ui/web_core/v0_9` -> `/src/v0_9/index.js`. const webCoreEntry = require.resolve('@a2ui/web_core/v0_9'); const resolvedRoot = dirname(dirname(dirname(webCoreEntry))); -// Verification hook only: point at an unpacked @a2ui/web_core tarball to -// confirm this test fails on pre-fix releases. Unset in normal runs. -const webCoreRoot = process.env.A2UI_WEB_CORE_ROOT ?? resolvedRoot; -const webCorePackageJsonPath = join(webCoreRoot, 'package.json'); + +function resolveRoot(): { root: string; packageJsonPath: string } { + const override = process.env.A2UI_WEB_CORE_ROOT; + if (override !== undefined) { + // Verification hook only: point at an unpacked @a2ui/web_core tarball + // to confirm this test fails on pre-fix releases. Refused under CI so + // a green run always guards the workspace-resolved dependency. + if (process.env.CI !== undefined) { + throw new Error( + 'A2UI_WEB_CORE_ROOT is set in CI; refusing to test a non-installed copy' + ); + } + console.warn( + `[integrity-test] testing web_core from override: ${override}` + ); + return { root: override, packageJsonPath: join(override, 'package.json') }; + } + return { + root: resolvedRoot, + packageJsonPath: join(resolvedRoot, 'package.json'), + }; +} + +const { root: webCoreRoot, packageJsonPath: webCorePackageJsonPath } = + resolveRoot(); // First release containing the openUrl protocol allowlist. const FIRST_FIXED = [0, 10, 2] as const; @@ -74,19 +95,32 @@ async function loadWebCore() { // test must be updated alongside the override bump. const moduleUrl = (relativePath: string): string => pathToFileURL(join(webCoreRoot, relativePath)).href; - const [functionsModule, dataModelModule, dataContextModule, catalogModule] = - (await Promise.all([ - import(moduleUrl('src/v0_9/basic_catalog/functions/basic_functions.js')), - import(moduleUrl('src/v0_9/state/data-model.js')), - import(moduleUrl('src/v0_9/rendering/data-context.js')), - import(moduleUrl('src/v0_9/catalog/types.js')), - ])) as [ - { BASIC_FUNCTIONS: unknown[] }, - { DataModel: DataModelConstructor }, - { DataContext: DataContextConstructor }, - { Catalog: CatalogConstructor }, - ]; - return { functionsModule, dataModelModule, dataContextModule, catalogModule }; + const [ + functionsModule, + dataModelModule, + dataContextModule, + catalogModule, + errorsModule, + ] = (await Promise.all([ + import(moduleUrl('src/v0_9/basic_catalog/functions/basic_functions.js')), + import(moduleUrl('src/v0_9/state/data-model.js')), + import(moduleUrl('src/v0_9/rendering/data-context.js')), + import(moduleUrl('src/v0_9/catalog/types.js')), + import(moduleUrl('src/v0_9/errors.js')), + ])) as [ + { BASIC_FUNCTIONS: unknown[] }, + { DataModel: DataModelConstructor }, + { DataContext: DataContextConstructor }, + { Catalog: CatalogConstructor }, + { A2uiExpressionError: new (...args: never[]) => Error }, + ]; + return { + functionsModule, + dataModelModule, + dataContextModule, + catalogModule, + errorsModule, + }; } describe('@a2ui/web_core openUrl integrity (CVE-2026-10032)', () => { @@ -105,6 +139,7 @@ describe('@a2ui/web_core openUrl integrity (CVE-2026-10032)', () => { dataModelModule, dataContextModule, catalogModule, + errorsModule, } = await loadWebCore(); const catalog = new catalogModule.Catalog( 'integrity', @@ -149,12 +184,14 @@ describe('@a2ui/web_core openUrl integrity (CVE-2026-10032)', () => { } catch (error) { thrown = error; } - // Security property: the URL is rejected (throws) and never - // opened. Deliberately not asserting the exact upstream error - // wording so a message reword that keeps the allowlist stays green. - expect(thrown instanceof Error, `Expected "${input}" to throw`).toBe( - true - ); + // Security property: the openUrl validator itself rejects the + // URL (A2uiExpressionError, not an incidental TypeError from the + // mock) and the URL is never opened. The error type — not its + // exact wording — keeps this robust to upstream message rewords. + expect( + thrown instanceof errorsModule.A2uiExpressionError, + `Expected "${input}" to throw A2uiExpressionError` + ).toBe(true); expect(openedUrl).toBe(''); } diff --git a/apps/web/busboy-crlf-integrity.test.ts b/apps/web/busboy-crlf-integrity.test.ts deleted file mode 100644 index 57e58864cb2..00000000000 --- a/apps/web/busboy-crlf-integrity.test.ts +++ /dev/null @@ -1,145 +0,0 @@ -/** @vitest-environment node */ - -import { readFileSync } from 'node:fs'; -import { createRequire } from 'node:module'; -import { dirname, join } from 'node:path'; -import { describe, expect, it } from 'vitest'; - -// Regression coverage for CVE-2026-74866 (GHSA-gxm5-99cw-xjw9): -// `@fastify/busboy` retained bare CR/LF characters in multipart -// Content-Disposition `filename`/`name` parameters (including RFC 5987 -// `filename*`/`name*` percent-encoded forms), enabling log, filesystem, or -// downstream-header injection. Fixed in 3.2.2 (see the -// `pnpm-workspace.yaml` override), which skips parts with bare line breaks. -// Mirrors the upstream `rejects bare CR or LF in disposition parameters` -// test so a future override downgrade fails loudly. - -const require = createRequire(import.meta.url); -const resolvedPackageJsonPath = require.resolve('@fastify/busboy/package.json'); -// Verification hook only: point at an unpacked @fastify/busboy tarball to -// confirm this test fails on pre-fix releases. Unset in normal runs. -const busboyRoot = process.env.BUSBOY_ROOT ?? dirname(resolvedPackageJsonPath); -const busboyPackageJsonPath = join(busboyRoot, 'package.json'); - -// First release that skips parts with bare CR/LF in name/filename. -const FIRST_FIXED = [3, 2, 2] as const; - -function parseVersion(version: string): [number, number, number] { - const parts = version.split('.').map((part) => Number.parseInt(part, 10)); - if (parts.length !== 3 || parts.some((part) => !Number.isInteger(part))) { - throw new Error(`Unexpected @fastify/busboy version: ${version}`); - } - return parts as [number, number, number]; -} - -function isAtLeast( - actual: [number, number, number], - minimum: readonly [number, number, number] -): boolean { - for (let index = 0; index < 3; index += 1) { - if (actual[index] !== minimum[index]) { - return actual[index] > minimum[index]; - } - } - return true; -} - -interface BusboyInstance { - on: (event: string, listener: (...args: never[]) => void) => void; - once: (event: string, listener: (...args: never[]) => void) => void; - end: (data?: unknown) => void; -} - -interface BusboyConstructor { - new (options: { headers: Record }): BusboyInstance; -} - -function loadBusboy(): BusboyConstructor { - const moduleExports = require(join(busboyRoot, 'index.js')) as unknown; - if (typeof moduleExports === 'function') { - return moduleExports as BusboyConstructor; - } - const named = moduleExports as { Busboy?: BusboyConstructor }; - if (typeof named.Busboy === 'function') { - return named.Busboy; - } - throw new Error(`Cannot load Busboy constructor from ${busboyRoot}`); -} - -function buildBody(parts: string[][], boundary: string): string { - const separator = `--${boundary}`; - return `${parts.map((part) => [separator, ...part].join('\r\n')).join('\r\n')}\r\n${separator}--\r\n`; -} - -async function parseDisposition( - Busboy: BusboyConstructor, - disposition: string -): Promise<{ emitted: boolean; names: string[] }> { - const boundary = 'integritycrlf'; - const body = buildBody( - [[`Content-Disposition: ${disposition}`, '', 'value']], - boundary - ); - const busboy = new Busboy({ - headers: { 'content-type': `multipart/form-data; boundary=${boundary}` }, - }); - let emitted = false; - const names: string[] = []; - busboy.on('field', (name: string) => { - emitted = true; - names.push(name); - }); - busboy.on('file', (name: string, stream: { resume: () => void }) => { - emitted = true; - names.push(name); - stream.resume(); - }); - busboy.end(Buffer.from(body, 'binary')); - await new Promise((resolve, reject) => { - busboy.once('finish', () => resolve()); - busboy.once('error', (error: Error) => reject(error)); - }); - return { emitted, names }; -} - -describe('@fastify/busboy CRLF integrity (CVE-2026-74866)', () => { - it('resolves a busboy release containing the CRLF fix', () => { - const busboyPackage = JSON.parse( - readFileSync(busboyPackageJsonPath, 'utf8') - ) as { version?: string }; - expect(typeof busboyPackage.version).toBe('string'); - const actual = parseVersion(busboyPackage.version as string); - expect(isAtLeast(actual, FIRST_FIXED)).toBe(true); - }); - - it('skips parts with bare CR or LF in name/filename', async () => { - const Busboy = loadBusboy(); - const maliciousDispositions = [ - 'form-data; name="field\rname"', - 'form-data; name="field\nname"', - 'form-data; name="field"; filename="file\rname.txt"', - 'form-data; name="field"; filename="file\nname.txt"', - "form-data; name*=utf-8''field%0Dname", - "form-data; name*=utf-8''field%0Aname", - "form-data; name=field; filename*=utf-8''file%0Dname.txt", - "form-data; name=field; filename*=utf-8''file%0Aname.txt", - ]; - for (const disposition of maliciousDispositions) { - const { emitted, names } = await parseDisposition(Busboy, disposition); - expect( - emitted, - `Expected no event for ${disposition} (got: ${names.join(', ')})` - ).toBe(false); - } - }); - - it('still parses well-formed parts', async () => { - const Busboy = loadBusboy(); - const { emitted, names } = await parseDisposition( - Busboy, - 'form-data; name="field"' - ); - expect(emitted).toBe(true); - expect(names).toEqual(['field']); - }); -}); diff --git a/apps/web/busboy-integrity.test.ts b/apps/web/busboy-integrity.test.ts new file mode 100644 index 00000000000..fb3978d369f --- /dev/null +++ b/apps/web/busboy-integrity.test.ts @@ -0,0 +1,235 @@ +/** @vitest-environment node */ + +import { spawnSync } from 'node:child_process'; +import { readFileSync } from 'node:fs'; +import { createRequire } from 'node:module'; +import { dirname, join } from 'node:path'; +import { describe, expect, it } from 'vitest'; + +// Regression coverage for the three `@fastify/busboy` CVEs behind the +// `pnpm-workspace.yaml` override (fixed releases: 3.2.1 for the two DoS +// advisories, 3.2.2 for CRLF; the pin targets 3.2.2 which supersedes both): +// +// - CVE-2026-19481 (GHSA-x8mw-p69m-v3mx): DoS via prototype-named multipart +// part headers (`__proto__`/`constructor` crashed the dicer header parser, +// which stored headers on a plain `{}`). +// - CVE-2026-19484 (GHSA-xjh9-v7x6-24jw): DoS via oversized multipart +// boundary (the Boyer-Moore-Horspool occurrence table was a Uint8Array, so +// a 252-byte boundary wrapped the shift to zero and looped forever). +// - CVE-2026-74866 (GHSA-gxm5-99cw-xjw9): CRLF injection via multipart +// Content-Disposition `filename`/`name` (including RFC 5987 `*` forms). +// +// Each behavioral case mirrors its upstream regression test so a future +// override downgrade fails loudly instead of silently restoring the parser +// bugs. The boundary case runs in a timeout-controlled child process so a +// vulnerable implementation cannot hang Vitest. + +const require = createRequire(import.meta.url); +const resolvedPackageJsonPath = require.resolve('@fastify/busboy/package.json'); + +function resolveRoot(): { root: string; packageJsonPath: string } { + const override = process.env.BUSBOY_ROOT; + if (override !== undefined) { + // Verification hook only: point at an unpacked @fastify/busboy tarball + // to confirm this test fails on pre-fix releases. Refused under CI so a + // green run always guards the workspace-resolved dependency. + if (process.env.CI !== undefined) { + throw new Error( + 'BUSBOY_ROOT is set in CI; refusing to test a non-installed copy' + ); + } + console.warn(`[integrity-test] testing busboy from override: ${override}`); + return { root: override, packageJsonPath: join(override, 'package.json') }; + } + const root = dirname(resolvedPackageJsonPath); + return { root, packageJsonPath: join(root, 'package.json') }; +} + +const { root: busboyRoot, packageJsonPath: busboyPackageJsonPath } = + resolveRoot(); + +// First release containing all three fixes. +const FIRST_FIXED = [3, 2, 2] as const; + +function parseVersion(version: string): [number, number, number] { + const parts = version.split('.').map((part) => Number.parseInt(part, 10)); + if (parts.length !== 3 || parts.some((part) => !Number.isInteger(part))) { + throw new Error(`Unexpected @fastify/busboy version: ${version}`); + } + return parts as [number, number, number]; +} + +function isAtLeast( + actual: [number, number, number], + minimum: readonly [number, number, number] +): boolean { + for (let index = 0; index < 3; index += 1) { + if (actual[index] !== minimum[index]) { + return actual[index] > minimum[index]; + } + } + return true; +} + +interface BusboyInstance { + on: (event: string, listener: (...args: never[]) => void) => void; + once: (event: string, listener: (...args: never[]) => void) => void; + end: (data?: unknown) => void; +} + +interface BusboyConstructor { + new (options: { headers: Record }): BusboyInstance; +} + +function readPackageMain(): string { + const busboyPackage = JSON.parse( + readFileSync(busboyPackageJsonPath, 'utf8') + ) as { main?: string }; + return busboyPackage.main ?? 'index.js'; +} + +function loadBusboy(): BusboyConstructor { + const moduleExports = require(join(busboyRoot, readPackageMain())) as unknown; + if (typeof moduleExports === 'function') { + return moduleExports as BusboyConstructor; + } + const named = moduleExports as { Busboy?: BusboyConstructor }; + if (typeof named.Busboy === 'function') { + return named.Busboy; + } + throw new Error(`Cannot load Busboy constructor from ${busboyRoot}`); +} + +function buildBody(parts: string[][], boundary: string): string { + const separator = `--${boundary}`; + return `${parts.map((part) => [separator, ...part].join('\r\n')).join('\r\n')}\r\n${separator}--\r\n`; +} + +async function collectField( + Busboy: BusboyConstructor, + headers: string[], + boundary: string +): Promise<{ fields: [string, string][]; finished: boolean }> { + const body = buildBody([[...headers, '', 'value']], boundary); + const busboy = new Busboy({ + headers: { 'content-type': `multipart/form-data; boundary=${boundary}` }, + }); + const fields: [string, string][] = []; + busboy.on('field', (name: string, value: string) => { + fields.push([name, value]); + }); + busboy.end(Buffer.from(body, 'binary')); + await new Promise((resolve, reject) => { + busboy.once('finish', () => resolve()); + busboy.once('error', (error: Error) => reject(error)); + }); + return { fields, finished: true }; +} + +async function parseDisposition( + Busboy: BusboyConstructor, + disposition: string +): Promise<{ emitted: boolean; names: string[] }> { + const boundary = 'integritycrlf'; + const body = buildBody( + [[`Content-Disposition: ${disposition}`, '', 'value']], + boundary + ); + const busboy = new Busboy({ + headers: { 'content-type': `multipart/form-data; boundary=${boundary}` }, + }); + let emitted = false; + const names: string[] = []; + busboy.on('field', (name: string) => { + emitted = true; + names.push(name); + }); + busboy.on('file', (name: string, stream: { resume: () => void }) => { + emitted = true; + names.push(name); + stream.resume(); + }); + busboy.end(Buffer.from(body, 'binary')); + await new Promise((resolve, reject) => { + busboy.once('finish', () => resolve()); + busboy.once('error', (error: Error) => reject(error)); + }); + return { emitted, names }; +} + +describe('@fastify/busboy integrity (CVE-2026-19481/19484/74866)', () => { + it('resolves a busboy release containing all three fixes', () => { + const busboyPackage = JSON.parse( + readFileSync(busboyPackageJsonPath, 'utf8') + ) as { version?: string }; + expect(typeof busboyPackage.version).toBe('string'); + const actual = parseVersion(busboyPackage.version as string); + expect(isAtLeast(actual, FIRST_FIXED)).toBe(true); + }); + + it('tolerates prototype-named part headers (CVE-2026-19481)', async () => { + const Busboy = loadBusboy(); + for (const name of ['__proto__', 'constructor']) { + const { fields, finished } = await collectField( + Busboy, + ['Content-Disposition: form-data; name="field"', `${name}: injected`], + 'prototypeheader' + ); + expect(finished).toBe(true); + expect(fields).toEqual([['field', 'value']]); + } + }); + + it('processes a fragmented 252-byte boundary without hanging (CVE-2026-19484)', () => { + const entryPath = join(busboyRoot, readPackageMain()); + const script = [ + `const Busboy = require(${JSON.stringify(entryPath)})`, + "const boundary = 'A'.repeat(252)", + 'const parser = new Busboy({', + " headers: { 'content-type': 'multipart/form-data; boundary=' + boundary },", + '})', + "parser.write(Buffer.from('--' + boundary.slice(0, -1)))", + "parser.write(Buffer.from('X'), (error) => process.exit(error ? 1 : 0))", + 'setTimeout(() => process.exit(1), 500)', + ].join('\n'); + const result = spawnSync(process.execPath, ['-e', script], { + timeout: 2000, + }); + expect({ + error: result.error?.message, + signal: result.signal, + status: result.status, + }).toEqual({ error: undefined, signal: null, status: 0 }); + }); + + it('skips parts with bare CR or LF in name/filename (CVE-2026-74866)', async () => { + const Busboy = loadBusboy(); + const maliciousDispositions = [ + 'form-data; name="field\rname"', + 'form-data; name="field\nname"', + 'form-data; name="field"; filename="file\rname.txt"', + 'form-data; name="field"; filename="file\nname.txt"', + "form-data; name*=utf-8''field%0Dname", + "form-data; name*=utf-8''field%0Aname", + "form-data; name=field; filename*=utf-8''file%0Dname.txt", + "form-data; name=field; filename*=utf-8''file%0Aname.txt", + ]; + for (const disposition of maliciousDispositions) { + const { emitted, names } = await parseDisposition(Busboy, disposition); + expect( + emitted, + `Expected no event for ${disposition} (got: ${names.join(', ')})` + ).toBe(false); + } + }); + + it('still parses well-formed parts', async () => { + const Busboy = loadBusboy(); + const { emitted, names } = await parseDisposition( + Busboy, + 'form-data; name="field"' + ); + expect(emitted).toBe(true); + expect(names).toEqual(['field']); + }); +});