Skip to content

fix: make the validators read input on Windows without the lstat/open race - #131

Open
divyesh01 wants to merge 1 commit into
cloudflare:mainfrom
divyesh01:fix/windows-validator-input
Open

divyesh01 wants to merge 1 commit into
cloudflare:mainfrom
divyesh01:fix/windows-validator-input

Conversation

@divyesh01

@divyesh01 divyesh01 commented Nov 3, 2026 •

Copy link
Copy Markdown

Fixes #53 and #117.

Problem

Windows Node leaves fs.constants.O_NOFOLLOW and O_NONBLOCK undefined, so readFileWithinLimit() in both validators rejects every input there. On Windows the findings suite fails (46 pass, 7 fail, 12 skipped) and the CLI can't validate anything.

#99 and #113 also fix this. Both check the path with lstat, then open it. The review on #113 points out that a file can be swapped between those two calls, and asks that platforms without the flags keep failing closed until there's a race-safe approach. This PR tries to answer that review.

Change

In both validators, and only when process.platform === "win32":

  1. Refuse \.\ and \?\ device paths, so a named pipe can't block the open.
  2. lstat the path. Refuse a symlink or anything that isn't a regular file.
  3. Open it read-only.
  4. fstat the open handle and require the same volume (dev) and file ID (ino, read as a bigint) as the lstat result. A zero file ID is refused, since a volume that can't report one can't prove anything.

If the file is swapped between steps 2 and 3, the IDs differ and the read fails with "input changed while it was being opened". Platforms that have the flags keep the existing path unchanged. Platforms that lack them and aren't Windows still throw the existing error, so nothing that fails closed today starts reading.

Tests: the symlink CLI tests are no longer skipped on Windows by the missing-flag check, and each suite gains a Windows-only test that a device path is refused without blocking.

Verification (Windows 11, Node 24.21.0)

  • node --test skills/security-audit/*.test.cjs: 63 pass, 0 fail, 4 skipped. Unpatched on the same machine: 46 pass, 7 fail, 12 skipped. The 4 skips are the two FIFO tests (no FIFOs on Windows) and the two symlink tests, which skip themselves because this machine doesn't allow creating symlinks (no Developer Mode or admin rights). So the symlink path wasn't exercised here, and a run with symlink rights would be useful.
  • A separate script replaced the input with a different file between the lstat and the open (it wraps fs.openSync), then called the exported readFileWithinLimit. With no swap it read the file. With the swap it refused with "input changed while it was being opened".
  • I haven't run it on Linux or macOS. Their code path is unchanged apart from the new hasFlags check.

🤖 Generated with Claude Code

… race

Windows Node has no O_NOFOLLOW or O_NONBLOCK, so readFileWithinLimit() in
both validators rejected every input there. On win32 only, refuse device
paths, reject a symlink or non-regular file by lstat, open the file, then
require the open handle to have the same volume and file ID as the lstat
result. A file swapped between the two calls is refused instead of read.
Other platforms without the flags still fail closed.

Fixes cloudflare#53 and cloudflare#117.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
coffeegrind123 added a commit to coffeegrind123/security-audit-skill that referenced this pull request Nov 11, 2026
Upstream main has not moved since 2026-09-14, but 79 pull requests are
open. Each was read at the diff level, tested in its own worktree, and
checked for conflicts; the best of each duplicate group is ported.

Validators: cloudflare#143 archived verifier owner reuse, cloudflare#87 shared artifacts
within one attempt, cloudflare#102/cloudflare#103 duplicate JSON keys, cloudflare#111 1,000-field
objects, cloudflare#127 ordinary class must match assignment, cloudflare#104 self-excluded
ordinary block, cloudflare#141 verbatim quotes checked with --target, cloudflare#45 line
upper bound, cloudflare#84 --terminal rejects open units, cloudflare#145 identity-checked
open on Windows (POSIX still fails closed), cloudflare#48 retained-artifact
check (skills/ part only). Overlapping changes were merged so both
behaviours and both test sets survive.

Method: cloudflare#125 critic reasons through handoff, cloudflare#132 deployment controls
become units, cloudflare#83 carried-record gates, cloudflare#93 abort cleanup, cloudflare#23
streaming tool calls, cloudflare#50 config-dependent reachability stays
needs_validation, cloudflare#58 sequential verifier fallback, cloudflare#96 verifier no
longer sees the hunter's verdict, severity or fix.

Execution safety (cloudflare#76 neutralized git, symlink-safe copies; cloudflare#95
sanitized repo ID and prior-run compatibility; cloudflare#108 untrusted-content
prompt block; cloudflare#129 isolation built beside the host) moves into
EXECUTION-SAFETY.md so SKILL.md stays under its token budget.

Companions: cloudflare#101 cryptography, cloudflare#116 Android, cloudflare#35 edge isolate state.

Skipped: duplicates (cloudflare#82 cloudflare#106 cloudflare#91 cloudflare#70 cloudflare#138 cloudflare#131 cloudflare#75 cloudflare#63 cloudflare#97 cloudflare#123 cloudflare#25
cloudflare#26 cloudflare#16 cloudflare#40 cloudflare#42 cloudflare#142), validator-weakening fallbacks (cloudflare#59 cloudflare#113 cloudflare#99),
README/LICENSE churn, rebrands, scope creep, and cloudflare#85 cloudflare#90 cloudflare#8 cloudflare#89 cloudflare#32.

UPGRADE.md records this sync procedure.

Co-authored-by: Rohankollabathula67 <rohankollabathula67@gmail.com>
Co-authored-by: lab 1207 <hajarevaibhav527@gmail.com>
Co-authored-by: Rudy Celekli <rudy@gradiahq.com>
Co-authored-by: Mohit Rawat <rawatmohit17906@gmail.com>
Co-authored-by: MAHER AL-AQIL <18458259+maqalaqil@users.noreply.github.com>
Co-authored-by: CodeInf <jiuqiaoy@gmail.com>
Co-authored-by: pucedoteth <119044801+pucedoteth@users.noreply.github.com>
Co-authored-by: Matt Van Horn <mvanhorn@users.noreply.github.com>
Co-authored-by: Pizo <pizofreude@proton.me>
Co-authored-by: ZhiHe-ma <302089060+ZhiHe-ma@users.noreply.github.com>
Co-authored-by: shivam <juyaljii610@gmail.com>
Co-authored-by: Dante <duanjl.china@gmail.com>
Co-authored-by: Francisco <francisco@theysay.me>
Co-authored-by: Roman Dolgov <alter@users.noreply.github.com>
Co-authored-by: bodapatisaikrishna <saikrishnabodapati@gmail.com>
Co-authored-by: alvessh <117163985+alvessh@users.noreply.github.com>
Co-authored-by: itinance <hhuebel@itinance.com>
Co-authored-by: ChoYugyeong <cho4639@gmail.com>
Co-authored-by: Shaun Liebenberg <shaun@liebies.co.za>
Co-authored-by: JAI <jai19kharb@gmail.com>
Co-authored-by: ghostzeronz-coder <ghostzeronz-coder@users.noreply.github.com>
Co-authored-by: Aman Mohamed Ali <69119173+spidervirus@users.noreply.github.com>
Co-authored-by: Sandeep.dhami <sandeep84397@gmail.com>
Co-authored-by: jastfan <duohello640@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Validator CLIs cannot read any input on Windows

1 participant