Repository navigation
fix(init): validate temporary node_modules parent - #36142
Conversation
|
Nice hardening. Validating the root/dated dirs before running cleanup and falling back gracefully instead of hard-erroring is a clear improvement, and the two new tests cover the repair and symlink-rejection paths well. One security nuance worth a look, given the intent of the change: The flow is:
If an attacker can replace the The practical precondition is a parent the attacker can write to:
So this isn't exploitable on a correctly configured system, but since the whole point of the PR is symlink/permission safety, it may be worth closing the window:
Minor, non-blocking: on a multi-user host where another user already owns |
|
Solid hardening, and the fd-tied chmod + ownership check + 1. The fd-based validation guards only the chmod, not the destructive GC that runs by path right after. In The comment ("Keep the check, permission repair, and final validation tied to the same directory so replacing the path cannot redirect the chmod") is accurate for the chmod, but that guarantee doesn't extend to the GC or the subsequent 2. Fallback temp dirs ( Neither is blocking. |
## Summary - validate the temporary `node_modules` root and dated directory before use - create Unix directories with owner-only permissions and repair permissive modes - fall back to a fresh random temporary directory when the preferred layout is unusable ## Details `create_temp_node_modules_dir()` assumed that `<tmp>/deno_nm` was a usable directory and ran dated-directory cleanup before validating it. Unexpected filesystem entries or permissive directory modes could therefore affect both cleanup and package initialization. The preferred root and dated directory are now checked before cleanup or use. If the preferred layout cannot be established, initialization continues in a fresh temporary directory without running cleanup through that path. ## Validation - `./tools/format.js --check` - `cargo test -p deno util::temp --lib -- --nocapture` - `cargo check -p deno` AI assistance was used to help implement and test this change.
Summary
node_modulesroot and dated directory before useDetails
create_temp_node_modules_dir()assumed that<tmp>/deno_nmwas a usabledirectory and ran dated-directory cleanup before validating it. Unexpected
filesystem entries or permissive directory modes could therefore affect both
cleanup and package initialization.
The preferred root and dated directory are now checked before cleanup or use.
If the preferred layout cannot be established, initialization continues in a
fresh temporary directory without running cleanup through that path.
Validation
./tools/format.js --checkcargo test -p deno util::temp --lib -- --nocapturecargo check -p denoAI assistance was used to help implement and test this change.