GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: correct string `restrictions` path boundary checks by alexander-akait · Pull Request #643 · webpack/enhanced-resolve

Conversation

@alexander-akait

@alexander-akait alexander-akait commented Jul 28, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Summary

isInside in RestrictionsPlugin decided containment with its own prefix rule, which disagrees with how path.win32 and path.posix — and therefore Windows and posix — actually compare paths. isSubPath in lib/util/path.js had the same misalignments, so the comparison now lives there once, aligned with Node, and both call sites share it. Supersedes #639 and #640 (bugs reported by @stormslowly), which fix two of these cases but key the boundary off path.sep — the host platform is the wrong signal here, see below.

restriction path before after
/a/b/c /a/b/c\sibling.js (posix sibling, \ in the filename) allowed rejected
/a/b/c/ /a/b/c/index.js rejected allowed
/a/b/c/ /a/b/c (the restricted directory itself) rejected allowed
/ /a/index.js rejected allowed
C:/a/b/c C:\a\b\c\index.js rejected allowed
C:\a\b\c C:\a\b/c/index.js rejected allowed
C:\a\b\c c:\a\b\c\index.js (differing drive-letter case) rejected allowed
\\server\share\a \\server\share\a\index.js rejected allowed

Windows treats / and \ as interchangeable and mixed within one path, and compares case-insensitively — path.win32.normalize, isAbsolute, dirname, resolve and relative all agree — so C:\a\b, C:/a/b and c:\A\B name the same directory and now all match each other. Posix does neither, so \ stays an ordinary filename character there, which is what keeps the escape closed.

In lib/util/path.js: isWindowsPath decides the flavor from the root — a drive letter or a leading \, which is exactly where win32.parse and posix.parse disagree about root — never from process.platform. This package resolves Windows paths on posix hosts and vice versa, and runs in browsers, Deno and Bun; deriving the separator from path.sep makes every path inside a C:\… restriction unresolvable on Linux, and every path inside a /… restriction unresolvable on Windows. Deciding by root rather than by "contains a backslash" also keeps a posix directory whose name contains \ comparing correctly. isInside answers containment the way relative(parent, child) does — including the parent itself, and ignoring a trailing separator on it — and isSubPath keeps its stricter "not a subpath of itself" rule on top of the same comparison, so TsconfigPathsPlugin gets the alignment too. One deliberate divergence from path.win32: a path starting with // stays posix, since it is indistinguishable from a posix path here and \ has to keep being a filename character in one.

RestrictionsPlugin imports from ./util/path only — no direct path use, so the browser shim keeps covering it — and normalizes each restriction once in the constructor. The posix hot path costs what it did before (a native startsWith is the whole answer); the character loop only runs for a Windows path whose spelling differs in separators or case, and the whole-string lowercase only for non-ASCII, matching how Node folds case. Measured on the isSubPath shape TsconfigPathsPlugin calls in its per-resolve loop: posix unchanged, Windows about 17 ns/call slower on a miss. The duplicated log/marker/callback tail in apply is now shared by both restriction kinds.

Out of scope, worth a separate look: getType classifies plain UNC (\\server\share) as Normal, which is already flagged in its tests. That makes normalize, join and dirname treat UNC paths as posix — join("\\\\server\\share\\a", "./index.js") yields a mixed \\server\share\a/index.js, .. segments are not collapsed, and dirname("\\\\server\\share\\a\\b") returns ".". The comparison here handles UNC correctly regardless, so fixing that is not needed for this change.

What kind of change does this PR introduce?

fix

Did you add tests for your changes?

Yes. test/path.test.js covers isWindowsPath, isInside and the newly aligned isSubPath behavior, alongside its existing cases, which all still hold. test/restrictions.test.js adds thirteen cases that run through the resolver on every host against a fake filesystem, precisely because the resolver is platform-agnostic, and twelve that drive the plugin directly for the forms the resolver normalizes away before they reach it. On top of those, a generated matrix asserts the plugin against Node's relative() verdict for every restriction/path pair, so the two cannot drift; pairs relative() cannot answer (a non-absolute input, which it resolves against process.cwd()) are skipped, and a guard fails if the matrix stops producing both verdicts.

Does this PR introduce a breaking change?

No. Paths that resolved before still resolve; a filename whose leading characters happen to match a restriction followed by \ no longer escapes it on posix.

If relevant, what needs to be documented once your changes are merged?

n/a

Use of AI

Written with Claude Code. It reproduced each case against main first, wrote the failing tests before the fix, and checked the helpers against Node's path API over ~1000 restriction/path pairs, including mutation-testing that harness to confirm it catches each regression; I reviewed the result. npm run lint, npm run test:only and npm run test:browser all pass locally.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@alexander-akait
fix: correct string restrictions path boundary checks
638de3f
`isInside` assumed a restriction never ends with a separator and treated `\`
as a separator on every platform, so `restrictions: ["/a/b/c/"]` (or `["/"]`)
rejected everything inside it, while `/a/b/c\sibling.js` escaped `/a/b/c` on
posix, where `\` is an ordinary filename character.

The segment boundary is now derived from the restriction itself — never from
`process.platform`, since Windows paths are resolved on posix hosts and in
browsers too — and restrictions are normalized once, so they are compared in
the same shape requests arrive in.
@changeset-bot

changeset-bot Bot commented Jul 28, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 569e7a9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
enhanced-resolve Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@codecov

codecov Bot commented Jul 28, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.00599% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.11%. Comparing base (2bcac6e) to head (569e7a9).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
lib/util/path.js 97.65% 3 Missing ⚠️
lib/RestrictionsPlugin.js 94.87% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #643      +/-   ##
==========================================
- Coverage   98.12%   98.11%   -0.01%     
==========================================
  Files          49       49              
  Lines        9902    10023     +121     
==========================================
+ Hits         9716     9834     +118     
- Misses        186      189       +3     
Flag Coverage Δ
integration 98.11% <97.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@codspeed

codspeed Bot commented Jul 28, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Merging this PR will regress 2 benchmarks

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 2 improved benchmarks
❌ 2 regressed benchmarks
✅ 138 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Memory tsconfig-extends: 3-level extends chain (warm) 4.9 KB 98.5 KB -94.99%
❌ Simulation tsconfig-extends: 3-level extends chain (warm) 2.1 ms 2.4 ms -10.47%
⚡ Memory extensions-many: 6-extension list (warm) 96.6 KB 1.9 KB ×51
⚡ Memory node-compare: node require.resolve x 1000 25.4 KB 21.2 KB +19.79%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing claude/enhanced-resolve-pr-639-24ru77 (569e7a9) with main (5e2e296)

Open in CodSpeed
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

alexander-akait added 3 commits July 28, 2026 15:50
@alexander-akait
fix: treat / and \ as interchangeable inside a windows restriction
7565690
Windows accepts both separators and allows them mixed within one path, so
`C:\a\b`, `C:/a/b` and `C:\a/b` name the same directory. The prefix test now
ignores which one is used when the restriction is a windows path, while other
paths keep comparing exactly, where `\` is a filename character.
@alexander-akait
fix: match node's path semantics when comparing a restriction
82e5c31
The boundary check is now verified against Node's own `path` API instead of
assumptions about how paths are shaped: a target is inside a parent when
`relative(parent, target)` neither escapes upward nor is absolute, with the
flavor taken from where `win32` and `posix` disagree about `parse().root`.

Three cases were off. Windows compares case-insensitively, so a differing
drive letter no longer rejects a path inside its restriction. A restriction
ending with a separator now contains the restricted directory itself. The
flavor is decided by the root rather than by a backslash anywhere in the
path, so a posix directory whose name contains a backslash keeps comparing
as a filename character.

The plugin now uses `path.win32`/`path.posix` directly rather than the
internal path helper, since it already knows which flavor applies, and both
are part of the browser shim.
@alexander-akait
refactor: align the path helpers with node instead of using node's path
569e7a9
The comparison belongs in `lib/util/path.js`, not in the plugin: `isSubPath`
had the same misalignments the restriction check had, and both now share one
implementation. `isWindowsPath` decides the flavor from the root, the way
`path.win32` and `path.posix` disagree about `parse().root`, and `isInside`
answers containment the way `relative()` does, including the parent itself.

`RestrictionsPlugin` goes back to importing from `./util/path` only, so the
browser shim keeps covering it.

The posix hot path keeps its cost: a native `startsWith` is still the whole
answer there, and the character loop only runs for a Windows path whose
spelling differs in separators or case.
@alexander-akait
alexander-akait merged commit d8693b6 into main Jul 28, 2026
35 of 38 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@alexander-akait
alexander-akait deleted the claude/enhanced-resolve-pr-639-24ru77 branch July 28, 2026 16:45
@github-actions github-actions Bot mentioned this pull request Jul 28, 2026
chore(release): new release #642
Merged
@alexander-akait alexander-akait mentioned this pull request Jul 28, 2026
fix: route UNC paths through win32 instead of posix #644
Merged
alexander-akait added a commit that referenced this pull request Jul 28, 2026
@alexander-akait
fix: route UNC paths through win32 instead of posix (#644)
10fcea0
**Summary**

`getType` accepted only the DOS device forms (`\\?\`, `\\.\`) as
windows-absolute, so a plain UNC share fell through to `Normal` and
every helper answered it with posix semantics. `path.win32` roots any
path starting with two backslashes, so both forms are windows-absolute
and both now take that branch.

| call | before | after / `path.win32` |
| --- | --- | --- |
| `dirname("\\\\server\\share\\a\\b")` | **`"."`** | `\\server\share\a`
|
| `join("\\\\server\\share\\a", "./index.js")` |
**`\\server\share\a/index.js`** | `\\server\share\a\index.js` |
| `normalize("\\\\server\\share\\a\\..\\b")` | **unchanged** |
`\\server\share\b` |
| `Resolver.isModule("\\\\server\\share\\a")` | **`true`** | `false` |

The `dirname` and `isModule` rows are the ones that bite: walking up
from a share to find a `package.json` gave up immediately at `"."`, and
an absolute share path was reported as a bare module request, so it was
looked for in `node_modules` instead of being resolved as a path.
Resolving anything on a network share was broken as a result.

`getDosDeviceType` is gone since the two forms no longer need telling
apart, which also drops a call from `getType`; it measures marginally
faster (89 ms vs 94 ms per 11M calls on a realistic mix of requests).

The helpers pick a flavor by path shape and then have to answer the way
that flavor does, so `test/path.test.js` now asserts that directly
against `path.win32`/`path.posix` — a curated list of shapes plus 5000
seeded generated ones, comparing the flavor, `normalize`, `dirname` and
`join` (~270 ms). Reverting this fix fails 22 of them.

Every shape we answer differently on purpose is listed in one place and
asserted on its own, next to what node does with it, so a divergence can
only be added deliberately:

- **A leading forward slash is a posix root**, however the separator
after it is spelled — `path.win32` reads `//server/share` *and*
`/\server\share` as UNC roots.
- **A single leading backslash** is a rooted path on Windows and an
ordinary filename character everywhere else; nothing in the string tells
the two apart.
- **Drive-relative paths** (`C:foo`, no separator after the colon) stay
`Normal`, as they already did on `main`. `path.win32` gives them the
root `C:` but reports them as *not* absolute, and `PathType` has no
windows-relative member — classifying them as `AbsoluteWin` would make
`join` treat them as absolute and drop the root, trading one
misalignment for another. Worth its own change.
- **Relative, empty and internal (`#…`) requests**, where the resolver
deliberately keeps its own semantics (a `./` prefix is preserved, an
empty path stays empty).

Found while reviewing #643, which fixes the restriction boundary check.
That PR is independent of this one — its comparison already handles UNC
— and they touch different parts of `lib/util/path.js`.

**What kind of change does this PR introduce?**

fix

**Did you add tests for your changes?**

Yes. `test/unc-paths.test.js` resolves against a UNC context through the
public API — a relative request, a nested directory, an absolute share
request from an unrelated context, and a description-file `main` — all
four fail on `main` and pass here. They run on every host against a fake
filesystem, since a real share cannot be mounted in CI and the resolver
picks the path flavor from the path rather than from the host.
`test/path.test.js` covers `getType`, `normalize`, `join` and `dirname`
directly, and adds the alignment suite described above.

**Does this PR introduce a breaking change?**

No, unless a posix path literally starting with `\\` was being resolved,
which would previously have been treated as a relative filename.

**If relevant, what needs to be documented once your changes are
merged?**

n/a

**Use of AI**

Written with Claude Code. It compared every helper against
`path.win32`/`path.posix` before and after — a curated matrix plus 70k
generated shapes — wrote the failing tests first, mutation-tested the
new alignment suite to confirm it catches the regression, and
benchmarked `getType` to confirm the hot path did not regress; I
reviewed the result. `npm run lint`, `npm run test:only` and `npm run
test:browser` all pass locally.
alexander-akait pushed a commit that referenced this pull request Jul 28, 2026
@github-actions
chore(release): new release (#642)
24c3521
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## [email protected]

### Patch Changes

- Keep the original request resolvable when `extensionAlias` lists its
own extension. (by
[@alexander-akait](https://github.com/alexander-akait) in
[#641](#641))

- Fix string `restrictions` boundary checks: a restriction ending with a
separator no longer rejects everything inside it, restrictions are
normalized before they are compared, and a Windows path now matches the
way `path.win32` does, treating `/` and `\` as interchangeable and
comparing case-insensitively, while `\` stays a filename character in a
posix path. The same comparison backs `tsconfig` path matching. (by
[@alexander-akait](https://github.com/alexander-akait) in
[#643](#643))

- Treat a UNC path (`\\server\share\…`) as a Windows path, so it
normalizes, joins and walks up with `path.win32` semantics instead of
being taken for a bare module request. (by
[@alexander-akait](https://github.com/alexander-akait) in
[#644](#644))

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@stormslowly stormslowly mentioned this pull request Jul 29, 2026
fix(restrictions): compare a directory restriction by path components rstackjs/rspack-resolver#288
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@alexander-akait
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.