Skip to content

Commit 1fbcf10

Browse files
committed
Add a test for tls min version defined in a different file
1 parent b12c0f6 commit 1fbcf10

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

rules/tls.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (t *insecureConfigTLS) processTLSConfVal(n *ast.KeyValueExpr, c *gosec.Cont
8787
}
8888

8989
case "MinVersion":
90-
if d, ok := n.Value.(*ast.Ident); ok {
90+
if d, ok := n.Value.(*ast.Ident); ok && d.Obj != nil {
9191
if vs, ok := d.Obj.Decl.(*ast.ValueSpec); ok && len(vs.Values) > 0 {
9292
if s, ok := vs.Values[0].(*ast.SelectorExpr); ok {
9393
x := s.X.(*ast.Ident).Name

testutils/source.go

+21
Original file line numberDiff line numberDiff line change
@@ -2838,6 +2838,27 @@ func TlsConfig1() *tls.Config {
28382838
return &tls.Config{MinVersion: 0x0304}
28392839
}
28402840
`}, 1, gosec.NewConfig()},
2841+
{[]string{`
2842+
package main
2843+
2844+
import (
2845+
"crypto/tls"
2846+
"fmt"
2847+
)
2848+
2849+
func main() {
2850+
cfg := tls.Config{
2851+
MinVersion: MinVer,
2852+
}
2853+
fmt.Println("tls min version", cfg.MinVersion)
2854+
}
2855+
`, `
2856+
package main
2857+
2858+
import "crypto/tls"
2859+
2860+
const MinVer = tls.VersionTLS13
2861+
`}, 0, gosec.NewConfig()},
28412862
}
28422863

28432864
// SampleCodeG403 - weak key strength

0 commit comments

Comments
 (0)