[PR #6259] [MERGED] fix(javascript): keep encoded URL slashes inside one runtime path segment #7234

Closed
opened 2026-11-01 21:46:21 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/6259
Author: @kaoru0822-kitauji
Created: 10/22/2026
Status: ✅ Merged
Merged: 10/22/2026
Merged by: @kaoru0822-kitauji

Base: main ← Head: fix/5878-url-prefix-encoded-slash


📝 Commits (1)

  • b9129b1 fix(javascript): keep encoded URL slashes inside one runtime path segment

📊 Changes

4 files changed (+407 additions, -54 deletions)

View changed files

📝 docs/javascript-runtime-reconciliation.md (+7 -1)
📝 src/domain/javascript/javascriptRuntimeLoadState.ts (+7 -6)
📝 src/domain/javascript/javascriptRuntimeStaticCandidates.ts (+114 -47)
➕ tests/boundary/cli/runtimeUrlPrefixMappingCli.test.ts (+279 -0)

📄 Description

What broke: A url-prefix runtime mapping decoded %2F into a path separator. reconcile-javascript-runtime then matched the script URL …/assets/child%2Fpart.js to the static file child/part.js with medium confidence and emitted an inferred observed_as edge.
Fix: The mapping now decodes each URL path segment on its own. A segment that decodes to contain / (or has malformed or non-UTF-8 escapes) has no artifact path, so the script stays unknown / no-authorized-location-mapping. Static nodes beneath that mapping's prefix also stay unknown in load state instead of becoming not-observed-in-capture.
Risk: Low. The change only affects HTTP(S) script and worker URLs whose path below the prefix contains %2F/%2f. Ordinary paths, encoded spaces, Unicode, %25 (%252F → literal child%2Fpart.js) and the existing %5C literal-backslash contract match as before.

Summary

Fixes #5878.

Before this change, pathBelowUrlPrefix called decodeURIComponent on the whole pathname suffix. The encoded slash in child%2Fpart.js, which is a byte inside one URL segment, became an artifact directory separator. Now an encoded slash stays inside its segment. That location has no artifact path under the prefix-only mapping, so REA returns the existing uncertain outcome and no observed_as edge. It does not add a new status.

Problem and expected behavior

Smallest trigger: one application layer with child/part.js (and optionally a literal child%2Fpart.js), a url-prefix mapping https://app.example.test/assets/ → "", and a source-free browser script at https://app.example.test/assets/child%2Fpart.js. The violated invariant is that a prefix-only mapping translates URL path segments to artifact path segments, so it must not invent hierarchy from bytes inside one segment. The static resolvers already reject encoded separators (admitsCanonicalPathSyntax, javascriptSourceMapPaths). This was the one runtime mapping path that decoded them unguarded.

Change and scope

  • src/domain/javascript/javascriptRuntimeStaticCandidates.ts (the owner of runtime-location → artifact-path translation):
    • translateRuntimeLocation is now the single place that relates one runtime location to one mapping. It returns outside, untranslatable or translated. mappedRuntimePaths (matching) and the load-state scope both use it. Before, each consumer repeated its own file-root/url-prefix dispatch.
    • pathBelowUrlPrefix decodes segment by segment (decodeUrlPathSegments). A URL beneath the prefix whose suffix cannot be translated is untranslatable, not outside. A URL equal to the prefix (for example the page itself) stays outside, as before.
    • StaticRuntimeScope records untranslatedArtifactPrefixes, but only for script and worker entities, since only those can correspond to load-state nodes. staticNodeRuntimeScope returns outside | within | uncertain.
  • src/domain/javascript/javascriptRuntimeLoadState.ts: uncertain nodes stay unknown / static-or-runtime-coverage-incomplete. Without this, the fix would swap a false loaded for a false not-observed-in-capture whenever another script under the same prefix made the capture complete. Many static servers serve child/part.js for child%2Fpart.js, so absence there is unproven.
  • docs/javascript-runtime-reconciliation.md: documents segment-wise decoding, %5C as a literal name byte, and the load-state consequence.
  • Not included: file-root mappings are unchanged, because they compare native paths and do not decode. #5872 (Electron file: target admission) is a separate defect. Percent-encoding case equivalence between the prefix and the URL (%2f vs %2F inside the prefix itself) is unchanged.

Contribution scope: not applicable. This is an ordinary fix within existing boundaries.

Contract and boundary impact

  • Semantic owner and earliest changed stage: javascriptRuntimeStaticCandidates.ts URL-prefix translation, during reconciliation matching and load-state scoping.

  • Contribution scope fit and linked maintainer decision: not applicable (ordinary fix).

  • CLI and MCP/tool-catalog contract: no schema change. For affected URLs, reconciliations[] items change from matched to unknown / no-authorized-location-mapping, there is no observed_as edge, and static_load_states for nodes beneath that prefix become unknown / static-or-runtime-coverage-incomplete.

  • Provider, bridge, target-format, or platform compatibility: none.

  • Evidence, artifact, provenance, or reconstruction contract: the runtime URL and static paths are preserved unchanged. Only the inferred cross-layer correspondence is withheld.

  • Target selection, authority, upstream behavior, and cleanup details: not applicable.

  • Generated metadata, package, or installation impact: none.

  • Read existing files or captured data.

Evidence and regression coverage

  • Tests added: tests/boundary/cli/runtimeUrlPrefixMappingCli.test.ts, which runs the built public CLI (node scripts/rea.mjs reconcile-javascript-runtime … --json) on real directory analysis and synthetic browser Evidence:

    • One capture with 8 scripts: child/part.js and child/part.js?v=%2F#f%2F → matched child/part.js. child%2Fpart.js and child%2fpart.js → unknown / no-authorized-location-mapping, 0 observed_as. child%252Fpart.js → matched literal child%2Fpart.js. sp%20ace.js → sp ace.js. %C3%A9.js → é.js. child/%E0.js → unknown.
    • Load state: the control (other.js only) gives child/part.js = not-observed-in-capture. Adding child%2Fpart.js gives child/part.js = unknown / static-or-runtime-coverage-incomplete, and other.js stays loaded.
    • The existing %5C literal-backslash and %2e%2e escape case in javascriptRuntimeReconciliation.test.ts is unchanged and passes.
  • Base reproduction: the issue's focused test, run on base c537c52c9 with the built CLI, printed the issue's three rows exactly, including {"suffix":"child%2Fpart.js","status":"matched",…,"paths":["child/part.js"],"observed_as":1}. After the fix it stops at that row. With src/ reverted and rebuilt, both new tests fail. With the fix, both pass.

  • User-visible CLI output: the affected script item is now {"status":"unknown","basis":"none","reason":"no-authorized-location-mapping"} with no observed_as edge.

  • Remaining proof gaps: no live browser or Electron runtime was used, and runtime Evidence is synthetic. Worker entities share the same code path, but no worker case was exercised. MCP shares the same application service, but it was not run separately for this case.

  • 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

All on base c537c52c9, macOS arm64, Node 24.18.0:

  • Issue repro test via the built CLI: reproduced on base; the %2F row no longer matches with the fix.
  • vitest run tests/boundary/cli/runtimeUrlPrefixMappingCli.test.ts: 2/2 passed with the fix; 2/2 failed with src/ reverted.
  • Related suites (cdpScriptMetadata, electronCli, jsonInputStatus, runtimeUrlPrefixMappingCli, javascriptRuntimeContentPriority, javascriptRuntimeReconciliation, javascriptApplicationWorkflows, javascriptRuntimeObservation, javascriptRuntimeUnresolvedTarget, javascriptSelectedPathEvidence, browserMcp, electronMcp, javascriptRuntimeReconciliationAmbiguity): 174 passed, 1 failed. The failure is javascriptRuntimeObservation.test.ts > includes targets outside the old caller root filter. It also fails locally with this PR's src/ changes reverted, so it is not caused by this change.
  • npm run check:fast: passed.
  • npm run format:check: passed.
  • npm run docs:check: passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Outputs for affected URLs become more conservative (unknown instead of an inferred match).
  • Real Hopper/Ghidra, browser, or OS coverage: none needed; no live browser was used.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new reads, launches or network access. Mappings still apply only to already-authorized locations.

Author readiness

Human owner: @kaoru0822-kitauji

  • 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.

🤖 Generated with Claude Code


🔄 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/6259 **Author:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Base:** `main` ← **Head:** `fix/5878-url-prefix-encoded-slash` --- ### 📝 Commits (1) - [`b9129b1`](https://github.com/morluto/rea/commit/b9129b19d40e637d5ec052dfbe7a46ad8a86b74a) fix(javascript): keep encoded URL slashes inside one runtime path segment ### 📊 Changes **4 files changed** (+407 additions, -54 deletions) <details> <summary>View changed files</summary> 📝 `docs/javascript-runtime-reconciliation.md` (+7 -1) 📝 `src/domain/javascript/javascriptRuntimeLoadState.ts` (+7 -6) 📝 `src/domain/javascript/javascriptRuntimeStaticCandidates.ts` (+114 -47) ➕ `tests/boundary/cli/runtimeUrlPrefixMappingCli.test.ts` (+279 -0) </details> ### 📄 Description **What broke:** A `url-prefix` runtime mapping decoded `%2F` into a path separator. `reconcile-javascript-runtime` then matched the script URL `…/assets/child%2Fpart.js` to the static file `child/part.js` with medium confidence and emitted an inferred `observed_as` edge. **Fix:** The mapping now decodes each URL path segment on its own. A segment that decodes to contain `/` (or has malformed or non-UTF-8 escapes) has no artifact path, so the script stays `unknown` / `no-authorized-location-mapping`. Static nodes beneath that mapping's prefix also stay `unknown` in load state instead of becoming `not-observed-in-capture`. **Risk:** Low. The change only affects HTTP(S) script and worker URLs whose path below the prefix contains `%2F`/`%2f`. Ordinary paths, encoded spaces, Unicode, `%25` (`%252F` → literal `child%2Fpart.js`) and the existing `%5C` literal-backslash contract match as before. ## Summary Fixes #5878. Before this change, `pathBelowUrlPrefix` called `decodeURIComponent` on the whole pathname suffix. The encoded slash in `child%2Fpart.js`, which is a byte inside one URL segment, became an artifact directory separator. Now an encoded slash stays inside its segment. That location has no artifact path under the prefix-only mapping, so REA returns the existing uncertain outcome and no `observed_as` edge. It does not add a new status. ## Problem and expected behavior Smallest trigger: one application layer with `child/part.js` (and optionally a literal `child%2Fpart.js`), a `url-prefix` mapping `https://app.example.test/assets/` → `""`, and a source-free browser script at `https://app.example.test/assets/child%2Fpart.js`. The violated invariant is that a prefix-only mapping translates URL path segments to artifact path segments, so it must not invent hierarchy from bytes inside one segment. The static resolvers already reject encoded separators (`admitsCanonicalPathSyntax`, `javascriptSourceMapPaths`). This was the one runtime mapping path that decoded them unguarded. ## Change and scope - `src/domain/javascript/javascriptRuntimeStaticCandidates.ts` (the owner of runtime-location → artifact-path translation): - `translateRuntimeLocation` is now the single place that relates one runtime location to one mapping. It returns `outside`, `untranslatable` or `translated`. `mappedRuntimePaths` (matching) and the load-state scope both use it. Before, each consumer repeated its own `file-root`/`url-prefix` dispatch. - `pathBelowUrlPrefix` decodes segment by segment (`decodeUrlPathSegments`). A URL beneath the prefix whose suffix cannot be translated is `untranslatable`, not `outside`. A URL equal to the prefix (for example the page itself) stays `outside`, as before. - `StaticRuntimeScope` records `untranslatedArtifactPrefixes`, but only for script and worker entities, since only those can correspond to load-state nodes. `staticNodeRuntimeScope` returns `outside | within | uncertain`. - `src/domain/javascript/javascriptRuntimeLoadState.ts`: `uncertain` nodes stay `unknown` / `static-or-runtime-coverage-incomplete`. Without this, the fix would swap a false `loaded` for a false `not-observed-in-capture` whenever another script under the same prefix made the capture complete. Many static servers serve `child/part.js` for `child%2Fpart.js`, so absence there is unproven. - `docs/javascript-runtime-reconciliation.md`: documents segment-wise decoding, `%5C` as a literal name byte, and the load-state consequence. - Not included: `file-root` mappings are unchanged, because they compare native paths and do not decode. #5872 (Electron `file:` target admission) is a separate defect. Percent-encoding case equivalence between the prefix and the URL (`%2f` vs `%2F` inside the prefix itself) is unchanged. Contribution scope: not applicable. This is an ordinary fix within existing boundaries. ## Contract and boundary impact - Semantic owner and earliest changed stage: `javascriptRuntimeStaticCandidates.ts` URL-prefix translation, during reconciliation matching and load-state scoping. - Contribution scope fit and linked maintainer decision: not applicable (ordinary fix). - CLI and MCP/tool-catalog contract: no schema change. For affected URLs, `reconciliations[]` items change from `matched` to `unknown` / `no-authorized-location-mapping`, there is no `observed_as` edge, and `static_load_states` for nodes beneath that prefix become `unknown` / `static-or-runtime-coverage-incomplete`. - Provider, bridge, target-format, or platform compatibility: none. - Evidence, artifact, provenance, or reconstruction contract: the runtime URL and static paths are preserved unchanged. Only the inferred cross-layer correspondence is withheld. - Target selection, authority, upstream behavior, and cleanup details: not applicable. - Generated metadata, package, or installation impact: none. - [x] Read existing files or captured data. ## Evidence and regression coverage - Tests added: `tests/boundary/cli/runtimeUrlPrefixMappingCli.test.ts`, which runs the built public CLI (`node scripts/rea.mjs reconcile-javascript-runtime … --json`) on real directory analysis and synthetic browser Evidence: - One capture with 8 scripts: `child/part.js` and `child/part.js?v=%2F#f%2F` → matched `child/part.js`. `child%2Fpart.js` and `child%2fpart.js` → `unknown` / `no-authorized-location-mapping`, 0 `observed_as`. `child%252Fpart.js` → matched literal `child%2Fpart.js`. `sp%20ace.js` → `sp ace.js`. `%C3%A9.js` → `é.js`. `child/%E0.js` → unknown. - Load state: the control (`other.js` only) gives `child/part.js` = `not-observed-in-capture`. Adding `child%2Fpart.js` gives `child/part.js` = `unknown` / `static-or-runtime-coverage-incomplete`, and `other.js` stays `loaded`. - The existing `%5C` literal-backslash and `%2e%2e` escape case in `javascriptRuntimeReconciliation.test.ts` is unchanged and passes. - Base reproduction: the issue's focused test, run on base `c537c52c9` with the built CLI, printed the issue's three rows exactly, including `{"suffix":"child%2Fpart.js","status":"matched",…,"paths":["child/part.js"],"observed_as":1}`. After the fix it stops at that row. With `src/` reverted and rebuilt, both new tests fail. With the fix, both pass. - User-visible CLI output: the affected script item is now `{"status":"unknown","basis":"none","reason":"no-authorized-location-mapping"}` with no `observed_as` edge. - Remaining proof gaps: no live browser or Electron runtime was used, and runtime Evidence is synthetic. Worker entities share the same code path, but no worker case was exercised. MCP shares the same application service, but it was not run separately for this case. - [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 All on base `c537c52c9`, macOS arm64, Node 24.18.0: - Issue repro test via the built CLI: reproduced on base; the `%2F` row no longer matches with the fix. - `vitest run tests/boundary/cli/runtimeUrlPrefixMappingCli.test.ts`: 2/2 passed with the fix; 2/2 failed with `src/` reverted. - Related suites (`cdpScriptMetadata`, `electronCli`, `jsonInputStatus`, `runtimeUrlPrefixMappingCli`, `javascriptRuntimeContentPriority`, `javascriptRuntimeReconciliation`, `javascriptApplicationWorkflows`, `javascriptRuntimeObservation`, `javascriptRuntimeUnresolvedTarget`, `javascriptSelectedPathEvidence`, `browserMcp`, `electronMcp`, `javascriptRuntimeReconciliationAmbiguity`): 174 passed, 1 failed. The failure is `javascriptRuntimeObservation.test.ts > includes targets outside the old caller root filter`. It also fails locally with this PR's `src/` changes reverted, so it is not caused by this change. - `npm run check:fast`: passed. - `npm run format:check`: passed. - `npm run docs:check`: passed. ## Compatibility, safety, and release - Breaking changes or migration steps: none. Outputs for affected URLs become more conservative (`unknown` instead of an inferred match). - Real Hopper/Ghidra, browser, or OS coverage: none needed; no live browser was used. - Package or release metadata impact: none. - Security, privacy, process, or containment review: no new reads, launches or network access. Mappings still apply only to already-authorized locations. ## Author readiness Human owner: @kaoru0822-kitauji - [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. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 21:46:21 +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#7234
No description provided.