Skip to content

fix(javascript): keep parent segments that re-enter the synthetic URL root - #7171

Closed
devreddy1015 wants to merge 1 commit into
morluto:mainfrom
devreddy1015:fix/javascript-synthetic-root-reentry
Closed

devreddy1015 wants to merge 1 commit into
morluto:mainfrom
devreddy1015:fix/javascript-synthetic-root-reentry

Conversation

@devreddy1015

@devreddy1015 devreddy1015 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Relative URLs that climb above their base with .. and then re-enter a directory named source lose their parent segments in two places:

  • createRequire(new URL("../source/anchor.cjs", import.meta.url)) was reported as base anchor.cjs, so require("./dep.cjs") resolved to app/dep.cjs. Node loads source/dep.cjs.
  • A source-map source ../../source/a.js from maps.js/main.js.map was reported as the in-artifact path a.js instead of unresolved.

Cause and change

Both sites resolve under a synthetic root made of source/ segments, then call posix.relative. A reference that names source (or %73ource) re-enters that root, and its parent segments vanish. The new pathBelowSyntheticUrlRoot resolves under two differently named roots and keeps the result with more leading ... A reference cannot re-enter both, and the URL parser still does all resolution. Module URLs already have this guard (applyUrlReference in the application layer), but domain code cannot import it.

Evidence

  • A new acceptance case in createRequireFilenameBase.test.ts runs through CLI and stdio MCP with a real Node control. Two new rows are in sourceToBundlePaths.test.ts. All of them fail without the fix and pass with it.
  • src/domain/javascript and src/application/javascript: 4,805 tests pass. 319 of 326 related boundary and acceptance files pass. The other 7 fail locally for environment reasons: Node 26 instead of the pinned 24, and missing generated files. The Node SEA one also fails without this change. npm run check:fast passes.
  • Not run: Node 24, macOS, Windows.

Scope: a static analysis fix within existing boundaries, with no CLI/MCP contract, package or metadata change.

Author readiness

Human owner: @devreddy1015

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

… root

Source-map source paths and static new URL(..., import.meta.url) paths
resolve relative references below a deep synthetic root of "source/"
segments, then take posix.relative(root, path). A reference that climbs
above the root and then names "source" (or %73ource) re-creates the
root's own segment, so its parent segments vanish:

- createRequire(new URL("../source/anchor.cjs", import.meta.url)) was
  reported as base "anchor.cjs", so require("./dep.cjs") resolved to
  app/dep.cjs while Node loads source/dep.cjs.
- A source-map source "../../source/a.js" from maps.js/main.js.map was
  reported as the in-artifact path "a.js" instead of unresolved.

pathBelowSyntheticUrlRoot resolves below two roots with different segment
names and keeps the result with more leading parent segments. A reference
cannot re-enter both names at once, and without re-entry both results are
identical. The URL parser still performs all resolution. Module URLs keep
their existing applyUrlReference guard in the application layer, which
these domain modules cannot import.
@greptile-apps

greptile-apps Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable code issues were found.

Summary

Preserves leading .. segments when relative URLs leave and re-enter a synthetic root.

  • Source maps leave outside references unresolved when they re-enter a same-named directory.
  • createRequire keeps parent segments in URL-based filename bases.

Tests were inspected, not run during this review. Supersession could not be checked because GitHub authentication was unavailable.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Static source-relative URL] --> C[Resolve below source and anchor roots]
  B[Relative source-map reference] --> C
  C --> D[Keep the path with more leading parent segments]
  D --> E[Static analysis retains the relative path]
  D --> F[Source-map matching rejects paths outside the artifact]
Loading

Reviews (1) · Last reviewed commit: "fix(javascript): keep parent segments th..." · Reviewed by Greptile

@devreddy1015
devreddy1015 marked this pull request as ready for review October 25, 2026 20:32
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T20:37:45.583552Z 1c8d682 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: I ran the PR's 2 changed test files on Node 22.23.4, 24.22.1 and 26.12.1, and all 74 tests passed each time. The CI workflow run on this head is marked action_required, with no test jobs in it. I did not check that the new cases fail without the fix.

Findings

Check Node 22.23.4 Node 24.22.1 Node 26.12.1
tests/acceptance/applications/createRequireFilenameBase.test.ts and tests/boundary/filesystem/sourceToBundlePaths.test.ts pass: 2 of 2 files, 74 of 74 tests pass: 2 of 2 files, 74 of 74 tests pass: 2 of 2 files, 74 of 74 tests
  • I ran head 1c8d682 in a VM (virtual machine) on the 2 changed test files. Each run printed Test Files 2 passed (2) and Tests 74 passed (74).
  • The head is 1237 commits behind main 559083b.
  • I read CI on the head live with gh. GitHub shows the PR as mergeable, state blocked, not a draft.
  • The CI workflow run is completed/action_required. No Source tests, Portable tests or Test shard jobs appear in its check runs.
  • PR title has 12 runs, all completed/action_required.
  • PR readiness has 5 runs completed/success, 7 completed/cancelled and 1 completed/failure. Its commit status is success.
  • Check runs: 6 success, 6 cancelled and 1 failure. The success runs are Greptile Review and 5 of Validate author declaration. The cancelled and failed runs are all Validate author declaration.

Not run

  • A run of createRequireFilenameBase.test.ts and sourceToBundlePaths.test.ts with only the three source files reverted, to confirm the new cases fail.
  • A probe that calls staticSourceRelativeUrlPath on ../anchor/x, ../../%73ource/x and file:///source/x, to settle the open questions.
  • A merge with current main, 559083b.
Test setup
  • Box: Fedora 44 VM (4 vCPUs, 8 GB) on my Nobara 44 PC, Linux 7.2.11
  • Node: 22.23.4, 24.22.1, 26.12.1
  • Head / base: 1c8d682 / 1173c0a (merge base with main)
  • Install: npm ci --offline and npm run test:prepare on Node 24.22.1
Commands
npm ci --offline
npm run test:prepare
xvfb-run -a npm run test:focused -- tests/acceptance/applications/createRequireFilenameBase.test.ts tests/boundary/filesystem/sourceToBundlePaths.test.ts

🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊

@morluto

morluto commented Nov 19, 2026

Copy link
Copy Markdown
Owner

The synthetic-root traversal fix for both createRequire and source-map paths landed in #12161, with regression coverage for same-named re-entry. Thanks for the original report and fix.

@morluto morluto closed this Nov 19, 2026
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants