@@ -63,31 +63,51 @@ func (t *insecureConfigTLS) processTLSCipherSuites(n ast.Node, c *gosec.Context)
63
63
return nil
64
64
}
65
65
66
- func (t * insecureConfigTLS ) processTLSConfVal (n * ast.KeyValueExpr , c * gosec.Context ) * gosec.Issue {
67
- if ident , ok := n .Key .(* ast.Ident ); ok {
66
+ func (t * insecureConfigTLS ) processTLSConf (n ast.Node , c * gosec.Context ) * gosec.Issue {
67
+ if kve , ok := n .(* ast.KeyValueExpr ); ok {
68
+ issue := t .processTLSConfVal (kve .Key , kve .Value , c )
69
+ if issue != nil {
70
+ return issue
71
+ }
72
+ } else if assign , ok := n .(* ast.AssignStmt ); ok {
73
+ if len (assign .Lhs ) < 1 || len (assign .Rhs ) < 1 {
74
+ return nil
75
+ }
76
+ if selector , ok := assign .Lhs [0 ].(* ast.SelectorExpr ); ok {
77
+ issue := t .processTLSConfVal (selector .Sel , assign .Rhs [0 ], c )
78
+ if issue != nil {
79
+ return issue
80
+ }
81
+ }
82
+ }
83
+ return nil
84
+ }
85
+
86
+ func (t * insecureConfigTLS ) processTLSConfVal (key ast.Expr , value ast.Expr , c * gosec.Context ) * gosec.Issue {
87
+ if ident , ok := key .(* ast.Ident ); ok {
68
88
switch ident .Name {
69
89
case "InsecureSkipVerify" :
70
- if node , ok := n . Value .(* ast.Ident ); ok {
90
+ if node , ok := value .(* ast.Ident ); ok {
71
91
if node .Name != "false" {
72
- return gosec .NewIssue (c , n , t .ID (), "TLS InsecureSkipVerify set true." , gosec .High , gosec .High )
92
+ return gosec .NewIssue (c , value , t .ID (), "TLS InsecureSkipVerify set true." , gosec .High , gosec .High )
73
93
}
74
94
} else {
75
95
// TODO(tk): symbol tab look up to get the actual value
76
- return gosec .NewIssue (c , n , t .ID (), "TLS InsecureSkipVerify may be true." , gosec .High , gosec .Low )
96
+ return gosec .NewIssue (c , value , t .ID (), "TLS InsecureSkipVerify may be true." , gosec .High , gosec .Low )
77
97
}
78
98
79
99
case "PreferServerCipherSuites" :
80
- if node , ok := n . Value .(* ast.Ident ); ok {
100
+ if node , ok := value .(* ast.Ident ); ok {
81
101
if node .Name == "false" {
82
- return gosec .NewIssue (c , n , t .ID (), "TLS PreferServerCipherSuites set false." , gosec .Medium , gosec .High )
102
+ return gosec .NewIssue (c , value , t .ID (), "TLS PreferServerCipherSuites set false." , gosec .Medium , gosec .High )
83
103
}
84
104
} else {
85
105
// TODO(tk): symbol tab look up to get the actual value
86
- return gosec .NewIssue (c , n , t .ID (), "TLS PreferServerCipherSuites may be false." , gosec .Medium , gosec .Low )
106
+ return gosec .NewIssue (c , value , t .ID (), "TLS PreferServerCipherSuites may be false." , gosec .Medium , gosec .Low )
87
107
}
88
108
89
109
case "MinVersion" :
90
- if d , ok := n . Value .(* ast.Ident ); ok {
110
+ if d , ok := value .(* ast.Ident ); ok {
91
111
obj := d .Obj
92
112
if obj == nil {
93
113
for _ , f := range c .PkgFiles {
@@ -118,10 +138,10 @@ func (t *insecureConfigTLS) processTLSConfVal(n *ast.KeyValueExpr, c *gosec.Cont
118
138
t .actualMinVersion = ival
119
139
}
120
140
}
121
- } else if ival , ierr := gosec .GetInt (n . Value ); ierr == nil {
141
+ } else if ival , ierr := gosec .GetInt (value ); ierr == nil {
122
142
t .actualMinVersion = ival
123
143
} else {
124
- if se , ok := n . Value .(* ast.SelectorExpr ); ok {
144
+ if se , ok := value .(* ast.SelectorExpr ); ok {
125
145
if pkg , ok := se .X .(* ast.Ident ); ok {
126
146
if ip , ok := gosec .GetImportPath (pkg .Name , c ); ok && ip == "crypto/tls" {
127
147
t .actualMinVersion = t .mapVersion (se .Sel .Name )
@@ -131,10 +151,10 @@ func (t *insecureConfigTLS) processTLSConfVal(n *ast.KeyValueExpr, c *gosec.Cont
131
151
}
132
152
133
153
case "MaxVersion" :
134
- if ival , ierr := gosec .GetInt (n . Value ); ierr == nil {
154
+ if ival , ierr := gosec .GetInt (value ); ierr == nil {
135
155
t .actualMaxVersion = ival
136
156
} else {
137
- if se , ok := n . Value .(* ast.SelectorExpr ); ok {
157
+ if se , ok := value .(* ast.SelectorExpr ); ok {
138
158
if pkg , ok := se .X .(* ast.Ident ); ok {
139
159
if ip , ok := gosec .GetImportPath (pkg .Name , c ); ok && ip == "crypto/tls" {
140
160
t .actualMaxVersion = t .mapVersion (se .Sel .Name )
@@ -144,7 +164,7 @@ func (t *insecureConfigTLS) processTLSConfVal(n *ast.KeyValueExpr, c *gosec.Cont
144
164
}
145
165
146
166
case "CipherSuites" :
147
- if ret := t .processTLSCipherSuites (n . Value , c ); ret != nil {
167
+ if ret := t .processTLSCipherSuites (value , c ); ret != nil {
148
168
return ret
149
169
}
150
170
@@ -192,17 +212,27 @@ func (t *insecureConfigTLS) Match(n ast.Node, c *gosec.Context) (*gosec.Issue, e
192
212
actualType := c .Info .TypeOf (complit .Type )
193
213
if actualType != nil && actualType .String () == t .requiredType {
194
214
for _ , elt := range complit .Elts {
195
- if kve , ok := elt .(* ast.KeyValueExpr ); ok {
196
- issue := t .processTLSConfVal (kve , c )
197
- if issue != nil {
198
- return issue , nil
199
- }
215
+ issue := t .processTLSConf (elt , c )
216
+ if issue != nil {
217
+ return issue , nil
200
218
}
201
219
}
202
220
issue := t .checkVersion (complit , c )
203
221
t .resetVersion ()
204
222
return issue , nil
205
223
}
224
+ } else {
225
+ if assign , ok := n .(* ast.AssignStmt ); ok && len (assign .Lhs ) > 0 {
226
+ if selector , ok := assign .Lhs [0 ].(* ast.SelectorExpr ); ok {
227
+ actualType := c .Info .TypeOf (selector .X )
228
+ if actualType != nil && actualType .String () == t .requiredType {
229
+ issue := t .processTLSConf (assign , c )
230
+ if issue != nil {
231
+ return issue , nil
232
+ }
233
+ }
234
+ }
235
+ }
206
236
}
207
237
return nil , nil
208
238
}
0 commit comments