Skip to content

Support Windows in the validators with an identity-checked open - #145

Open
pizofreude wants to merge 1 commit into
cloudflare:mainfrom
pizofreude:fix/windows-safe-input-read
Open

pizofreude wants to merge 1 commit into
cloudflare:mainfrom
pizofreude:fix/windows-safe-input-read

Conversation

@pizofreude

Copy link
Copy Markdown

Problem

On native Windows, both validators reject every input:

Failed to read findings JSON: OS no-follow and nonblocking input protection is unavailable

Node's Windows build exposes neither fs.constants.O_NOFOLLOW nor O_NONBLOCK (only O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_TRUNC, O_APPEND), because Win32 has no POSIX no-follow flag. The shell does not matter: PowerShell, cmd and Git Bash all start the same node.exe. On Node 24.21, 7 of the 65 tests fail on Windows, and Phase 4 cannot validate findings.json there at all.

The current code says "Node exposes no race-safe fallback on these platforms". This PR adds one for Windows, and keeps every other platform unchanged.

Change

readFileWithinLimit now opens through openInputDescriptor:

  • POSIX: unchanged. O_RDONLY | O_NOFOLLOW | O_NONBLOCK, with ELOOP/EMLINK reported as a symlink.
  • Windows: openWindowsInputDescriptor:
    1. lstat the path (bigint). Reject a symlink or junction (Node reports reparse points as symbolic links) and any non-regular file, before opening it.
    2. Open read-only.
    3. fstat the descriptor and lstat the path again. Require all three to report the same volume (dev) and file index (ino), and the second lstat to still not be a link.
    4. Otherwise reject with input changed while it was opened, and close the descriptor.
  • Other platforms without the flags: still rejected, as before.

Why this is race-safe

  • Swap before the open: the descriptor's identity differs from the first lstat, so it is rejected.
  • Swap and restore around the open: same result, because the descriptor still names the other file.
  • Swap after the open: the second lstat differs from the descriptor, so it is rejected.
  • Files read: only a descriptor whose identity equals the regular file the path named before and after opening is ever read.
  • No identity reported: ino === 0n is rejected, because nothing can be compared.
  • Blocking: O_NONBLOCK guards against FIFOs, which Windows filesystems do not have. Device paths such as CON, NUL and \\.\pipe\... fail the pre-open lstat (ENOENT) or the regular-file check, so they are never opened.
  • Hard links: this matches the POSIX path, which does not reject them either.

Tests

  • HAS_SAFE_INPUT_OPEN is true on win32, so the existing CLI tests now run on Windows. The FIFO and POSIX-symlink tests keep their Windows skip.

  • Windows CLI tests:

    • A regular file is accepted.
    • A junction is rejected.
    • A file symlink is rejected. The test skips with a reason when the host cannot create one.
    • CON, NUL and a named pipe are rejected without blocking.
  • Deterministic race tests (every platform): openWindowsInputDescriptor(file, fsApi = fs) takes an injectable fs. A scripted fs places the swap at an exact step:

    • between the lstat and the open,
    • around the open,
    • right after the open,
    • onto another volume,
    • a link appearing after the open,
    • a missing file index.

    Each must reject and close the descriptor. Pre-open rejection must not open at all.

  • Mutation check: removing any one of the six checks fails at least one test:

    • the identity comparison before the open,
    • the identity comparison after the open,
    • the after-open link check,
    • the close on rejection,
    • the pre-open link check,
    • the zero-index guard.

Results

Host Node Tests Pass Fail Skip
Windows 10 (native) 24.21.0 91 85 0 6
Linux (WSL2) 24.18.0 91 83 0 8
GitHub Actions windows-latest 24.22.2 91 87 0 4
GitHub Actions macos-latest 24.22.2 91 83 0 8
GitHub Actions ubuntu-latest 24.22.2 91 83 0 8

The CI run is in my fork, on a separate branch that only adds the workflow, so this PR contains no CI files: https://github.com/pizofreude/security-audit-skill/actions/runs/42674348712. The windows-latest runner can create file symlinks, so both Windows: rejects a file symlink without following it tests run and pass there instead of skipping. The Windows skips are the FIFO and POSIX-symlink tests. The Linux and macOS skips are the Windows-only tests.

End-to-end check: on native Windows, the patched validators accept a real audit run's findings.json and coverage-ledger.json. Both report PASS.

Node on Windows exposes neither O_NOFOLLOW nor O_NONBLOCK, so both
validators rejected every input there with "OS no-follow and nonblocking
input protection is unavailable", and 7 tests failed on native Windows.

On Windows, readFileWithinLimit now opens through openWindowsInputDescriptor:
lstat the path and reject a symlink, junction or non-regular file before
opening it; open read-only; then require fstat of the descriptor and a second
lstat of the path to report the same volume and file index as the first
lstat. A swap before, during or after the open changes that identity and is
rejected, and the descriptor is closed. A path such as CON or a named pipe is
never opened, so the open cannot block, and Windows filesystems have no
FIFOs. A filesystem that reports no file index (0) is rejected. POSIX
platforms keep the O_NOFOLLOW | O_NONBLOCK open unchanged, and other
platforms without those flags still reject.

Tests:
- HAS_SAFE_INPUT_OPEN is true on win32, so the CLI tests now run there.
- Windows CLI tests: regular file accepted, junction rejected, file symlink
  rejected (skips with a reason when the host cannot create one), and CON,
  NUL and a named pipe rejected without blocking.
- Deterministic race tests on every platform: openWindowsInputDescriptor
  takes an injectable fs, and a scripted fs lands a swap between lstat and
  open, around the open, right after the open, onto another volume, a link
  after the open, and a missing file index. Each must reject and close the
  descriptor. Removing any one of the six checks fails at least one test.

Results: native Windows (Node 24.21) 91 tests, 85 pass, 0 fail, 6 skip;
Linux (Node 24.18) 91 tests, 83 pass, 0 fail, 8 skip.
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>
@zachshallbetter

Copy link
Copy Markdown

There are six open attempts at Windows input for the validators: #59, #99, #113, #131, #145, and the Windows commit in #75. I read through all of them, and this one looks like the strongest to me. The race tests are especially nice.

Two small things:

  • sameFileIdentity only checks left.ino !== 0n. That's correct for every current call site, because equality forces the other side to match, but checking both sides would make it hold for future callers.
  • Nothing ties the two copies of openWindowsInputDescriptor together. The existing "keeps shared helpers aligned" test could compare them across the two modules.

#53 and #117 should close with this one.

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