Skip to content

fix: keep validators usable where O_NOFOLLOW is unavailable (Windows) - #113

Open
PhucNguyen-Dev wants to merge 1 commit into
cloudflare:mainfrom
PhucNguyen-Dev:fix/windows-no-follow-fallback
Open

PhucNguyen-Dev wants to merge 1 commit into
cloudflare:mainfrom
PhucNguyen-Dev:fix/windows-no-follow-fallback

Conversation

@PhucNguyen-Dev

Copy link
Copy Markdown

Summary

readFileWithinLimit() in both validators refuses to run at all when fs.constants.O_NOFOLLOW / O_NONBLOCK are unavailable:

if (!Number.isInteger(noFollow) || noFollow === 0 || !Number.isInteger(nonBlock) || nonBlock === 0) {
  // Node exposes no race-safe fallback on these platforms, so reject all inputs.
  throw new SafeInputError("OS no-follow and nonblocking input protection is unavailable");
}

Windows Node leaves both constants undefined, so on Windows every CLI invocation dies with that message. Phase 4 and Phase 5 validation — the whole point of findings.json and coverage-ledger.json being machine-checked — is unusable there. The bundled suites show it: the findings suite fails 22 pass / 7 fail, and the ledger suite hides the same bug by skipping its CLI tests (HAS_SAFE_INPUT_OPEN).

Change

  • Where the constants are absent, reject a symlink with lstat before opening and drop the flags from the open call.
  • Keep every other safeguard untouched: same 1 MiB cap, same regular-file check, same ELOOP/EMLINK handling, same SafeInputError messages.
  • The two test suites no longer gate their CLI cases on the constants, so those tests now run on every platform instead of being skipped.

POSIX behaviour is unchanged — the constants exist there, so the original openSync(..., O_RDONLY | O_NOFOLLOW | O_NONBLOCK) path is taken exactly as before.

Test results

Windows 11, Node v22.23.4, from skills/security-audit:

suite before after
validate-findings.test.cjs 22 pass, 7 fail, 5 skipped 32 pass, 0 fail, 2 skipped
validate-coverage-ledger.test.cjs 24 pass, 0 fail, 7 skipped 29 pass, 0 fail, 2 skipped

The 2 remaining skips are platform-inherent, not regressions: FIFO cases need Git-Bash (the repo's existing win32 guard stays), and file-symlink creation on Windows needs Developer Mode. Both are unchanged by this patch.

Honest caveat

lstat-then-open is not as race-proof as O_NOFOLLOW on its own — it is a check followed by an open rather than one atomic flag. On platforms where the flag exists nothing changes, so the weaker path only applies where today the alternative is a hard failure. If you would rather keep the atomic guarantee and only accept Windows input via stdin, say so and I will rework it.

Each validator still rejects a symlink when handed one from a platform that can create it; that is the behaviour the previously platform-skipped test asserts.

Windows Node leaves fs.constants.O_NOFOLLOW and O_NONBLOCK undefined, so
readFileWithinLimit() in both validators threw "OS no-follow and
nonblocking input protection is unavailable" for every file. On Windows
the findings validator therefore failed 7 of its CLI tests and the
coverage-ledger validator silently skipped its CLI tests instead.

Fall back to an lstat symlink check and drop the unavailable flags from
the open call when the constants are absent; the ELOOP/EMLINK handling
and every other safeguard stay unchanged. The test suites no longer gate
their CLI cases on the constants, so both run on every platform.

Windows: validate-findings 22 pass/7 fail -> 32 pass/0 fail,
validate-coverage-ledger 24 pass/7 skipped -> 29 pass/0 fail (2 skips
remain: FIFO cases need Git-Bash, symlink creation needs Developer Mode).

Linux/macOS is unaffected: the constants exist there, so the original
open path is taken unchanged.

@agammann agammann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In both validators, lstatSync(file) followed by openSync(file, O_RDONLY) is not an atomic replacement for O_NOFOLLOW: another process can replace the file with a symlink between those calls, and the open will follow it. This changes the previous fail-closed behavior precisely on platforms without O_NOFOLLOW. Also, when O_NONBLOCK is absent, opening a FIFO can block before the later fstat rejects it. Could these platforms keep a fail-closed path until a race-safe open strategy exists, with tests for the missing-flag cases?

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.

2 participants