We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
For some reason gosec is happy with this code:
package main import ( "os" "path/filepath" ) func open(fn string) { fh, err := os.OpenFile(filepath.Clean(fn), os.O_RDONLY, 0o600) if err != nil { panic(err) } defer fh.Close() } func main() { fn := "filename" open(fn) }
while if it is changed to this I get a G304 error:
package main import ( "os" "path/filepath" ) func open(fn string, perm os.FileMode) { fh, err := os.OpenFile(filepath.Clean(fn), os.O_RDONLY, perm) if err != nil { panic(err) } defer fh.Close() } func main() { fn := "filename" open(fn, 0o600) }
The error:
[.../main.go:9] - G304 (CWE-22): Potential file inclusion via variable (Confidence: HIGH, Severity: MEDIUM) 8: func open(fn string, perm os.FileMode) { > 9: fh, err := os.OpenFile(filepath.Clean(fn), os.O_RDONLY, perm) 10: if err != nil {
There seems to be the same problem if passing in the flag:
package main import ( "os" "path/filepath" ) func open(fn string, flag int) { fh, err := os.OpenFile(filepath.Clean(fn), flag, 0o600) if err != nil { panic(err) } defer fh.Close() } func main() { fn := "filename" open(fn, os.O_RDONLY) }
[.../main.go:9] - G304 (CWE-22): Potential file inclusion via variable (Confidence: HIGH, Severity: MEDIUM) 8: func open(fn string, flag int) { > 9: fh, err := os.OpenFile(filepath.Clean(fn), flag, 0o600) 10: if err != nil {
Some additional information:
$ go version go version go1.24.1 darwin/arm64
Probably not very helpful -version output (updated via go install github.com/securego/gosec/v2/cmd/gosec@latest just before opening the ticket)
go install github.com/securego/gosec/v2/cmd/gosec@latest
$ gosec -version Version: dev Git tag: Build date:
The text was updated successfully, but these errors were encountered:
No branches or pull requests
For some reason gosec is happy with this code:
while if it is changed to this I get a G304 error:
The error:
There seems to be the same problem if passing in the flag:
Some additional information:
Probably not very helpful -version output (updated via
go install github.com/securego/gosec/v2/cmd/gosec@latest
just before opening the ticket)The text was updated successfully, but these errors were encountered: