Skip to content

Read validator CLI input safely on Windows - #59

Open
henrychen95 wants to merge 3 commits into
cloudflare:mainfrom
henrychen95:fix/windows-safe-input
Open

henrychen95 wants to merge 3 commits into
cloudflare:mainfrom
henrychen95:fix/windows-safe-input

Conversation

@henrychen95

Copy link
Copy Markdown

Fixes #53.

This implements the approach sketched in #53, including the fail-closed behavior requested there for filesystems that cannot supply an identity.

The existing POSIX safe-open path is unchanged.

On platforms where O_NOFOLLOW and O_NONBLOCK are unavailable, the validators now use a best-effort fallback:

  • lstat rejects symbolic links and final-component NTFS junctions before opening.
  • The opened descriptor is required to refer to a regular file, rejecting inputs such as named pipes.
  • lstat and fstat identities are compared across the open using bigint (dev, ino) values to detect final-component replacement.
  • If a usable file identity is unavailable, the fallback fails closed.

An earlier draft of this patch compared plain JavaScript Number values. NTFS file IDs are 64-bit, so values above 2^53 can lose precision and make distinct IDs compare equal. Adversarial TOCTOU testing on NTFS exposed this, and the fallback now uses bigint stats instead.

The fallback still has an unavoidable lstat → open race window compared with O_NOFOLLOW; the post-open identity check is intended to detect replacement rather than claim equivalent atomic semantics.

New tests cover:

  • final-component NTFS junction rejection
  • intermediate junction traversal, matching POSIX final-component-only O_NOFOLLOW semantics
  • named-pipe rejection without hanging
  • identity mismatch rejection
  • unchanged identity acceptance
  • unavailable file identity failing closed

Previously skipped validator CLI tests now run on Windows.

Validation:

  • Linux (Ubuntu 24.04, Node 22):
    • findings: 34 passed, 0 failed, 3 skipped
    • coverage-ledger: 31 passed, 0 failed, 7 skipped
  • Windows 11 / NTFS (Node 24):
    • findings: 35 passed, 0 failed, 2 skipped
    • coverage-ledger: 36 passed, 0 failed, 2 skipped

Both validators were updated symmetrically, and the zero-dependency standalone CLI design is preserved.

Platforms without O_NOFOLLOW/O_NONBLOCK (Windows) previously rejected
every input, breaking the full-audit validation phases there. Keep the
POSIX safe open unchanged and add a best-effort fallback: lstat rejects
symlinks and NTFS junctions before opening, the regular-file check after
opening rejects named pipes, and comparing (dev, ino) across the open
detects the final component being replaced mid-flight.

Enable the HAS_SAFE_INPUT_OPEN-gated CLI tests on Windows so the
fallback is exercised there. On Linux the suites pass unchanged,
including the FIFO and symlink hostile-input tests.
NTFS file IDs are 64-bit and do not survive Number conversion above
2^53: two IDs differing only in low bits compare equal, so the
replacement check could silently pass on the platform it exists for.
Compare bigint stats in the fallback branch instead; the POSIX path
keeps its plain-number fstat.

Also add adversarial tests for the fallback: NTFS junction rejection
as the final component, junction traversal as an intermediate
component (matching POSIX final-component-only protection), named-pipe
rejection without hanging, and bigint identity mismatch and acceptance.
The replacement and acceptance tests run wherever the fallback runs;
fs.constants is not writable, so they cannot be forced onto POSIX.
Issue cloudflare#53 asks for exactly this: a filesystem that reports ino == 0
must not quietly skip the replacement check. Reject such inputs with
'file identity is unavailable' instead of reading them, and cover both
the pre-open and post-open identities with tests.
@wyaaa671-afk

Copy link
Copy Markdown

Fixes #53.

This implements the approach sketched in #53, including the fail-closed behavior requested there for filesystems that cannot supply an identity.

The existing POSIX safe-open path is unchanged.

On platforms where O_NOFOLLOW and O_NONBLOCK are unavailable, the validators now use a best-effort fallback:

  • lstat rejects symbolic links and final-component NTFS junctions before opening.
  • The opened descriptor is required to refer to a regular file, rejecting inputs such as named pipes.
  • lstat and fstat identities are compared across the open using bigint (dev, ino) values to detect final-component replacement.
  • If a usable file identity is unavailable, the fallback fails closed.

An earlier draft of this patch compared plain JavaScript Number values. NTFS file IDs are 64-bit, so values above 2^53 can lose precision and make distinct IDs compare equal. Adversarial TOCTOU testing on NTFS exposed this, and the fallback now uses bigint stats instead.

The fallback still has an unavoidable lstat → open race window compared with O_NOFOLLOW; the post-open identity check is intended to detect replacement rather than claim equivalent atomic semantics.

New tests cover:

  • final-component NTFS junction rejection
  • intermediate junction traversal, matching POSIX final-component-only O_NOFOLLOW semantics
  • named-pipe rejection without hanging
  • identity mismatch rejection
  • unchanged identity acceptance
  • unavailable file identity failing closed

Previously skipped validator CLI tests now run on Windows.

Validation:

  • Linux (Ubuntu 24.04, Node 22):
    • findings: 34 passed, 0 failed, 3 skipped
    • coverage-ledger: 31 passed, 0 failed, 7 skipped
  • Windows 11 / NTFS (Node 24):
    • findings: 35 passed, 0 failed, 2 skipped
    • coverage-ledger: 36 passed, 0 failed, 2 skipped

Both validators were updated symmetrically, and the zero-dependency standalone CLI design is preserved.

@wyaaa671-afk wyaaa671-afk mentioned this pull request Sep 28, 2026
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

2 participants