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
In specific cases of int conversion, // #nosec G115 fails to disable the warning if there's an open bracket between the comment and the issue it's addressing.
Steps to reproduce the behavior
package main
import"fmt"funcmain() {
ten:=10uintTen:=uint(10)
configVal:=uint(ten) // #nosec G115 -- this worksinputSlice:= []int{1, 2, 3, 4, 5}
iflen(inputSlice) <=int(uintTen) { // #nosec G115 -- this worksfmt.Println("hello world!")
}
iflen(inputSlice) <=int(configVal) { // #nosec G115 -- this failsfmt.Println("hello world!")
}
iflen(inputSlice) <=int(configVal) /* #nosec G115 -- this works, but is horrible */ {
fmt.Println("hello world!")
}
// #nosec G115 - This also works, although the documentation implies it shouldn'tiflen(inputSlice) <=int(configVal) {
fmt.Println("hello world!")
}
}
Huh, that worked - Updating the title and description to be more accurate, and added a little bit to the example.
paul-at-cybr
changed the title
#nosec doesn't work if it's preceded by an open bracket {
#nosec G115 doesn't work in particular cases if it's preceded by an open bracket {
Oct 12, 2024
The nosec typically is ignoring an entire AST node, and not just a line. We did some improvements to be more fine grained, but it seems that this case is not handled.
Summary
In specific cases of int conversion,
// #nosec G115
fails to disable the warning if there's an open bracket between the comment and the issue it's addressing.Steps to reproduce the behavior
gosec version
Go version (output of 'go version')
go version go1.23.2 linux/amd64
Operating system / Environment
Any
Expected behavior
A nosec comment that always works
Actual behavior
A nosec comment that sometimes doesn't work
The text was updated successfully, but these errors were encountered: