[PR #3162] [CLOSED] fix(main): safely guard realpathSync resolution during direct entrypoint check #5650

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

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/3162
Author: @qorvr
Created: 10/14/2026
Status: ❌ Closed

Base: main ← Head: fix/safe-entrypoint-resolution


📝 Commits (2)

  • 4955893 fix(main): safely guard realpathSync during direct entrypoint check
  • ab10b36 test(main): test undefined entrypoint safely and guard parameter fallback

📊 Changes

2 files changed (+41 additions, -6 deletions)

View changed files

📝 src/main.ts (+17 -5)
📝 tests/boundary/mcp/mainErrors.test.ts (+24 -1)

📄 Description

Summary

When REA's MCP entrypoint module (src/main.ts) is imported in environments with synthetic, missing, bundled, or non-existent file paths in process.argv[1], the direct invocation check unconditionally called realpathSync(process.argv[1]). This throws an unhandled synchronous ENOENT / EINVAL error during module loading before any fallback or caller handling can execute.

Evaluated and error found by SubQ by Qorvr.

Problem and expected behavior

  • Smallest trigger: Importing src/main.ts or executing in a virtualized/bundled runtime where process.argv[1] does not point to an accessible on-disk file (or is undefined/invalid).
  • Observed failure: realpathSync(entryPath) throws an unhandled error immediately upon evaluation.
  • Expected behavior: Direct entrypoint check should safely evaluate whether argv[1] resolves to import.meta.url, and gracefully return false on any file-system resolution error without crashing module import.

Change and scope

  • Added an isDirectEntrypoint helper function that wraps pathToFileURL(realpathSync(entryPath)).href === currentUrl in a try / catch block.
  • Defaults safely to false when entryPath is undefined or cannot be resolved by realpathSync.
  • Added unit tests in tests/boundary/mcp/mainErrors.test.ts covering both undefined and invalid/non-existent entryPath.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/main.ts entrypoint guard.
  • Contribution scope fit and linked maintainer decision: not applicable (standard bug fix in existing boundary).
  • CLI and MCP/tool-catalog contract: none (internal guard).
  • Provider, bridge, target-format, or platform compatibility: improves resilience on environments where process.argv[1] may point to synthetic paths.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): none.
  • Generated metadata impact: none.

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.

Evidence and regression coverage

  • Tests added or updated: Added tests in tests/boundary/mcp/mainErrors.test.ts to verify isDirectEntrypoint returns false safely for undefined and non-existent paths.
  • Base reproduction or other evidence: Calling realpathSync on a non-existent path throws ENOENT.
  • Remaining proof gaps: none.

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

  • npx vitest run tests/boundary/mcp/mainErrors.test.ts — 7 tests passed (including 2 new tests).
  • npm run format:check — oxfmt passed on all files.
  • npm run lint — oxlint passed with 0 errors; module boundary checks passed.
  • turbo run typecheck lint — passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: cross-platform safe.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: safe exception handling.

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/3162 **Author:** [@qorvr](https://github.com/qorvr) **Created:** 10/14/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/safe-entrypoint-resolution` --- ### 📝 Commits (2) - [`4955893`](https://github.com/morluto/rea/commit/4955893c0bc9bae221c1fc8f570da05dec483e39) fix(main): safely guard realpathSync during direct entrypoint check - [`ab10b36`](https://github.com/morluto/rea/commit/ab10b36ae8df06a2542cba7555d65c8d4ecce504) test(main): test undefined entrypoint safely and guard parameter fallback ### 📊 Changes **2 files changed** (+41 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `src/main.ts` (+17 -5) 📝 `tests/boundary/mcp/mainErrors.test.ts` (+24 -1) </details> ### 📄 Description ## Summary When REA's MCP entrypoint module (`src/main.ts`) is imported in environments with synthetic, missing, bundled, or non-existent file paths in `process.argv[1]`, the direct invocation check unconditionally called `realpathSync(process.argv[1])`. This throws an unhandled synchronous `ENOENT` / `EINVAL` error during module loading before any fallback or caller handling can execute. Evaluated and error found by SubQ by Qorvr. ## Problem and expected behavior - **Smallest trigger:** Importing `src/main.ts` or executing in a virtualized/bundled runtime where `process.argv[1]` does not point to an accessible on-disk file (or is undefined/invalid). - **Observed failure:** `realpathSync(entryPath)` throws an unhandled error immediately upon evaluation. - **Expected behavior:** Direct entrypoint check should safely evaluate whether `argv[1]` resolves to `import.meta.url`, and gracefully return `false` on any file-system resolution error without crashing module import. ## Change and scope - Added an `isDirectEntrypoint` helper function that wraps `pathToFileURL(realpathSync(entryPath)).href === currentUrl` in a `try / catch` block. - Defaults safely to `false` when `entryPath` is `undefined` or cannot be resolved by `realpathSync`. - Added unit tests in `tests/boundary/mcp/mainErrors.test.ts` covering both undefined and invalid/non-existent `entryPath`. ## Contract and boundary impact - Semantic owner and earliest changed stage: `src/main.ts` entrypoint guard. - Contribution scope fit and linked maintainer decision: not applicable (standard bug fix in existing boundary). - CLI and MCP/tool-catalog contract: none (internal guard). - Provider, bridge, target-format, or platform compatibility: improves resilience on environments where `process.argv[1]` may point to synthetic paths. - Evidence, artifact, provenance, or reconstruction contract: none. - Target selection, authority, upstream behavior, and cleanup details (if applicable): none. - Generated metadata impact: none. Expected effects: - [x] 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. ## Evidence and regression coverage - Tests added or updated: Added tests in `tests/boundary/mcp/mainErrors.test.ts` to verify `isDirectEntrypoint` returns `false` safely for undefined and non-existent paths. - Base reproduction or other evidence: Calling `realpathSync` on a non-existent path throws `ENOENT`. - Remaining proof gaps: none. 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 - `npx vitest run tests/boundary/mcp/mainErrors.test.ts` — 7 tests passed (including 2 new tests). - `npm run format:check` — oxfmt passed on all files. - `npm run lint` — oxlint passed with 0 errors; module boundary checks passed. - `turbo run typecheck lint` — passed. ## Compatibility, safety, and release - Breaking changes or migration steps: none. - Real Hopper/Ghidra, browser, or OS coverage: cross-platform safe. - Package or release metadata impact: none. - Security, privacy, process, or containment review: safe exception handling. ## 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:08:16 +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#5650
No description provided.