我有這樣的代碼:
if cfg.GetRedisTLS() {
clientOpts.TLSConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
//nolint:gosec // need insecure TLS option for testing and development
InsecureSkipVerify: cfg.GetRedisInsecure(),
}
}
當我運行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(),
}
}
和
if cfg.GetRedisTLS() {
clientOpts.TLSConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
//nolint:gosec // need insecure TLS option for testing and development
InsecureSkipVerify: cfg.GetRedisInsecure(), // NOSONAR #nosec
}
}
和
if cfg.GetRedisTLS() {
clientOpts.TLSConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
//nolint:gosec // NOSONAR #nosec need insecure TLS option for testing and development
InsecureSkipVerify: cfg.GetRedisInsecure(),
}
}
和
if cfg.GetRedisTLS() {
clientOpts.TLSConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
//nolint:gosec // NOSONAR #nosec need insecure TLS option for testing and development
InsecureSkipVerify: cfg.GetRedisInsecure(), /* #nosec */
}
}
和
if cfg.GetRedisTLS() {
clientOpts.TLSConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
//nolint:gosec // NOSONAR #nosec need insecure TLS option for testing and development
/* #nosec */ InsecureSkipVerify: cfg.GetRedisInsecure(), /* #nosec */
}
}
和
if cfg.GetRedisTLS() {
clientOpts.TLSConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
//nolint:gosec // NOSONAR #nosec need insecure TLS option for testing and development
/* #nosec */ InsecureSkipVerify: cfg.GetRedisInsecure() /* #nosec */, /* #nosec */
}
}
和
if cfg.GetRedisTLS() {
clientOpts.TLSConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
//nolint:gosec // NOSONAR #nosec need insecure TLS option for testing and development
/* #nosec */ InsecureSkipVerify: /* #nosec */ cfg.GetRedisInsecure() /* #nosec */, /* #nosec */
}
}
和
if cfg.GetRedisTLS() {
clientOpts.TLSConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
//nolint:gosec // NOSONAR #nosec need insecure TLS option for testing and development
/* #nosec */ InsecureSkipVerify /* #nosec */ :/* #nosec */ cfg.GetRedisInsecure(), /* #nosec */
}
}
我在 gosec 專案中打開了這個問題https://github.com/securego/gosec/issues/780
在 gosec 中我還能做些什么來忽略這個?
uj5u.com熱心網友回復:
正如@rodolfo所建議的那樣,我復制了Github上提到的解決方案,因為它可能對其他人有所幫助。
顯然在與陳述句// #nosec G402 相同的行上使用可以解決問題:if
if cfg.GetRedisTLS() { // #nosec G402
clientOpts.TLSConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
InsecureSkipVerify: cfg.GetRedisInsecure(),
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/429847.html
