Skip to content

fix: avoid filesystem races in inventory regression assertions - #69411

Merged
pelikhan merged 1 commit into
mainfrom
pelikhan-fix-filesystem-races
Oct 16, 2026
Merged

pelikhan merged 1 commit into
mainfrom
pelikhan-fix-filesystem-races

Conversation

@pelikhan

Copy link
Copy Markdown
Collaborator

Summary

  • Address CodeQL js/file-system-race alerts 1032 and 1033 in the inventory symlink regression test.
  • Open the output once with O_RDONLY | O_NOFOLLOW, then use fstatSync and a single descriptor-based read for all metadata/content assertions.
  • Preserve file-type, 0600 permission, JSON, newline, and unchanged symlink-target coverage; close the descriptor in finally.

Validation

  • node --test .github/scripts/test_lint_monster_issues.cjs .github/scripts/test_secure_write.cjs — 26 tests pass.
  • Pinned Prettier check and git diff --check pass.
  • PATH="/opt/homebrew/bin:$PATH" make agent-report-progress passes.

CodeQL alert closure remains subject to the next scan; no alerts or tracking issues were manually dismissed or closed.

Open the generated inventory once with O_NOFOLLOW and use the file descriptor for metadata and content checks.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@pelikhan
pelikhan marked this pull request as ready for review October 16, 2026 15:43
Copilot AI max review requested due to automatic review settings October 16, 2026 15:43
@pelikhan
pelikhan merged commit 8fc91a3 into main Oct 16, 2026
19 checks passed
@pelikhan
pelikhan deleted the pelikhan-fix-filesystem-races branch October 16, 2026 15:44
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Test Quality Sentinel · haiku45 · 18.5 AIC · ⌖ 10.1 AIC · ◇ 2.47 AIC · ⊞ 9.2K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

Copy link
Copy Markdown
Contributor

🔎 PR Code Quality Reviewer is reviewing code quality for this pull request...

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Ponytail Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Ponytail Reviewer · gpt56 · 4.98 AIC · ⌖ 5.33 AIC · ⊞ 14.6K · ◷

Generated by Ponytail Reviewer for #69411

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused test-only change preserves coverage and reliably closes the descriptor, with no unresolved issues.

0 open findings

What changed in this PR

Hardens gh-aw’s inventory symlink regression test against filesystem races without changing production behavior.

Changes:

  • Uses one no-follow file descriptor for metadata and content assertions.
  • Preserves regression coverage and closes the descriptor in finally.

No confirmed vulnerabilities found.

File Description
.github/​scripts/​test_lint_monster_issues.cjs Replaces repeated path lookups with descriptor-based assertions.

🧠 Review effort: Max


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /diagnosing-bugs (via pr-triage: bug_fix) — no blocking issues found.

📋 Analysis

Root cause vs. symptom

This correctly fixes the root cause of the CodeQL js/file-system-race TOCTOU alerts rather than suppressing them: all metadata/content checks (fstatSync, content read) now operate on a single already-opened file descriptor instead of re-resolving the path three times (lstatSync → readFileSync → statSync → readFileSync), which is exactly the race window CodeQL flags.

Positive Highlights

  • ✅ O_RDONLY | O_NOFOLLOW correctly rejects symlinks at open time, preserving the original isSymbolicLink() === false intent via stat.isFile().
  • ✅ fs.closeSync(fd) wrapped in finally avoids fd leaks on assertion failure.
  • ✅ All prior coverage preserved (file type, 0600 perms, JSON parse, trailing newline).
  • ✅ Scoped to test-only code; verified locally — all 13 tests in the file still pass.
  • ✅ CI only runs this script on ubuntu-latest/ubuntu-slim, so O_NOFOLLOW portability isn't a concern here.

Minor (non-blocking) observation

The outside file read (fs.readFileSync(outside, "utf8")) still uses path-based access, but that target is untouched by collectIssues and isn't part of the race being fixed, so leaving it as-is is reasonable.

No actionable changes requested.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · sonnet50 · 27 AIC · ⌖ 14.8 AIC · ⊞ 10.1K
Comment /matt to run again

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