Skip to content

fix(ext/node): tolerate unreadable cwd in require._nodeModulePaths#34542

Merged
littledivy merged 1 commit into
mainfrom
orch/divybot-284
May 30, 2026
Merged

fix(ext/node): tolerate unreadable cwd in require._nodeModulePaths#34542
littledivy merged 1 commit into
mainfrom
orch/divybot-284

Conversation

@divybot

@divybot divybot commented May 29, 2026

Copy link
Copy Markdown
Contributor

Summary

op_require_node_module_paths always called env_current_dir() for non-file:/// paths, even when the incoming from was already absolute. On macOS, getcwd(3) walks the directory tree from / and fails with EACCES if any ancestor is unreadable — e.g. running under su nonadmin -c "..." from a directory the unprivileged user can't read, the scenario from #21585. That cwd lookup then bubbled up as NotFound: Unable to get CWD, crashing createRequire(import.meta.url) (which deno injects when deno -e is spawned as a child process via child_process.spawn) even though the absolute import.meta.url path didn't need cwd at all.

Skip the cwd lookup when from is already absolute. The previous fix #33587 made Eval/Repl fall back to a sentinel cwd at the workspace-factory layer, but the node-compat require ops sat below that and re-fetched cwd directly.

Test plan

Enables and passes two previously-skipped Node compat tests that spawn deno -e 0 with the parent's cwd already unlinked (the same failure mode as the original macOS bug, just reachable on Linux):

  • parallel/test-cwd-enoent.js
  • parallel/test-cwd-enoent-preload.js

parallel/test-cwd-enoent-repl.js (already enabled by #33587) continues to pass.

$ cargo test --test node_compat test-cwd-enoent
test node_compat::parallel::test-cwd-enoent-preload.js ... ok
test node_compat::parallel::test-cwd-enoent-repl.js ... ok
test node_compat::parallel::test-cwd-enoent.js ... ok

Closes denoland/orchid#284

`op_require_node_module_paths` always called `env_current_dir()` for
non-`file:///` paths, even when the incoming `from` was already absolute.
On macOS, `getcwd()` walks the directory tree from `/` and fails with
EACCES if any ancestor is unreadable (e.g. running under `su nonadmin`
from a directory the unprivileged user can't read — see deno#21585),
which crashed `createRequire(import.meta.url)` for any spawned `deno -e`
child even though the absolute path didn't need the cwd at all.

Skip the cwd lookup when `from` is already absolute, and enable the
previously-disabled node compat tests `test-cwd-enoent.js` and
`test-cwd-enoent-preload.js` which exercise this path.

Closes denoland/orchid#284

Co-Authored-By: Divy Srivastava <[email protected]>
@littledivy
littledivy merged commit b2d8713 into main May 30, 2026
136 checks passed
@littledivy
littledivy deleted the orch/divybot-284 branch May 30, 2026 01:56
littledivy added a commit to crowlKats/deno that referenced this pull request Jun 10, 2026
…enoland#34542)

## Summary

`op_require_node_module_paths` always called `env_current_dir()` for
non-`file:///` paths, even when the incoming `from` was already
absolute. On macOS, `getcwd(3)` walks the directory tree from `/` and
fails with `EACCES` if any ancestor is unreadable — e.g. running under
`su nonadmin -c "..."` from a directory the unprivileged user can't
read, the scenario from denoland#21585. That cwd lookup then
bubbled up as `NotFound: Unable to get CWD`, crashing
`createRequire(import.meta.url)` (which deno injects when `deno -e` is
spawned as a child process via `child_process.spawn`) even though the
absolute `import.meta.url` path didn't need cwd at all.

Skip the cwd lookup when `from` is already absolute. The previous fix
denoland#33587 made `Eval`/`Repl` fall back to a sentinel cwd at the
workspace-factory layer, but the node-compat require ops sat below that
and re-fetched cwd directly.

## Test plan

Enables and passes two previously-skipped Node compat tests that spawn
`deno -e 0` with the parent's cwd already unlinked (the same failure
mode as the original macOS bug, just reachable on Linux):

- `parallel/test-cwd-enoent.js`
- `parallel/test-cwd-enoent-preload.js`

`parallel/test-cwd-enoent-repl.js` (already enabled by denoland#33587) continues
to pass.

```
$ cargo test --test node_compat test-cwd-enoent
test node_compat::parallel::test-cwd-enoent-preload.js ... ok
test node_compat::parallel::test-cwd-enoent-repl.js ... ok
test node_compat::parallel::test-cwd-enoent.js ... ok
```

Closes denoland/orchid#284

Co-authored-by: divybot <[email protected]>
Co-authored-by: Divy Srivastava <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants