标签: gosec

如何禁用“TLS InsecureSkipVerify 可能为真”错误

我有这样的代码:

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)

lint go gosec

3
推荐指数
1
解决办法
4209
查看次数

gosec linter:G101:潜在的硬编码凭据

我从goseclinter 收到此消息:

foo/cloud.go:34:2: G101: Potential hardcoded credentials (gosec)
        fooAPIKeyENVVar = "Foo_API_KEY"
Run Code Online (Sandbox Code Playgroud)

如何禁用此警告?

static-analysis go gosec

2
推荐指数
1
解决办法
2727
查看次数

标签 统计

go ×2

gosec ×2

lint ×1

static-analysis ×1