Skip to content

Add G122 SSA analyzer for filepath.Walk/WalkDir symlink TOCTOU race risksPR description#1532

Merged
ccojocar merged 1 commit intosecurego:masterfrom
ccojocar:symlink_race
Feb 20, 2026
Merged

Add G122 SSA analyzer for filepath.Walk/WalkDir symlink TOCTOU race risksPR description#1532
ccojocar merged 1 commit intosecurego:masterfrom
ccojocar:symlink_race

Conversation

@ccojocar
Copy link
Member

This change introduces a new SSA-based analyzer, G122, to detect unsafe filesystem operations inside filepath.Walk, filepath.WalkDir, and io/fs.WalkDir callbacks when callback path values flow into race-prone sinks such as os.Remove, os.OpenFile, os.Rename, and os.Chmod.It adds CWE mapping for the new rule as G122 -> CWE-367 (TOCTOU race condition), and adds the CWE-367 definition to the CWE data.It wires G122 into analyzer registration and updates the README available rules list.It adds dedicated G122 sample coverage with vulnerable and safe cases, including safe root-scoped usage through os.Root APIs (for example root.Open and root.Remove).Validation was completed: full test suite passes, golangci-lint reports zero issues, and gosec CLI validation confirms expected trigger and non-trigger behavior for G122.

…isks

This change introduces a new SSA-based analyzer, G122, to detect unsafe
filesystem operations inside filepath.Walk, filepath.WalkDir, and
io/fs.WalkDir callbacks when callback path values flow into race-prone
sinks such as os.Remove, os.OpenFile, os.Rename, and os.Chmod.

It adds CWE mapping for the new rule as G122 -> CWE-367 (TOCTOU race
condition), and adds the CWE-367 definition to the CWE data.

It wires G122 into analyzer registration and updates the README
available rules list.

It adds dedicated G122 sample coverage with vulnerable and safe cases,
including safe root-scoped usage through os.Root APIs (for example
root.Open and root.Remove).

Validation was completed: full test suite passes, golangci-lint reports
zero issues, and gosec CLI validation confirms expected trigger and
non-trigger behavior for G122.

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
@ccojocar ccojocar merged commit b568aa1 into securego:master Feb 20, 2026
7 checks passed
@ccojocar ccojocar deleted the symlink_race branch February 20, 2026 18:26
@codecov
Copy link

codecov bot commented Feb 20, 2026

Codecov Report

❌ Patch coverage is 55.80110% with 80 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.69%. Comparing base (1735e5a) to head (b668098).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
analyzers/walk_symlink_race.go 55.80% 64 Missing and 16 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1532      +/-   ##
==========================================
- Coverage   80.09%   79.69%   -0.40%     
==========================================
  Files         101      102       +1     
  Lines        9198     9379     +181     
==========================================
+ Hits         7367     7475     +108     
- Misses       1384     1442      +58     
- Partials      447      462      +15     

☔ 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.

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