Repository navigation
Conversation
Export `hasPrototypePollution` in `dynamic-value-strategy.ts` and wrap the v1.0 MCP catalog processor with `filterAllowedV10McpMessages` so only valid, unpolluted v1.0 surface update messages reach `processMessages`.
Add a `hasPrototypePollution` guard at the entry of `V09WireValidator.validateRenderItem` to match the v1.0 wire validator. Return early in `HostCommunication.messageListener` when an incoming `SEND_TO_SERVER` payload fails validation so invalid envelopes are never emitted on `messageStream$` or stored in `latestEnvelope` / `messageHistoryBuffer`.
Escape backticks as `\u0060` across single- and multi-catalog prompt serialization to prevent Markdown code-fence breakouts. Wrap MCP tool metadata in `<mcp_tools>...</mcp_tools>` and user custom instructions in `<custom_instructions>...</custom_instructions>` with closing-tag escaping, single-line tool metadata sanitization, and reinforcing data/precedence postambles.
There was a problem hiding this comment.
Code Review
This pull request introduces robust prototype pollution checks and prompt injection hardening across the codebase. Specifically, it adds a hasPrototypePollution utility to inspect nested structures, filters incoming MCP tool response messages to drop disallowed or polluted payloads, wraps custom user instructions and MCP tools in XML-style delimiters with closing-tag escaping, and escapes backticks in serialized catalogs to prevent markdown code-fence breakouts. The reviewer pointed out a security improvement in hasPrototypePollution where the prototype of arrays should also be validated to prevent prototype pollution via array subclasses.
There was a problem hiding this comment.
Code Review
This pull request introduces robust security hardening against prototype pollution and prompt injection. It adds a hasPrototypePollution utility to inspect nested structures, integrates message filtering in the MCP catalog to drop disallowed or polluted messages, and escapes backticks and XML-style tags in prompt strategies to prevent code-fence breakout. Additionally, it validates incoming host communication messages for prototype pollution. The review feedback correctly identifies two important issues: a potential security bypass in hasPrototypePollution where recursion uses Object.keys instead of Object.getOwnPropertyNames (missing non-enumerable properties), and a bug in isAllowedV10McpMessage that incorrectly rejects valid messages containing explicit undefined values.
⚡ A2UI Composer PR PreviewYour automated preview is successfully live (commit
|
Fail closed in `resolveDynamicTree` when `depth >= MAX_RESOLUTION_DEPTH`
by returning `{}` for objects and `[]` for arrays instead of the raw
unstripped input.
On the unchanged-result short-circuit, recurse into `resolveDynamicTree`
with `NO_OP_RESOLVE_EXPRESSION` so passthrough `args` and extra v0.9 own
properties are sanitized without re-evaluating expressions.
Back `SYNONYM_MAP` and `buildComponentHealMap` with null-prototype objects and guard all `componentsObj`, `healMap`, and `SYNONYM_MAP` lookups in `healComponentInstance` with `Object.hasOwn` so `Object.prototype` keys (`toString`, `valueOf`, `hasOwnProperty`, `constructor`, `__proto__`) are rejected. Extract `takeWireProp` to replace unquoted object rest-destructuring in `normalizeV10RpcEnvelopeItem` with shallow copies, bracket access, and `delete` so property renaming cannot break normalization.
Validate array prototypes against Array.prototype or null and iterate Object.getOwnPropertyNames(val) for both arrays and objects in hasPrototypePollution so array subclasses, own pollution keys on arrays, and pollution nested inside non-enumerable properties are rejected. Ignore top-level keys with undefined values in isAllowedV10McpMessage so valid v1.0 messages with explicit undefined sibling update keys are accepted while non-undefined disallowed keys continue to be dropped.
Summary
Hardens untrusted boundary handling across the v1.0 MCP bridge, cross-frame message validation, payload healing/normalization, and system prompt construction:
Bridge v1.0 MCP Response Filtering (
bba63d74):hasPrototypePollution(val, maxDepth = 64)inbridge/src/mcp/dynamic-value-strategy.tsreusingisPrototypePollutionKeyand checkingObject.getPrototypeOf,Object.getOwnPropertyNames, nested objects/arrays, and recursion depth.rawProcessorincreateMcpFunctionsCatalog(bridge/src/mcp/v1-0-mcp-catalog.ts) withfilterAllowedV10McpMessages/isAllowedV10McpMessageso untrusted MCP tool and resource responses are restricted to single-operation v1.0 surface-update messages (createSurface,updateComponents,updateDataModel,deleteSurface) free of prototype pollution and extra top-level keys, blocking injected RPC control messages (callRendererFunction,agentFunctionResponse,callAgentFunctionResponse) while keeping v0.9 and v1.0 paths separate.Shell Cross-Frame & Host Communication Validation (
3ffce3a6):hasPrototypePollution(item)guard at the entry ofV09WireValidator.validateRenderItem(shell/src/app/shell/cross-frame-validator/v0-9-wire-validator.ts), matchingV10WireValidator.validateRenderItem.HostCommunication.messageListener(shell/src/app/shell/host-communication/host-communication.ts) when an incomingSEND_TO_SERVERpayload failsCrossFrameValidator.validateIncomingMessageso invalid envelopes never reachrecordEnvelope,messageStream$,latestEnvelope(), orgetEnvelopeHistory().Prompt Code-Fence & Delimiter Hardening (
23ef0b0e):\u0060across single- and multi-catalog JSON serialization (serializeCatalogForPromptandserializeCatalogsForPrompt) to prevent Markdown code-fence breakouts.<mcp_tools>...</mcp_tools>with single-line sanitization, backtick escaping, case-preserving closing-tag escaping (HTML and JSON modes, covering trailing attributes and self-closing slashes), and a reinforcing data-only postamble.customInstructionsin<custom_instructions>...</custom_instructions>with closing-tag escaping and a precedence postamble across bothV09PromptStrategyandV10PromptStrategy.Bridge
resolveDynamicTreeFail-Closed Depth Limit & Unchanged-Branch Sanitization (5ffcacac):resolveDynamicTree(bridge/src/mcp/dynamic-value-strategy.ts) whendepth >= MAX_RESOLUTION_DEPTH, returning[]for arrays and{}for non-null objects instead of returning unstripped deep structures verbatim.exprResult.unchanged || exprResult.value === value), recurse intoresolveDynamicTreewithNO_OP_RESOLVE_EXPRESSIONso passthroughargsand extra v0.9 own properties have prototype-pollution keys stripped andMAX_RESOLUTION_DEPTHenforced without re-evaluating expressions.bridge/src/mcp/v0-9-dynamic-value-strategy.spec.tsandbridge/src/mcp/v1-0-dynamic-value-strategy.spec.ts.Shell
component-name-healerPrototype-Lookup Guard &a2ui-rpc-envelopeClosure-Safe Deletion (d29d24fd):SYNONYM_MAPandbuildComponentHealMapwith null-prototype objects (Object.create(null)) and guard all lookups oncomponentsObj,healMap, andSYNONYM_MAPinhealComponentInstance(shell/src/app/chat/a2ui-payload-parser/component-name-healer.ts) withObject.hasOwn, rejectingObject.prototypekeys (toString,valueOf,hasOwnProperty,constructor,Constructor,__proto__) even on externally supplied plain objects.shell/src/app/chat/a2ui-payload-parser/component-name-healer.spec.tscovering positive healing/synonym behavior and prototype-key rejection.takeWirePropinshell/src/app/shared/a2ui-rpc-envelope.tsto replace unquoted object rest-destructuring innormalizeV10RpcEnvelopeItemwith shallow copies, bracket property reads, anddeleteso Closure property renaming cannot break normalization.Verification
corepack yarn prettier:check— passedcorepack yarn tsc— passedcorepack yarn lint— passedcorepack yarn build— passedcorepack yarn test— passed (rootscripts/*.test.mjs: 48 tests;a2ui-bridge: 18 files / 353 tests;lit-basic-catalog: 3 files / 26 tests;ng-basic-catalog: 4 files / 34 tests;react-basic-catalog: 4 files / 26 tests;react-slack-catalog: 14 files / 197 tests;a2ui-composer-shell: 123 files / 3048 tests, 94.25% stmts / 87.99% branches / 95.2% funcs / 94.96% lines)E2E_HEADLESS=true corepack yarn --cwd shell playwright test --project=e2e e2e/cross-frame-security.e2e.ts e2e/user-journey.e2e.ts— 13 passed (pre-helper-extraction on7e211ce0)