Skip to content

fix: audit fixes — path safety, shared reads, dir pruning#485

Merged
tomasz-tomczyk merged 4 commits intomainfrom
audit/go-fixes
May 7, 2026
Merged

fix: audit fixes — path safety, shared reads, dir pruning#485
tomasz-tomczyk merged 4 commits intomainfrom
audit/go-fixes

Conversation

@tomasz-tomczyk
Copy link
Copy Markdown
Owner

Summary

  • Normalize backslashes before traversal check in bulk JSON paths — "subdir\..\..\etc\passwd" on Unix would previously pass isAbsoluteOrTraversal (filepath.Clean treats backslash as literal) then convert to a traversal path
  • Add source label to JSON parse errors (file vs stdin in error messages)
  • Replace os.ReadFile with readFileShared for review.json reads in review_file.go, session_write.go, github.go — consistent Windows sharing-violation protection
  • Extract fileIgnored/dirIgnored helpers in session.go; prune ignored directories early in walkDirSubsFirst rather than per-file
  • Use GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT) in terminateProcess on Windows so the daemon's signal handler runs before falling back to TerminateProcess
  • Add table tests for fileIgnored/dirIgnored, backslash traversal rejection
  • Remove stale autodetect.go reference from AGENTS.md

Review

  • Code review: passed
  • Parity audit: N/A (no frontend changes)

Test plan

  • go test -race -count=1 ./... — pass
  • golangci-lint run ./... — 0 issues
  • New tests: TestProcessBulkFileOrLineEntryRejectsBackslashTraversal, TestFileIgnored, TestDirIgnored

🤖 Generated with Claude Code

tomasz-tomczyk and others added 3 commits May 7, 2026 13:31
… labels, dir pruning

- Normalize backslash separators in bulk JSON paths before filepath.Clean
  so Windows-authored bulk JSON ("subdir\file.go") works on Unix
- Add source label to JSON parse errors so callers can distinguish file
  vs stdin failures ("Error parsing JSON from bulk.json at byte …")
- Replace os.ReadFile with readFileShared in review_file.go, session_write.go,
  github.go for consistent cross-process locking semantics
- Extract fileIgnored/dirIgnored helpers in session.go; prune ignored
  directories early in walkDirSubsFirst instead of per-file
- Use GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT) in terminateProcess on Windows
  so the daemon's signal.NotifyContext handler runs before falling back to Kill
- Remove stale autodetect.go reference from AGENTS.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Move the backslash→slash replacement before isAbsoluteOrTraversal so
Windows-style traversal inputs ("subdir\..\..\etc\passwd") are rejected
on Unix too. Previously, filepath.Clean treated backslash as a literal
on Unix, so the check passed; after ReplaceAll the path became a real
traversal that landed in the review file as a corrupted key.

Also document dirIgnored's trailing-slash-only contract and add a test
for the backslash traversal rejection.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Locks the trailing-slash-only contract for dirIgnored (bare basename
patterns like "node_modules" are not pruned at the directory level)
and covers fileIgnored pattern matching including the dir/ prefix case.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

❌ Patch coverage is 81.81818% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.19%. Comparing base (2515c6d) to head (992e3a0).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
session.go 73.91% 3 Missing and 3 partials ⚠️
platform_windows.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #485      +/-   ##
==========================================
- Coverage   69.19%   69.19%   -0.01%     
==========================================
  Files          43       43              
  Lines       10829    10851      +22     
==========================================
+ Hits         7493     7508      +15     
- Misses       2767     2772       +5     
- Partials      569      571       +2     
Flag Coverage Δ
e2e 32.06% <13.63%> (-0.16%) ⬇️
unit 67.06% <85.71%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…ror no-offset path

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tomasz-tomczyk tomasz-tomczyk merged commit ac054a5 into main May 7, 2026
9 of 10 checks passed
@tomasz-tomczyk tomasz-tomczyk deleted the audit/go-fixes branch May 7, 2026 13:43
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