mirror of
https://github.com/securego/gosec.git
synced 2026-06-20 00:15:59 +02:00
Add G122 SSA analyzer for filepath.Walk/WalkDir symlink TOCTOU race risks (#1532)
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>
This commit is contained in:
@@ -73,6 +73,7 @@ var ruleToCWE = map[string]string{
|
||||
"G119": "200",
|
||||
"G120": "400",
|
||||
"G121": "346",
|
||||
"G122": "367",
|
||||
"G201": "89",
|
||||
"G202": "89",
|
||||
"G203": "79",
|
||||
|
||||
Reference in New Issue
Block a user