Repository navigation
fix(npm): reject symlinked package materialization dirs - #36191
Conversation
bartlomieju
left a comment
There was a problem hiding this comment.
Nice fix — the ensure_not_symlink before/after create_dir_all approach is right, and covering all three helpers with in-memory-fs regressions is great. Two things worth considering:
1. clone_dir_recursive_except_node_modules_child (local.rs) has the same vector but isn't hardened. It's used for patch packages and workspace members (local.rs:582, hoisted.rs:536) and still does let _ = fs_remove_dir_all(to) then fs_create_dir_all(to) then hard_link_file/fs_copy with no symlink check. On Linux, remove_dir_all on a symlinked to fails with NotADirectory and the error is discarded, so the symlink stays, create_dir_all succeeds (target is a dir), and package files get written through the redirected path — the exact write-through this PR closes in the other three helpers. Worth routing this destination through create_dir_all_no_symlink/ensure_not_symlink too so the fix is complete.
2. Minor: ensure_not_symlink/create_dir_all_no_symlink are duplicated verbatim in both libs/npm_cache/fs_util.rs and libs/npm_installer/fs.rs. Since npm_installer already depends on npm_cache (it calls deno_npm_cache::hard_link_dir_recursive), these could be exported once from npm_cache and reused rather than kept in two places where they can drift. Non-blocking.
## Summary - reject symlinked package materialization destinations - apply the check to both hard-link and copy paths - cover both helpers with in-memory filesystem regressions ## Details Package initialization previously treated an existing symlinked destination as a directory. Creating the destination and then hard-linking or copying package files could therefore write through that redirected path. Materialization now checks each destination directory before and after creation using symlink-aware metadata. Existing ordinary directories continue to work as before, while a symlinked destination returns an ordinary filesystem error. ## Validation - `./tools/format.js --check` - `cargo test -p deno_npm_cache hard_link_dir_recursive -- --nocapture` - `cargo test -p deno_npm_installer copy_dir_recursive -- --nocapture` AI assistance was used to help implement and test this change.
…e ×3, deno, nushell, pydantic), blind-annotated v2 labels pending approval Seeded with seed-corpus-from-external.sh --commit-trees from merged PRs of public MIT repositories no thj member touched, each with a later fix commit on the default branch that touches the PR's files (toward gate G3: ≥ 10 public-repo fixtures; this lands the public leg at 11): pr-54 vitejs/vite#23879 fix e954a9cda0b5 (watch new URL(..., import.meta.url) assets with a query or hash) pr-55 vitejs/vite#23777 fix 4d16e7c14d5e (preload dependencies in chunk import-map hashing) pr-56 vitejs/vite#23667 fix a7d56967ef00 (skip the patches-dir hash for the nub lockfile) pr-57 denoland/deno#36191 fix 5f2241642635 (validate npm package link names) pr-58 nushell/nushell#18376 fix aa89ea092a57 (dc-glob relative vs absolute paths) pr-59 pydantic/pydantic#13079 fix a6bf50b721c2 (ValidationInfo.field_name under model_validate_json) Each fixture: head/ base/ head.diff PR.md, the instruction templates, upstream/LICENSE, external/pr-NN.json provenance (visibility public), incident-scan.sh --no-gh --window-days 30 over the source clone (pr-55 2, pr-56 1, the others 0), THIRD-PARTY.tsv rows (MIT), corpus.tsv rows (kind external), the two recall tasks. Labels: two blind Opus 5.5 annotators per fixture over annotation-packets.sh packets (blind-session.sh, container, trace growth-fixtures-pr-NN-{A,B}), annotation_merge.py, the lead's adjudication where they differed (pr-55 11 items, pr-56 1, pr-57 12; decisions.json beside each adjudication.json); 14 defects, label_source fix-commit (12) or incident (2), review_driven false; pooled hunk-verdict kappa 0.906 over 58 hunks (pooled-2026-10-26-growth/kappa.json). Every label file says `# approved-by: pending` and every manifest `approved: false` until the maintainer approves (seed-corpus-from-record.sh --approve). pr-58 and pr-59 predate the Fable 5.1 cutoff (exposure pre-cutoff, recorded in fixture.yaml). Annotation spend USD 1.11 (12 sessions, spend-rows.jsonl). SHA256SUMS refrozen (2,030 files); both --check modes pass. Caveat recorded in the run notes: annotation-packets.sh diffs the PR head against the fix commit, so a fixture whose fix landed after other commits to the same files shows those hunks too (pr-57 15 of 29 hunks, pr-55 5 of 17, pr-59 2 of 5 lie outside the seeder's fix regions). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Summary
Details
Package initialization previously treated an existing symlinked destination
as a directory. Creating the destination and then hard-linking or copying
package files could therefore write through that redirected path.
Materialization now checks each destination directory before and after
creation using symlink-aware metadata. Existing ordinary directories continue
to work as before, while a symlinked destination returns an ordinary
filesystem error.
Validation
./tools/format.js --checkcargo test -p deno_npm_cache hard_link_dir_recursive -- --nocapturecargo test -p deno_npm_installer copy_dir_recursive -- --nocaptureAI assistance was used to help implement and test this change.