Skip to content

Commit 897c203

Browse files
authored
Reset the state of TLS rule after each version check (#570)
Signed-off-by: Cosmin Cojocar <[email protected]>
1 parent 6c57ae1 commit 897c203

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq
369369
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
370370
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
371371
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
372+
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
372373
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
373374
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
374375
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=

rules/tls.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ func (t *insecureConfigTLS) checkVersion(n ast.Node, c *gosec.Context) *gosec.Is
146146
return nil
147147
}
148148

149+
func (t *insecureConfigTLS) resetVersion() {
150+
t.actualMaxVersion = 0
151+
t.actualMinVersion = 0
152+
}
153+
149154
func (t *insecureConfigTLS) Match(n ast.Node, c *gosec.Context) (*gosec.Issue, error) {
150155
if complit, ok := n.(*ast.CompositeLit); ok && complit.Type != nil {
151156
actualType := c.Info.TypeOf(complit.Type)
@@ -158,7 +163,9 @@ func (t *insecureConfigTLS) Match(n ast.Node, c *gosec.Context) (*gosec.Issue, e
158163
}
159164
}
160165
}
161-
return t.checkVersion(complit, c), nil
166+
issue := t.checkVersion(complit, c)
167+
t.resetVersion()
168+
return issue, nil
162169
}
163170
}
164171
return nil, nil

testutils/source.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -2057,7 +2057,24 @@ func main() {
20572057
if err != nil {
20582058
fmt.Println(err)
20592059
}
2060-
}`}, 0, gosec.NewConfig()}}
2060+
}`}, 0, gosec.NewConfig()}, {[]string{`
2061+
package p0
2062+
2063+
import "crypto/tls"
2064+
2065+
func TlsConfig0() *tls.Config {
2066+
var v uint16 = 0
2067+
return &tls.Config{MinVersion: v}
2068+
}
2069+
`, `
2070+
package p0
2071+
2072+
import "crypto/tls"
2073+
2074+
func TlsConfig1() *tls.Config {
2075+
return &tls.Config{MinVersion: 0x0304}
2076+
}
2077+
`}, 1, gosec.NewConfig()}}
20612078

20622079
// SampleCodeG403 - weak key strength
20632080
SampleCodeG403 = []CodeSample{

0 commit comments

Comments
 (0)