Skip to content

Commit 5c302fb

Browse files
authored
Merge pull request #121 from cosmincojocar/tls
Add a check for PreferServerCipherSuites flag of tls.Config
2 parents 1c8e7ff + 2262f5d commit 5c302fb

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

rules/tls.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ func (t *InsecureConfigTLS) processTlsConfVal(n *ast.KeyValueExpr, c *gas.Contex
6868
return gas.NewIssue(c, n, "TLS InsecureSkipVerify may be true.", gas.High, gas.Low)
6969
}
7070

71+
case "PreferServerCipherSuites":
72+
if node, ok := n.Value.(*ast.Ident); ok {
73+
if node.Name == "false" {
74+
return gas.NewIssue(c, n, "TLS PreferServerCipherSuites set false.", gas.Medium, gas.High)
75+
}
76+
} else {
77+
// TODO(tk): symbol tab look up to get the actual value
78+
return gas.NewIssue(c, n, "TLS PreferServerCipherSuites may be false.", gas.Medium, gas.Low)
79+
}
80+
7181
case "MinVersion":
7282
if ival, ierr := gas.GetInt(n.Value); ierr == nil {
7383
if (int16)(ival) < t.MinVersion {
@@ -90,7 +100,9 @@ func (t *InsecureConfigTLS) processTlsConfVal(n *ast.KeyValueExpr, c *gas.Contex
90100
if ret := t.processTlsCipherSuites(n, c); ret != nil {
91101
return ret
92102
}
103+
93104
}
105+
94106
}
95107
return nil
96108
}

rules/tls_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,32 @@ func TestInsecureCipherSuite(t *testing.T) {
138138

139139
checkTestResults(t, issues, 1, "TLS Bad Cipher Suite: TLS_RSA_WITH_RC4_128_SHA")
140140
}
141+
142+
func TestPreferServerCipherSuites(t *testing.T) {
143+
config := map[string]interface{}{"ignoreNosec": false}
144+
analyzer := gas.NewAnalyzer(config, nil)
145+
analyzer.AddRule(NewModernTlsCheck(config))
146+
147+
issues := gasTestRunner(`
148+
package main
149+
150+
import (
151+
"crypto/tls"
152+
"fmt"
153+
"net/http"
154+
)
155+
156+
func main() {
157+
tr := &http.Transport{
158+
TLSClientConfig: &tls.Config{PreferServerCipherSuites: false},
159+
}
160+
client := &http.Client{Transport: tr}
161+
_, err := client.Get("https://golang.org/")
162+
if err != nil {
163+
fmt.Println(err)
164+
}
165+
}
166+
`, analyzer)
167+
168+
checkTestResults(t, issues, 1, "TLS PreferServerCipherSuites set false")
169+
}

0 commit comments

Comments
 (0)