Skip to content

fix(javascript): preserve ESM path intent and artifact confinement - #2700

Merged
morluto merged 25 commits into
morluto:mainfrom
rohitg00:fix/esm-package-directory-intent
Oct 22, 2026
Merged

morluto merged 25 commits into
morluto:mainfrom
rohitg00:fix/esm-package-directory-intent

Conversation

@rohitg00

@rohitg00 rohitg00 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Preserve legacy ESM path intent, artifact confinement, and package-map provenance during offline module resolution.

Problem and expected behavior

A request such as legacy/feature.js/. must retain directory intent. A request such as legacy/../../../rea-artifact/outside.js must be rejected before URL normalization erases its escape from the artifact root. An unavailable imports or exports target must retain the selected raw target and map kind.

Unpaired UTF-16 surrogates in ASAR metadata paths must not abort analysis, collide with replacement-character siblings, or mask package-map outcomes that do not require a URL. No dedicated issue was identified for these corrections; the remaining cases were raised in review.

Change and scope

  • Resolve legacy ESM subpaths with URL suffix and directory semantics. Admit preprocessed pathname text before encoded dot segments can disappear.
  • Check relative traversal depth before constructing the synthetic file URL. Preserve permitted parent traversal and significant empty URL segments while rejecting root escape and reentry.
  • Construct package URLs only for relative target selection. Request-local opaque identities preserve structural containment when metadata cannot be represented as a URL. Lookup remains unavailable while an opaque segment remains; traversal beyond it can resolve a representable same-container target.
  • Preserve imports/exports metadata path, map kind, and selected raw target on unavailable outcomes.

Existing upstream integrations and the bounded Apple fixture compiler timeout are retained.

Contract and boundary impact

  • Semantic owner: package URL admission and finalization in JavaScriptArtifactPathResolution, before graph relationships are projected.
  • Contribution scope: correctness within existing offline analysis. A new maintainer authority decision is not applicable.
  • CLI/MCP: no schema or tool-catalog change. Corrected statuses, paths, and limitations flow through both surfaces.
  • Compatibility: CommonJS, package-main probing, and exact package-map keys retain their existing owners.
  • Evidence: raw requests, source identities, selected targets, and unavailable outcomes remain explicit.
  • Authority/cleanup: no new target execution or resource ownership.
  • Generated metadata, dependencies, installation, or migrations: none.

Expected effects:

  • Read existing files or captured data.

Evidence and regression coverage

Existing CLI/stdio MCP fixtures cover loader behavior, suffixes, directory forms, encoded-dot admission, package-map selection, and real ASAR Unicode identities. Added regression source covers synthetic-root escape/reentry, allowed parent traversal, empty segments, query/fragment controls, and imports/exports provenance on unavailable targets.

Source inspection establishes the affected branches and their corrected handling. The new regression cases have not been executed.

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity and source provenance remain preserved.
  • Unsupported and unavailable outcomes remain visible.

Validation performed

Merged current main (cf0a38a). The doctorHopperDiscovery CI failure came from the older base and passes after the merge. Executed on Node 24.19.0 (macOS arm64): npm run test:focused -- tests/boundary/cli/doctorHopperDiscovery.test.ts tests/acceptance/applications/packageSpecifierSuffixCli.test.ts tests/acceptance/applications/packageUrlUnicodeCli.test.ts, 7/7 passed through CLI and stdio MCP; pre-push typecheck and lint passed. Independent run by CassieFox23 on Linux, Node 24.18.0 and 26.11.1: the PR test files pass, and 4 of them fail on main. Not run: Windows, Node 22, the full suite, real app ASARs.

Compatibility, safety, and release

No public contract or dependency change. Artifact-root confinement is checked before lossy URL normalization; symlink following or target execution is not introduced. Runtime and cross-platform behavior of the latest changes remain unverified.

Author readiness

Human owner: @rohitg00

  • 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

  • Concrete problem, contribution scope, and semantic owner identified.
  • Regression sources and relevant consumers updated.
  • Final source diff reviewed for unrelated changes and unsupported claims.
  • Latest changes verified by required automated checks.

Maintainer blocker verification

The remaining resolver changes stay within the existing offline artifact inventory: no new symlink following, outside-filesystem lookup, URL fetch, provider, execution or mutation is added. The static-scope routine-fix exception therefore applies. On the exact current head, Node 24.18.0/npm 11.16.0, packageSpecifierSuffixCli.test.ts and packageUrlUnicodeCli.test.ts passed 6/6 through CLI and stdio MCP, and check:fast passed. Coverage includes artifact-root escape/re-entry, Unicode/unrepresentable paths and explicit unavailable outcomes. No target execution was performed.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 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-15T06:20:52.064382Z be52121 New commits
ℹ️ 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.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge, with no blocking code issue found.

Summary

The remaining changes reject artifact-root escape before URL parsing and preserve package-map source details when a selected target cannot be looked up.

  • Legacy ESM imports stay within the artifact root.
  • Unavailable package-map results name the selected target.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Legacy ESM subpath] --> B[Preprocess URL text and remove suffixes]
  B --> C[Reject forbidden path syntax]
  C --> D[Check traversal depth]
  D -->|Escapes root| E[Rejected]
  D -->|Stays inside root| F[Construct URL]
  F --> G[Check root and directory form]
  G --> H[Look up exact inventoried file]
Loading

Reviews (17) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0f83944c7c

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9bd18e7fb6

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 49c0023885

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 60c667b882

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ec811e576f

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2628578467

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0cefcd2126

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e3f8c65310

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Review findings addressed at their producing boundaries and consumers. Latest changes were reviewed from source; tests and provider runs were skipped at the maintainer's request. Findings requiring separate decisions or verification remain open.

  1. thread 1

The UTF-8 replacement fallback collapsed lone surrogates onto a real U+FFFD sibling identity. Structural package segments now retain exact lone UTF-16 code units as distinct WTF-8 escapes, while final target admission validates only the relative target and preserves the unavailable lookup limitation. No replacement-character path can supply the original surrogate package identity.

Current source: e3f8c65. Validation: source inspection only; tests and checks were skipped at the user's explicit request.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cbe29d92b1

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Review findings addressed at their producing boundaries and consumers. Latest changes were reviewed from source; tests and provider runs were skipped at the maintainer's request. Findings requiring separate decisions or verification remain open.

  1. thread 1

The structural WTF-8 ancestor was entering normal URI decoding after legacy traversal, so an unrepresentable base became a malformed-target rejection. The metadata URL owner now assigns valid request-local structural identities and retains the original path limitation separately. Legacy resolution uses the canonical artifact-root path for admission, classifies URL directory form, and reports unavailable before any lookup of the unrepresentable base. Removed the separate encodedAdmissionPath representation and package-relative slicing from both consumers. The existing public CLI/MCP ASAR matrix now includes parent-traversed legacy files and directory forms.

Current source: cbe29d9. Validation: source inspection only; authored regressions were not executed. Tests, checks, builds and provider execution were skipped at the user's explicit request. No passing runtime or real-provider result is claimed. Directly related representation and consumer cleanup is included.

  1. thread 1

The WTF-8 structural marker could be spelled by package target text, allowing an escaping entry to appear to re-enter the package root. The metadata URL owner now allocates request-local ASCII structural identities absent from both source paths and the target after URL tab/newline preprocessing. These identities are used only for admission; the original inventory path remains explicitly unavailable for lookup. Removed the old WTF-8 encoder and encodedAdmissionPath repair. Added CLI/MCP ASAR cases for both WTF-8 re-entry and tab-split placeholder re-entry with external fallback.

Current source: cbe29d9. Validation: source inspection only; authored regressions were not executed. Tests, checks, builds and provider execution were skipped at the user's explicit request. No passing runtime or real-provider result is claimed. Directly related representation and consumer cleanup is included.

@morluto morluto added bug Something isn't working area: domain Domain logic, errors, and pure functions P2: medium Medium priority issue labels Oct 13, 2026
@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Source fixes and publication evidence for the review findings below. Tests and executable checks were skipped at the maintainer's request. Findings that still require a decision or execution evidence remain open.

review thread

The package metadata path can contain an unpaired UTF-16 surrogate, so its structural URL uses opaque segments. The resolver now retains the exact generated marker set and reports the representability limitation only when a marker survives URL normalization. If parent traversal removes the marker, it checks the representable candidate against the inventory and returns the resulting found or missing outcome. This is public in commit 980611ed39280c03a39eddf3f6c42370d89181fd, the live PR head. Validation was source inspection and diff review only. Tests, builds, checks, CLI execution, and CI reruns were skipped as instructed; no runtime claim is made. No directly related source cleanup remains.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed7e8e3fc2

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

morluto added a commit that referenced this pull request Oct 14, 2026
Preserve CommonJS literal paths and confined ESM URL semantics, including package main fallback, directory intent, Unicode identity, and present opaque modules. Parse extraction inputs at their AST/source owner, retain skipped HTML and source-map coverage, and distinguish endpoint candidates from proven receiver facts. Version structural fingerprints with computed literal contents and propagate them through worker contracts.

Reviewed fixes include #1810, #1840, #2642, #2700, #2702, #2714, #2803, #2960, #2968, #2986, #3035, and #3036.

Validation: 158 resolver tests passed; public CLI/MCP module lookup controls, package-main/Unicode workflows, and six builtin workflows passed in the current compiled lane. Worker schema/fingerprint regressions passed. Large public pdf.js completion and real Electron analysis remain unverified.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@rohitg00 rohitg00 changed the title fix(javascript): preserve legacy ESM directory intent fix(javascript): preserve ESM path intent and artifact confinement Oct 14, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@rohitg00
rohitg00 marked this pull request as draft October 14, 2026 10:14
@rohitg00
rohitg00 marked this pull request as ready for review October 14, 2026 10:22
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: The PR works on Node 24.18.0 and 26.11.1. Four tests that fail on main pass with it. Main still marks three escaping imports as resolved, and the PR rejects them.

I tested head 3ca3697 as pushed. GitHub says it merges cleanly with main f09f454 (#3833). Main already holds the earlier rounds of this PR. Commit b58adaf names #2700. It sits inside the PR's base 44d98de. Main has none of what is left: 19 changed source lines and 74 added test lines.

Results

Check Node 24.18.0 Node 26.11.1
The two PR test files on head (6 tests) 6 pass 6 pass
The same two files on main f09f454 (#3833) 4 fail, 2 pass 4 fail, 2 pass
The same two files on main plus the PR's source change 6 pass not run
CLI import fixture on head 3 rejected, 3 resolved 3 rejected, 3 resolved
CLI import fixture on main 6 resolved 6 resolved
CLI import fixture on main plus the PR's source change 3 rejected, 3 resolved not run

The fixture holds outside.js at the root and an empty package at node_modules/legacy. The importer asks for six legacy paths. Main resolves all six to outside.js. Three of them climb out past the artifact root and name the private rea-artifact folder:

  • legacy/../../../rea-artifact/outside.js
  • legacy/../../../../rea-artifact/outside.js
  • legacy/../.\t./.\n./rea-artifact/outside.js?cache=1#entry

Head rejects those three. Its evidence says they escape the canonical artifact root. The other three still resolve. Greptile raised this case in review.

The four failures on main are the two traversal tests and the two Unicode tests. The Unicode tests fail on a missing line. That line should name the selected imports target. It comes from the PR's second change.

The CI log for this head shows one failing test. It is a Hopper launcher test that calls doctor, in a file this PR does not touch. Three shards were cancelled, so their results are unknown. I did not run any of these. That reading comes from the CI log and is unchecked by me.

Not run

  • A hand-made ASAR fixture with a lone surrogate. The PR's own Unicode test covers that case.
  • Node 22, and Node 26 on main plus the PR's source change.
  • Windows, macOS, the rest of the suite, and every file that calls setup or doctor.
  • A real app ASAR.

Thanks, rohitg00, for the fix and the thorough tests.

Test setup
Commands
npm ci && npm run build && npm run test:prepare
npm run test:focused -- tests/acceptance/applications/packageSpecifierSuffixCli.test.ts tests/acceptance/applications/packageUrlUnicodeCli.test.ts
node scripts/rea.mjs analyze-javascript-application <fixture> --format json

Main plus the PR: I copied the PR's two test files onto main and applied its source diff. The patch applied with an offset of 74 lines and no conflicts. Each run sat under systemd-run with a 6 GB memory cap, at nice 19.

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@morluto
morluto merged commit 6714fb1 into morluto:main Oct 22, 2026
66 checks passed
@morluto morluto mentioned this pull request Oct 25, 2026
3 tasks done
@morluto morluto added the area: evidence Evidence, artifacts, and reconstruction label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions area: evidence Evidence, artifacts, and reconstruction bug Something isn't working P2: medium Medium priority issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants