Skip to content

src: resolve watched path once in FSEventWrap - #67646

Open
ShogunPanda wants to merge 1 commit into
nodejs:mainfrom
ShogunPanda:fs-watch-store-resolved-path
Open

ShogunPanda wants to merge 1 commit into
nodejs:mainfrom
ShogunPanda:fs-watch-store-resolved-path

Conversation

@ShogunPanda

@ShogunPanda ShogunPanda commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

FSEventWrap::Start() checked the read scope on the path as it was passed in, started the watch on the same string, and later used it again to check the entries reported by libuv. A relative path or a symbolic link could resolve differently at each of those steps, for example after process.chdir() or when the link was replaced.

Resolve the path to its canonical form once, check the read scope on it, and use the same path to start the watch and to check the reported entries.

Behavior changes when the permission model is enabled, limited to fs.watch() and fs.promises.watch():

  • A path whose canonical form is not granted now throws ERR_ACCESS_DENIED when the watch starts. This includes a symbolic link in a granted directory that points elsewhere, a granted path that goes through a symbolic link outside of the granted scope, and a .. that follows a symbolic link. Before, these were accepted and the names of the reported entries were dropped.
  • On macOS, a path below /private/var, /private/tmp or /private/etc is also accepted if the same path spelled with /var, /tmp or /etc is granted, and the link really resolves there. No other symbolic link is followed outside of the granted paths.
  • Watching a single file and watching the root directory report the right names.

The grants themselves, and every other API, are unchanged. Documented in doc/api/permissions.md.

Testing: rewrote test/parallel/test-permission-fs-watch-resolved-path.js, with no timers; it fails without the change. test-permission-*, test-fs-watch* and test-fs-promises-watch* pass, as do cpplint, clang-format, eslint and the markdown lint. The macOS-only branch could not be exercised on Linux.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/security-wg

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run. labels Nov 20, 2026
@ShogunPanda
ShogunPanda force-pushed the fs-watch-store-resolved-path branch from 4de050b to f7ec6a0 Compare November 20, 2026 10:16
@ShogunPanda ShogunPanda changed the title src: store resolved path in FSEventWrap src: resolve watched path once in FSEventWrap Nov 20, 2026
@ShogunPanda
ShogunPanda force-pushed the fs-watch-store-resolved-path branch from f7ec6a0 to f562b6f Compare November 20, 2026 10:26
`FSEventWrap::Start()` checked the read scope on the path as it was
passed in, then started the watch on the same string, and later used it
again to check the entries reported by libuv. A relative path or a
symbolic link could resolve differently at each of those steps, for
example after `process.chdir()` or when the link was replaced.

Resolve the path to its canonical form once, check the read scope on
it, and use the same path to start the watch and to check the reported
entries. A path whose canonical form is not granted now throws
`ERR_ACCESS_DENIED` when the watch starts, including a `..` that
follows a symbolic link.

On macOS, a path below `/private/var`, `/private/tmp` or
`/private/etc` is also accepted if the same path spelled with `/var`,
`/tmp` or `/etc` is granted. No other symbolic link is followed outside
of the granted paths, and the grants themselves are not changed.

Assisted-By: OpenAI GPT-5.6 Sol <openai/gpt-5.6-sol>
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
@ShogunPanda
ShogunPanda force-pushed the fs-watch-store-resolved-path branch from f562b6f to 8df2191 Compare November 20, 2026 10:34
@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.08108% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.71%. Comparing base (5884b8e) to head (8df2191).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/fs_event_wrap.cc 81.08% 2 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67646      +/-   ##
==========================================
- Coverage   90.71%   90.71%   -0.01%     
==========================================
  Files         801      801              
  Lines      280906   280938      +32     
  Branches    54249    54246       -3     
==========================================
+ Hits       254832   254841       +9     
- Misses      16246    16258      +12     
- Partials     9828     9839      +11     
Files with missing lines Coverage Δ
src/fs_event_wrap.cc 79.45% <81.08%> (+8.39%) ⬆️

... and 27 files with indirect coverage changes

🚀 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants