我有这样的代码:
if cfg.GetRedisTLS() {
clientOpts.TLSConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
//nolint:gosec // need insecure TLS option for testing and development
InsecureSkipVerify: cfg.GetRedisInsecure(),
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行时,golangci-lint run
它会识别该nolint
指令并忽略该错误,但是当 Sonarqube 运行时,它会不断失败并显示消息“TLS InsecureSkipVerify 可能为真”
此问题https://github.com/securego/gosec/issues/278讨论了#nosec
在评论中使用来禁用该错误。这里讨论了在声明的特定部分中使用它https://github.com/securego/gosec/issues/278#issuecomment-745209803
所以我尝试过:
if cfg.GetRedisTLS() {
clientOpts.TLSConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
//nolint:gosec // need insecure TLS option for testing and development
// NOSONAR #nosec
InsecureSkipVerify: cfg.GetRedisInsecure(),
}
}
Run Code Online (Sandbox Code Playgroud)
和
if cfg.GetRedisTLS() {
clientOpts.TLSConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
//nolint:gosec // need insecure TLS option …
Run Code Online (Sandbox Code Playgroud) 我从gosec
linter 收到此消息:
foo/cloud.go:34:2: G101: Potential hardcoded credentials (gosec)
fooAPIKeyENVVar = "Foo_API_KEY"
Run Code Online (Sandbox Code Playgroud)
如何禁用此警告?