Skip to content

fix(audit): record JavaScript files that could not be read - #368

Open
DeryFerd wants to merge 1 commit into
qybaihe:mainfrom
DeryFerd:fix/audit-unreadable-js
Open

DeryFerd wants to merge 1 commit into
qybaihe:mainfrom
DeryFerd:fix/audit-unreadable-js

Conversation

@DeryFerd

@DeryFerd DeryFerd commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Summary

A directory audit walks the tree, keeps every JS/TS file it finds, and reads each one to build the exposure model. That read had no guard, so a file that stat accepted but readFileSync could not open, such as a script owned by another account, one removed between the walk and the read, or one held open by a scanner, threw out of auditTarget. The caller lost the entire report: no attack surface, no unreadableFiles entry, no partial marker. defendTarget lost stage 2 with it, because it calls the audit directly.

What changed

  • src/engine/auditor.ts: the JS/TS loop now reads inside a try/catch, pushes the project-relative path into unreadableFiles, and continues with the next file. That is the same treatment the nested artifact loop already gives an unreadable .asar or .wasm, so both halves of a directory audit now fail the same way.
  • The directory branch already derives parseStatus from that list, so a run with one unreadable script reports partial instead of throwing or claiming complete.
  • tests/audit-unreadable-nested.test.ts: a new case injects a single EACCES for one file name and asserts that the audit returns, lists locked.js, marks the simulation partial, and still counts the readable sibling. A permission error cannot be produced portably, since chmod 000 is ignored on Windows and by root, so the test passes every other read through to the real filesystem.

Why it matters

The audit is the pre-flight stage of defendTarget and the whole of bla_audit. A single unreadable script in a large build tree used to turn a report into a stack trace. For an operator that is worse than a partial result in two ways: the rest of the surface disappears with the failing file, and nothing says the run stopped early. The report contract in this repo is that BLA names what it could not examine, and this path broke that contract instead of degrading into it.

Validation

npx vitest run tests/audit-unreadable-nested.test.ts tests/audit-partial-shield-score-honesty.test.ts tests/audit-redteam-reinforcements.test.ts tests/audit-symlink-safety.test.ts tests/defend-stage-status-honesty.test.ts tests/directory-fail-open.test.ts tests/one-click-defend.test.ts
npx tsc --noEmit

The new test fails on the old code with EACCES: permission denied thrown from the read inside auditTarget. After the change, 21 tests pass in that set with one symlink test skipped on Windows, and the type check is clean.

Compatibility

A tree where every script is readable reports exactly what it did before. unreadableFiles only appears when something could not be read, and a directory audit that previously threw now returns a report. Callers notice the difference only in the case that used to crash.

A directory audit guarded its nested non-JS loop (qybaihe#330) but still read every JS/TS file with a bare readFileSync, so one unreadable script (EACCES, a file removed between the walk and the read) threw out of auditTarget and removed the whole audit and the defend pre-flight stage. Collect the path into unreadableFiles and mark the simulation partial, matching the sibling loop.
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