Skip to content

Read validator input safely on Windows - #69

Closed
YuukiFST wants to merge 1 commit into
cloudflare:mainfrom
YuukiFST:windows-input-fallback
Closed

YuukiFST wants to merge 1 commit into
cloudflare:mainfrom
YuukiFST:windows-input-fallback

Conversation

@YuukiFST

@YuukiFST YuukiFST commented Oct 7, 2026

Copy link
Copy Markdown

Problem

On native Windows, Node defines neither fs.constants.O_NOFOLLOW nor O_NONBLOCK, so validate-findings.cjs and validate-coverage-ledger.cjs refuse every input with OS no-follow and nonblocking input protection is unavailable. A full audit run on Windows cannot reach the "both validators pass" terminal state. The test suites hide this: the ledger suite skips its CLI tests when O_NOFOLLOW is missing, and seven findings CLI tests fail.

Change

On win32 only, when the constants are missing, readFileWithinLimit takes a fallback with the same guarantees for the final path component:

  1. Resolve the path and refuse any \ or // form (\.\pipe\..., \?\..., UNC): opening one can connect to a pipe server or start SMB authentication before any check runs.
  2. lstat with bigint: true: refuse a symbolic link (Node reports junctions as links too), a non-file, or ino 0.
  3. Open read-only.
  4. fstat the descriptor with bigint: true: refuse a non-file, or a dev, ino or birth time that differs from step 2, which closes the swap between check and open. Birth time is compared too because ReFS file IDs are not guaranteed unique.

The POSIX path, and any other platform without the constants, is unchanged. readFileWithinLimit is exported from both modules so tests can reach the fallback.

Tests

The CLI tests now run on win32 through the fallback. New win32 tests cover a symbolic link (skipped without the privilege to create one), a junction, a named pipe, a relative path, and a file deleted and recreated between lstat and open. Removing the identity check turns the swap tests red.

  • Windows 10, Node 24.20.0: 69 pass, 0 fail, 6 skip (before: 46 pass, 7 fail, 12 skip).
  • GitHub Actions windows-latest and ubuntu-latest, Node 22: both suites green, symbolic-link test runs on windows-latest.

Node on Windows defines neither O_NOFOLLOW nor O_NONBLOCK, so both
validators refuse every input there with "OS no-follow and nonblocking
input protection is unavailable", and the suites either skip their CLI
tests or fail seven of them.

On win32 only, when the constants are missing, readFileWithinLimit now:

1. resolves the path and refuses any \\ or // form (\\.\pipe\...,
   \\?\..., \\server\share), because opening one can connect to a pipe
   server or start SMB authentication before any check runs;
2. lstats the path with bigint: true and refuses a symbolic link (Node
   reports junctions as links too), anything that is not a file, or an
   ino of 0, which some file systems report when they have no file ID;
3. opens it read-only;
4. fstats the descriptor and refuses a non-file or a dev, ino or birth
   time that differs from step 2, which closes the swap between check
   and open. Birth time is compared too because ReFS file IDs are not
   guaranteed unique.

The POSIX path and every other platform without the constants are
unchanged. readFileWithinLimit is exported from both modules so the
tests can reach the fallback directly.

The CLI tests now run on win32 through the fallback. New win32 tests
cover a symbolic link (skipped when the process lacks the privilege to
create one), a junction, a named pipe (refused as a non-local path), a
relative path that still reads, and a file deleted and recreated
between lstat and open, which must fail with "input changed between
check and open". On Windows 10 with Node 24: 69 pass, 0 fail, 6 skip
across both suites (was 46 pass, 7 fail, 12 skip).
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.

1 participant