You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// osRootSuggestion returns an Autofix suggesting the use of os.Root where supported
115
+
// to constrain file access under a fixed directory and mitigate traversal risks.
116
+
func (r*readfile) osRootSuggestion() string {
117
+
major, minor, _:=gosec.GoVersion()
118
+
ifmajor==1&&minor>=24 {
119
+
return"Consider using os.Root to scope file access under a fixed root (Go >=1.24). Prefer root.Open/root.Stat over os.Open/os.Stat to prevent directory traversal."
120
+
}
121
+
return""
122
+
}
123
+
114
124
// isSafeJoin checks if path is baseDir + filepath.Clean(fn) joined.
115
125
// improvements over earlier naive version:
116
126
// - allow baseDir as a BasicLit or as an identifier that resolves to a string constant
0 commit comments