[PR #3834] [CLOSED] fix(process): reject the __proto__ environment name the PTY backend drops #5935

Closed
opened 2026-10-31 01:10:33 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/3834
Author: @skyvanguard
Created: 10/15/2026
Status: ❌ Closed

Base: main ← Head: fix/process-scenario-proto-environment


📝 Commits (2)

  • 673f0c1 fix(process): reject the proto environment name the PTY backend drops
  • b099a83 test(process): validate the advertised environment contract over MCP

📊 Changes

8 files changed (+300 additions, -48 deletions)

View changed files

📝 docs/process-capture.md (+4 -1)
📝 src/contracts/sessionToolContracts.ts (+1 -1)
➕ src/domain/ownKeyRecordSchema.test.ts (+41 -0)
➕ src/domain/ownKeyRecordSchema.ts (+116 -0)
📝 src/domain/portableSchemaPatterns.test.ts (+38 -16)
📝 src/domain/process/processScenario.ts (+51 -21)
📝 tests/boundary/process/processCli.test.ts (+14 -4)
📝 tests/boundary/process/processSessionMcp.test.ts (+35 -5)

📄 Description

Summary

Fixes #3338. capture-process accepted an environment entry named __proto__ and silently dropped it, so the child ran with a different input than the caller selected. REA now rejects that name before launch with an actionable diagnostic, in the CLI and over MCP.

Problem and expected behavior

Two layers lose the entry:

  1. Scenario parsing (REA). zod 4.4.3 z.record skips the own key "__proto__" without validating or reporting it ($ZodRecord: if (key === "__proto__") continue;). processScenarioSchema.environment is such a record, so parsing succeeded without the entry.
  2. PTY launch (dependency). @lydell/node-pty 1.1.0 copies opt.env with utils.assign, which does target[key] = source[key] (unixTerminal.js:47). Assigning __proto__ on a plain object calls the prototype setter, so the copy drops it before the child's environment is built. Upstream node-pty 1.1.0 has the same assign.

Because of (2), preserving the entry in the schema alone would make the recorded scenario claim an override the child never received. The contract REA can keep is: an accepted override reaches the child, and an override that cannot reach it is rejected visibly.

Change and scope

  • src/domain/ownKeyRecordSchema.ts: a string-keyed record that validates an own __proto__ member with the same key and value schemas instead of skipping it. If the key schema accepts it, it is kept as an ordinary data property in its original position. It is built from a refinement plus overwrite rather than a transform, so input JSON Schema projections keep an enclosing .default({}). It advertises exactly the z.record JSON Schema.
  • src/domain/process/processScenario.ts: the RE2-safe complement pattern now excludes a set of reserved names. With one name it reproduces the previous pattern byte for byte. __proto__ joins REA_PROCESS_RUN_ID, with a diagnostic that points to the /usr/bin/env __proto__=VALUE workaround from the report. The reporter verified that workaround on macOS; it was not re-run here. environment uses the record helper, so the key schema actually sees __proto__.
  • Trade-off: like the existing refine + overwrite schemas, the refinement and the overwrite each parse the (small) environment map once. The projection override lives on the returned instances, so derivations such as .describe() must not be applied to the helper's result. This is documented on the helper.
  • Tool description and docs/process-capture.md state the rejection.

Not included:

  • No change to node-pty; the upstream report is microsoft/node-pty#993. Once a release with that fix reaches @lydell/node-pty, accepting the name again only requires removing the reservation.
  • nativeCallObservationInputSchema.environment uses the same z.record shape and likely drops __proto__ the same way. Its debugger launch path differs and could not be verified here.
  • Over MCP, the SDK's input-validation text shows the record's generic Invalid key in record for reserved keys, without the nested reason. This already happens for REA_PROCESS_RUN_ID.

Contract and boundary impact

  • Semantic owner and earliest changed stage: processScenarioSchema (request parsing), before any launch.
  • Contribution scope fit and linked maintainer decision: not applicable (fix within an existing boundary).
  • CLI and MCP/tool-catalog contract: capture_process_scenario now rejects environment.__proto__. The advertised propertyNames.pattern excludes it and the description mentions it. Before the reservation was added, the input and output JSON Schema projections were byte-identical to main after switching to the helper.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: scenarios that previously parsed with a silently dropped __proto__ entry are now rejected; no Evidence shape changes.
  • Target selection, authority, upstream behavior, and cleanup details: not applicable; rejection happens before launch.
  • Generated metadata: the tool description changes; npm run docs:check passes.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

(None apply. The change only rejects input before launch.)

Evidence and regression coverage

  • Tests added or updated:

    • src/domain/portableSchemaPatterns.test.ts: the look-ahead equivalence covers both reserved names, plus the __proto__ diagnostic at ["environment", "__proto__"].
    • tests/boundary/process/processCli.test.ts: the CLI reports both reserved keys with the projected issue.
    • tests/boundary/process/processSessionMcp.test.ts: MCP rejects REA_PROCESS_RUN_ID and a JSON-parsed __proto__ before launch; the marker file stays absent. The input schema that tools/list advertises, compiled with Ajv 2020, admits an ordinary override and rejects both names.
    • src/domain/ownKeyRecordSchema.test.ts: the accepted-__proto__ branch (data property, position, untouched prototype), value-issue paths, and JSON Schema parity with z.record.
  • Base reproduction (executed): replacing the helper with z.record(environmentName, childProcessString) (reservation kept) makes the new domain, CLI and MCP __proto__ tests fail, because the entry is accepted and dropped silently. Removing the __proto__ reservation makes the advertised-contract assertion fail (expected true to be false).

  • node-pty (executed against the installed package's utils.assign):

    scenario env own keys: [ '__proto__', 'NORMAL_CAPTURE_KEY' ]
    node-pty assign() own keys: [ 'NORMAL_CAPTURE_KEY' ]
    spread own keys: [ '__proto__', 'NORMAL_CAPTURE_KEY' ]
    
  • Independent macOS confirmation (observed by @1052326311 in this thread, not by the author): on macOS arm64 with the locked @lydell/node-pty and a real PTY, the child omitted an own __proto__ entry while receiving the control, and the /usr/bin/env __proto__=VALUE workaround delivered both values.

  • User-visible CLI output (details.issues of the invalid_request error):

    {
      "path": ["environment", "__proto__"],
      "reason": "invalid_format",
      "expected": "regex",
      "message": "__proto__ cannot reach the captured process because the PTY backend drops it before launch; run /usr/bin/env with __proto__=VALUE before the command instead"
    }
    
  • Remaining proof gaps: validation ran on Windows, where native process capture is unavailable by design. No PTY capture of this PR's revision has run on Linux or macOS, and repository CI is awaiting workflow approval. The node-pty drop and the workaround are confirmed by the macOS check above, which did not exercise this PR's fail-closed path.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

Windows 11, Node.js 24.19.0:

  • npx tsc --noEmit -p tsconfig.json: passed.
  • npm run check:fast: passed.
  • npx oxfmt --check / npx oxlint on changed files: passed; no new warnings.
  • npm run test:local -- src/domain/ownKeyRecordSchema.test.ts src/domain/portableSchemaPatterns.test.ts src/domain/process/processScenario.test.ts src/domain/inputIssueProjection.test.ts: 26 passed.
  • npm run test:focused -- tests/boundary/process/processCli.test.ts tests/boundary/process/processSessionMcp.test.ts: new and updated tests passed; 2 PTY-gated tests skipped. 2 existing capture tests fail identically on main because Windows PTY capture is unavailable.
  • npm run test:changed: 147 failures, all in Windows path and IDA/Ghidra suites. The same 147 tests fail when those 16 files run on clean main.
  • npm run docs:check: passed.
  • After b099a83: npm run test:focused -- tests/boundary/process/processSessionMcp.test.ts tests/boundary/process/processCli.test.ts: new assertions passed; the same 2 existing Windows capture failures.
  • npm run jscpd: passed (3.21%, threshold 3.5%).

Compatibility, safety, and release

  • Breaking changes or migration steps: a scenario with an environment.__proto__ entry was previously accepted, but the entry never reached the child. It is now rejected. Callers can launch /usr/bin/env with __proto__=VALUE before the command.
  • Real Hopper/Ghidra, browser, or OS coverage: none; Linux/macOS process capture was not run.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new launch, authority, or data paths; input is rejected earlier.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/3834 **Author:** [@skyvanguard](https://github.com/skyvanguard) **Created:** 10/15/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/process-scenario-proto-environment` --- ### 📝 Commits (2) - [`673f0c1`](https://github.com/morluto/rea/commit/673f0c1cb2a1f05eb11186eb0cb7cb91e8cdafaa) fix(process): reject the __proto__ environment name the PTY backend drops - [`b099a83`](https://github.com/morluto/rea/commit/b099a83b97f9e6c4436640db608655dcd9f071a7) test(process): validate the advertised environment contract over MCP ### 📊 Changes **8 files changed** (+300 additions, -48 deletions) <details> <summary>View changed files</summary> 📝 `docs/process-capture.md` (+4 -1) 📝 `src/contracts/sessionToolContracts.ts` (+1 -1) ➕ `src/domain/ownKeyRecordSchema.test.ts` (+41 -0) ➕ `src/domain/ownKeyRecordSchema.ts` (+116 -0) 📝 `src/domain/portableSchemaPatterns.test.ts` (+38 -16) 📝 `src/domain/process/processScenario.ts` (+51 -21) 📝 `tests/boundary/process/processCli.test.ts` (+14 -4) 📝 `tests/boundary/process/processSessionMcp.test.ts` (+35 -5) </details> ### 📄 Description ## Summary Fixes #3338. `capture-process` accepted an environment entry named `__proto__` and silently dropped it, so the child ran with a different input than the caller selected. REA now rejects that name before launch with an actionable diagnostic, in the CLI and over MCP. ## Problem and expected behavior Two layers lose the entry: 1. **Scenario parsing (REA).** zod 4.4.3 `z.record` skips the own key `"__proto__"` without validating or reporting it (`$ZodRecord`: `if (key === "__proto__") continue;`). `processScenarioSchema.environment` is such a record, so parsing succeeded without the entry. 2. **PTY launch (dependency).** `@lydell/node-pty` 1.1.0 copies `opt.env` with `utils.assign`, which does `target[key] = source[key]` (`unixTerminal.js:47`). Assigning `__proto__` on a plain object calls the prototype setter, so the copy drops it before the child's environment is built. Upstream `node-pty` 1.1.0 has the same `assign`. Because of (2), preserving the entry in the schema alone would make the recorded scenario claim an override the child never received. The contract REA can keep is: an accepted override reaches the child, and an override that cannot reach it is rejected visibly. ## Change and scope - `src/domain/ownKeyRecordSchema.ts`: a string-keyed record that validates an own `__proto__` member with the same key and value schemas instead of skipping it. If the key schema accepts it, it is kept as an ordinary data property in its original position. It is built from a refinement plus `overwrite` rather than a transform, so input JSON Schema projections keep an enclosing `.default({})`. It advertises exactly the `z.record` JSON Schema. - `src/domain/process/processScenario.ts`: the RE2-safe complement pattern now excludes a set of reserved names. With one name it reproduces the previous pattern byte for byte. `__proto__` joins `REA_PROCESS_RUN_ID`, with a diagnostic that points to the `/usr/bin/env __proto__=VALUE` workaround from the report. The reporter verified that workaround on macOS; it was not re-run here. `environment` uses the record helper, so the key schema actually sees `__proto__`. - Trade-off: like the existing `refine` + `overwrite` schemas, the refinement and the overwrite each parse the (small) environment map once. The projection override lives on the returned instances, so derivations such as `.describe()` must not be applied to the helper's result. This is documented on the helper. - Tool description and `docs/process-capture.md` state the rejection. Not included: - No change to node-pty; the upstream report is microsoft/node-pty#993. Once a release with that fix reaches `@lydell/node-pty`, accepting the name again only requires removing the reservation. - `nativeCallObservationInputSchema.environment` uses the same `z.record` shape and likely drops `__proto__` the same way. Its debugger launch path differs and could not be verified here. - Over MCP, the SDK's input-validation text shows the record's generic `Invalid key in record` for reserved keys, without the nested reason. This already happens for `REA_PROCESS_RUN_ID`. ## Contract and boundary impact - Semantic owner and earliest changed stage: `processScenarioSchema` (request parsing), before any launch. - Contribution scope fit and linked maintainer decision: not applicable (fix within an existing boundary). - CLI and MCP/tool-catalog contract: `capture_process_scenario` now rejects `environment.__proto__`. The advertised `propertyNames.pattern` excludes it and the description mentions it. Before the reservation was added, the input and output JSON Schema projections were byte-identical to `main` after switching to the helper. - Provider, bridge, target-format, or platform compatibility: none. - Evidence, artifact, provenance, or reconstruction contract: scenarios that previously parsed with a silently dropped `__proto__` entry are now rejected; no Evidence shape changes. - Target selection, authority, upstream behavior, and cleanup details: not applicable; rejection happens before launch. - Generated metadata: the tool description changes; `npm run docs:check` passes. Expected effects: - [ ] Read existing files or captured data. - [ ] Launch or attach to a process. - [ ] Inject instrumentation or run scripts/code. - [ ] Change process memory, registers, files, or configuration. - [ ] Contact network services. - [ ] Recover protected code or work around protections. - [ ] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. (None apply. The change only rejects input before launch.) ## Evidence and regression coverage - Tests added or updated: - `src/domain/portableSchemaPatterns.test.ts`: the look-ahead equivalence covers both reserved names, plus the `__proto__` diagnostic at `["environment", "__proto__"]`. - `tests/boundary/process/processCli.test.ts`: the CLI reports both reserved keys with the projected issue. - `tests/boundary/process/processSessionMcp.test.ts`: MCP rejects `REA_PROCESS_RUN_ID` and a JSON-parsed `__proto__` before launch; the marker file stays absent. The input schema that `tools/list` advertises, compiled with Ajv 2020, admits an ordinary override and rejects both names. - `src/domain/ownKeyRecordSchema.test.ts`: the accepted-`__proto__` branch (data property, position, untouched prototype), value-issue paths, and JSON Schema parity with `z.record`. - Base reproduction (executed): replacing the helper with `z.record(environmentName, childProcessString)` (reservation kept) makes the new domain, CLI and MCP `__proto__` tests fail, because the entry is accepted and dropped silently. Removing the `__proto__` reservation makes the advertised-contract assertion fail (`expected true to be false`). - node-pty (executed against the installed package's `utils.assign`): ``` scenario env own keys: [ '__proto__', 'NORMAL_CAPTURE_KEY' ] node-pty assign() own keys: [ 'NORMAL_CAPTURE_KEY' ] spread own keys: [ '__proto__', 'NORMAL_CAPTURE_KEY' ] ``` - Independent macOS confirmation (observed by @1052326311 in this thread, not by the author): on macOS arm64 with the locked `@lydell/node-pty` and a real PTY, the child omitted an own `__proto__` entry while receiving the control, and the `/usr/bin/env __proto__=VALUE` workaround delivered both values. - User-visible CLI output (`details.issues` of the `invalid_request` error): ```json { "path": ["environment", "__proto__"], "reason": "invalid_format", "expected": "regex", "message": "__proto__ cannot reach the captured process because the PTY backend drops it before launch; run /usr/bin/env with __proto__=VALUE before the command instead" } ``` - Remaining proof gaps: validation ran on Windows, where native process capture is unavailable by design. No PTY capture of this PR's revision has run on Linux or macOS, and repository CI is awaiting workflow approval. The node-pty drop and the workaround are confirmed by the macOS check above, which did not exercise this PR's fail-closed path. For evidence-bearing changes: - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed Windows 11, Node.js 24.19.0: - `npx tsc --noEmit -p tsconfig.json`: passed. - `npm run check:fast`: passed. - `npx oxfmt --check` / `npx oxlint` on changed files: passed; no new warnings. - `npm run test:local -- src/domain/ownKeyRecordSchema.test.ts src/domain/portableSchemaPatterns.test.ts src/domain/process/processScenario.test.ts src/domain/inputIssueProjection.test.ts`: 26 passed. - `npm run test:focused -- tests/boundary/process/processCli.test.ts tests/boundary/process/processSessionMcp.test.ts`: new and updated tests passed; 2 PTY-gated tests skipped. 2 existing capture tests fail identically on `main` because Windows PTY capture is unavailable. - `npm run test:changed`: 147 failures, all in Windows path and IDA/Ghidra suites. The same 147 tests fail when those 16 files run on clean `main`. - `npm run docs:check`: passed. - After `b099a83`: `npm run test:focused -- tests/boundary/process/processSessionMcp.test.ts tests/boundary/process/processCli.test.ts`: new assertions passed; the same 2 existing Windows capture failures. - `npm run jscpd`: passed (3.21%, threshold 3.5%). ## Compatibility, safety, and release - Breaking changes or migration steps: a scenario with an `environment.__proto__` entry was previously accepted, but the entry never reached the child. It is now rejected. Callers can launch `/usr/bin/env` with `__proto__=VALUE` before the command. - Real Hopper/Ghidra, browser, or OS coverage: none; Linux/macOS process capture was not run. - Package or release metadata impact: none. - Security, privacy, process, or containment review: no new launch, authority, or data paths; input is rejected earlier. ## Author readiness Human owner: <!-- @GitHub-handle --> - [x] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:10:33 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#5935
No description provided.