Add G122 SSA analyzer for filepath.Walk/WalkDir symlink TOCTOU race risksPR description#1532
Merged
ccojocar merged 1 commit intosecurego:masterfrom Feb 20, 2026
Merged
Conversation
…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>
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.