[PR #4193] [CLOSED] fix(target): reject app program file when Contents/MacOS leaves the bundle #6118

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

📋 Pull Request Information

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

Base: main ← Head: fix/app-bundle-symlink-escape


📝 Commits (3)

  • a72bf07 fix(target): reject app program file when Contents/MacOS leaves the bundle
  • 261d625 fix(target): check programs directory containment before resolving executable
  • f2c3925 Merge branch 'main' into fix/app-bundle-symlink-escape

📊 Changes

3 files changed (+171 additions, -101 deletions)

View changed files

📝 src/application/AppBundleExecutable.test.ts (+122 -29)
📝 src/application/AppBundleExecutable.ts (+38 -28)
📝 tests/boundary/filesystem/binaryTarget.test.ts (+11 -44)

📄 Description

fix(target): reject app program file when Contents/MacOS leaves the bundle

Summary

Fixes #4181.

Prevents open_binary and resolveAppBundleExecutable from following a symlinked Contents/MacOS (or any intermediate path) outside an app bundle to inspect arbitrary host files.

Problem and expected behavior

  • Smallest trigger: Opening an app bundle whose Contents/MacOS is a symlink pointing outside the bundle (e.g. /usr/bin), declaring a binary such as true in CFBundleExecutable.
  • Violated invariant: resolveLayoutExecutable checked lexical containment using only isPathWithinRoot(realpath(programs), realpath(executable)). When programs was a symlink to an outside directory, both sides resolved to outside paths (e.g., /usr/bin and /usr/bin/true), allowing the check to pass without ever verifying containment against the canonical bundle root.
  • Expected outcome: Any program file or programs directory resolving outside the canonical bundle root must be rejected with app program file leaves ${layout.programsLabel} (e.g., app program file leaves Contents/MacOS or app program file leaves the bundle root).

Change and scope

In src/application/AppBundleExecutable.ts:

  • Resolves canonicalBundle = await fileSystem.realpath(bundle) in parallel with canonicalPrograms and canonicalExecutable.
  • Enforces three containment assertions:
    1. isPathWithinRoot(canonicalBundle, canonicalPrograms) — verifies the programs directory does not leave the bundle.
    2. isPathWithinRoot(canonicalBundle, canonicalExecutable) — verifies the resolved program file does not leave the bundle.
    3. isPathWithinRoot(canonicalPrograms, canonicalExecutable) — verifies the program file stays within the declared programs directory.
  • Rejects with BinaryTargetError(bundle, "app program file leaves " + layout.programsLabel) if any check fails.

Ordinary bug fix within existing resolution boundaries; no maintainer scope decision required.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/application/AppBundleExecutable.ts, app bundle target resolution.
  • Contribution scope fit and linked maintainer decision: not applicable (bug fix within existing boundaries).
  • CLI and MCP/tool-catalog contract: Unchanged schemas; escaping bundles return BinaryTargetError instead of admitting host binaries.
  • Provider, bridge, target-format, or platform compatibility: macOS and iOS app bundles across macOS, Linux, and Windows hosts.
  • Evidence, artifact, provenance, or reconstruction contract: Preserves provenance.
  • Target selection, authority, upstream behavior, and cleanup details: Read-only admission containment check; no cleanup required.
  • Generated metadata: 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:
    • src/application/AppBundleExecutable.test.ts:
      • rejects an app bundle whose Contents/MacOS resolves outside the bundle
      • rejects a flat app bundle whose program file resolves outside the bundle root
      • accepts a symlinked app bundle whose executable stays within the canonical bundle
    • tests/boundary/filesystem/binaryTarget.test.ts:
      • rejects an app bundle whose Contents/MacOS symlink leaves the bundle
  • Base reproduction:
    • Tested on base revision before the fix: rejects an app bundle whose Contents/MacOS resolves outside the bundle failed with AssertionError: expected true to be false because /usr/bin/true was admitted.
    • Passed after applying the tripartite containment check.
  • Remaining proof gaps:
    • Real symlinks on Windows are skipped in binaryTarget.test.ts due to Windows unprivileged symlink permissions; full resolution semantics are validated across all platforms via injectable AppBundleFileSystem in AppBundleExecutable.test.ts.

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

  • npm run test:local -- src/application/AppBundleExecutable.test.ts — 4 passed in 876ms
  • npm run test:focused -- tests/boundary/filesystem/binaryTarget.test.ts — 54 passed, 9 skipped (Windows) in 2.70s
  • npm run check:fast — typecheck and lint passed with 0 errors
  • npm run verify:test-discovery — discovered all 1,349 test files exactly once
  • npm run verify:module-boundaries — verified resolved module boundaries across 1,944 source files

Compatibility, safety, and release

  • Breaking changes or migration steps: None.
  • Real Hopper/Ghidra, browser, or OS coverage: Cross-platform target resolution check.
  • Package or release metadata impact: None.
  • Security, privacy, process, or containment review: Fixes a directory confinement bypass where callers constraining analysis targets could have untrusted bundles point REA at arbitrary host files.

Author readiness

Human owner: @Abishek0070

  • 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/4193 **Author:** [@Abishek0070](https://github.com/Abishek0070) **Created:** 10/15/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/app-bundle-symlink-escape` --- ### 📝 Commits (3) - [`a72bf07`](https://github.com/morluto/rea/commit/a72bf07bb0218b1ecdb6328da6d8d274f5755623) fix(target): reject app program file when Contents/MacOS leaves the bundle - [`261d625`](https://github.com/morluto/rea/commit/261d6252052b6409351f827e8874e3b46b7bb3f2) fix(target): check programs directory containment before resolving executable - [`f2c3925`](https://github.com/morluto/rea/commit/f2c3925070467f86ae011db2d363db8b8fe647e9) Merge branch 'main' into fix/app-bundle-symlink-escape ### 📊 Changes **3 files changed** (+171 additions, -101 deletions) <details> <summary>View changed files</summary> 📝 `src/application/AppBundleExecutable.test.ts` (+122 -29) 📝 `src/application/AppBundleExecutable.ts` (+38 -28) 📝 `tests/boundary/filesystem/binaryTarget.test.ts` (+11 -44) </details> ### 📄 Description fix(target): reject app program file when Contents/MacOS leaves the bundle ## Summary Fixes #4181. Prevents `open_binary` and `resolveAppBundleExecutable` from following a symlinked `Contents/MacOS` (or any intermediate path) outside an app bundle to inspect arbitrary host files. ## Problem and expected behavior - **Smallest trigger**: Opening an app bundle whose `Contents/MacOS` is a symlink pointing outside the bundle (e.g. `/usr/bin`), declaring a binary such as `true` in `CFBundleExecutable`. - **Violated invariant**: `resolveLayoutExecutable` checked lexical containment using only `isPathWithinRoot(realpath(programs), realpath(executable))`. When `programs` was a symlink to an outside directory, both sides resolved to outside paths (e.g., `/usr/bin` and `/usr/bin/true`), allowing the check to pass without ever verifying containment against the canonical bundle root. - **Expected outcome**: Any program file or programs directory resolving outside the canonical bundle root must be rejected with `app program file leaves ${layout.programsLabel}` (e.g., `app program file leaves Contents/MacOS` or `app program file leaves the bundle root`). ## Change and scope In `src/application/AppBundleExecutable.ts`: - Resolves `canonicalBundle = await fileSystem.realpath(bundle)` in parallel with `canonicalPrograms` and `canonicalExecutable`. - Enforces three containment assertions: 1. `isPathWithinRoot(canonicalBundle, canonicalPrograms)` — verifies the programs directory does not leave the bundle. 2. `isPathWithinRoot(canonicalBundle, canonicalExecutable)` — verifies the resolved program file does not leave the bundle. 3. `isPathWithinRoot(canonicalPrograms, canonicalExecutable)` — verifies the program file stays within the declared programs directory. - Rejects with `BinaryTargetError(bundle, "app program file leaves " + layout.programsLabel)` if any check fails. Ordinary bug fix within existing resolution boundaries; no maintainer scope decision required. ## Contract and boundary impact - Semantic owner and earliest changed stage: `src/application/AppBundleExecutable.ts`, app bundle target resolution. - Contribution scope fit and linked maintainer decision: not applicable (bug fix within existing boundaries). - CLI and MCP/tool-catalog contract: Unchanged schemas; escaping bundles return `BinaryTargetError` instead of admitting host binaries. - Provider, bridge, target-format, or platform compatibility: macOS and iOS app bundles across macOS, Linux, and Windows hosts. - Evidence, artifact, provenance, or reconstruction contract: Preserves provenance. - Target selection, authority, upstream behavior, and cleanup details: Read-only admission containment check; no cleanup required. - Generated metadata: 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: - `src/application/AppBundleExecutable.test.ts`: - `rejects an app bundle whose Contents/MacOS resolves outside the bundle` - `rejects a flat app bundle whose program file resolves outside the bundle root` - `accepts a symlinked app bundle whose executable stays within the canonical bundle` - `tests/boundary/filesystem/binaryTarget.test.ts`: - `rejects an app bundle whose Contents/MacOS symlink leaves the bundle` - Base reproduction: - Tested on base revision before the fix: `rejects an app bundle whose Contents/MacOS resolves outside the bundle` failed with `AssertionError: expected true to be false` because `/usr/bin/true` was admitted. - Passed after applying the tripartite containment check. - Remaining proof gaps: - Real symlinks on Windows are skipped in `binaryTarget.test.ts` due to Windows unprivileged symlink permissions; full resolution semantics are validated across all platforms via injectable `AppBundleFileSystem` in `AppBundleExecutable.test.ts`. 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 - `npm run test:local -- src/application/AppBundleExecutable.test.ts` — 4 passed in 876ms - `npm run test:focused -- tests/boundary/filesystem/binaryTarget.test.ts` — 54 passed, 9 skipped (Windows) in 2.70s - `npm run check:fast` — typecheck and lint passed with 0 errors - `npm run verify:test-discovery` — discovered all 1,349 test files exactly once - `npm run verify:module-boundaries` — verified resolved module boundaries across 1,944 source files ## Compatibility, safety, and release - Breaking changes or migration steps: None. - Real Hopper/Ghidra, browser, or OS coverage: Cross-platform target resolution check. - Package or release metadata impact: None. - Security, privacy, process, or containment review: Fixes a directory confinement bypass where callers constraining analysis targets could have untrusted bundles point REA at arbitrary host files. ## Author readiness Human owner: @Abishek0070 - [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 - [ ] 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:12:00 +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#6118
No description provided.