Commit d535582
fix(permissions): treat Windows
On Windows, requesting a path through its `\\?\` verbatim
(extended-length) form — e.g. `\\?\C:\foo` — was permission-checked as a
*distinct* path from the regular `C:\foo`. As a result, a directory
already granted read/write access would unexpectedly trigger a new
permission prompt:
```
> deno repl --allow-read=.
> Array.from(Deno.readDirSync(Deno.cwd())) // no prompt
[]
> Array.from(Deno.readDirSync('\\\\?\\' + Deno.cwd())) // unexpected prompt
✅ Granted read access to "\\?\C:\Users\Student\Empty".
[]
```
This also breaks node polyfills that hand `\\?\`-prefixed paths to fs
ops (e.g. `_fs_chmod.ts`, see wojpawlik/deno2node#39).
### Cause
The path descriptors in `deno_permissions` build their comparison key
with `deno_path_util::normalize_path`, which walks `path.components()`.
Rust parses `\\?\C:\foo` as a `Component::Prefix(VerbatimDisk)`, and
`normalize_path` preserves that verbatim prefix, so `\\?\C:\foo` and
`C:\foo` never compare equal. The existing `is_windows_device_path`
branch only handled `\\.\` device-namespace paths.
### Fix
Strip the verbatim prefix via `dunce::simplified` before normalization,
at the three path-descriptor construction sites
(`PathQueryDescriptor::new`, `PathQueryDescriptor::new_known_absolute`,
`PathDescriptor::new_known_cwd`).
`dunce::simplified` only strips the prefix when the regular form is
genuinely equivalent — it refuses paths containing `.`/`..` components
(taken literally in verbatim mode), reserved DOS device names (`CON`,
`NUL`, `COM1`, …), or paths that exceed the legacy length limit. Those
forms are *not* the same file as their stripped counterpart, so this
conservative behavior avoids over-granting. On non-Windows platforms the
helper is a no-op, so behavior there is unchanged.
A `#[cfg(windows)]` unit test (`check_path_verbatim_prefix`) covers both
directions (grant regular → request verbatim, and grant verbatim →
request regular) plus a negative case.
Closes #18597
Closes denoland/divybot#553
---------
Co-authored-by: divybot <divybot@users.noreply.github.com>
Co-authored-by: Divy Srivastava <me@littledivy.com>\\?\ verbatim paths as equivalent (#35096)1 parent ee9e5c7 commit d535582
4 files changed
Lines changed: 69 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
352 | 352 | | |
353 | 353 | | |
354 | 354 | | |
| 355 | + | |
355 | 356 | | |
356 | 357 | | |
357 | 358 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1345 | 1345 | | |
1346 | 1346 | | |
1347 | 1347 | | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
1348 | 1376 | | |
1349 | 1377 | | |
1350 | 1378 | | |
| |||
1354 | 1382 | | |
1355 | 1383 | | |
1356 | 1384 | | |
| 1385 | + | |
| 1386 | + | |
1357 | 1387 | | |
1358 | 1388 | | |
1359 | 1389 | | |
| |||
1382 | 1412 | | |
1383 | 1413 | | |
1384 | 1414 | | |
| 1415 | + | |
1385 | 1416 | | |
1386 | 1417 | | |
1387 | 1418 | | |
| |||
1546 | 1577 | | |
1547 | 1578 | | |
1548 | 1579 | | |
| 1580 | + | |
1549 | 1581 | | |
1550 | 1582 | | |
1551 | 1583 | | |
| |||
9822 | 9854 | | |
9823 | 9855 | | |
9824 | 9856 | | |
| 9857 | + | |
| 9858 | + | |
| 9859 | + | |
| 9860 | + | |
| 9861 | + | |
| 9862 | + | |
| 9863 | + | |
| 9864 | + | |
| 9865 | + | |
| 9866 | + | |
| 9867 | + | |
| 9868 | + | |
| 9869 | + | |
| 9870 | + | |
| 9871 | + | |
| 9872 | + | |
| 9873 | + | |
| 9874 | + | |
| 9875 | + | |
| 9876 | + | |
| 9877 | + | |
| 9878 | + | |
| 9879 | + | |
| 9880 | + | |
| 9881 | + | |
| 9882 | + | |
| 9883 | + | |
| 9884 | + | |
| 9885 | + | |
| 9886 | + | |
| 9887 | + | |
| 9888 | + | |
| 9889 | + | |
| 9890 | + | |
9825 | 9891 | | |
9826 | 9892 | | |
9827 | 9893 | | |
| |||
0 commit comments