5
5
import go
6
6
7
7
module InsecureFeatureFlag {
8
- /**
9
- * Holds if `name` may be the name of a feature flag that controls a security feature.
10
- */
11
- bindingset [ name]
12
- predicate isSecurityFlagName ( string name ) { name .regexpMatch ( "(?i).*(secure|(en|dis)able).*" ) }
13
-
14
- /**
15
- * Holds if `name` may be the name of a feature flag that controls whether certificate checking is
16
- * enabled.
17
- */
18
- bindingset [ name]
19
- predicate isCertificateFlagName ( string name ) {
20
- name .regexpMatch ( "(?i).*(selfCert|selfSign|validat|verif|trust).*" )
21
- }
22
-
23
- /**
24
- * Holds if `name` suggests an old or legacy version of TLS.
25
- *
26
- * We accept 'intermediate' because it appears to be common for TLS users
27
- * to define three profiles: modern, intermediate, legacy/old, perhaps based
28
- * on https://wiki.mozilla.org/Security/Server_Side_TLS (though note the
29
- * 'intermediate' used there would now pass muster according to this query)
30
- */
31
- bindingset [ name]
32
- predicate isLegacyTlsFlagName ( string name ) {
33
- name .regexpMatch ( "(?i).*(old|intermediate|legacy).*" )
34
- }
35
-
36
8
/**
37
9
* A kind of flag that may indicate security expectations regarding the code it guards.
38
10
*/
39
11
abstract class FlagKind extends string {
40
- FlagKind ( ) {
41
- this = "securityFeature" or this = "legacyTlsVersion" or this = "insecureCertificate"
42
- }
12
+ bindingset [ this ]
13
+ FlagKind ( ) { any ( ) }
43
14
44
15
/**
45
16
* Returns a flag name of this type.
@@ -54,44 +25,36 @@ module InsecureFeatureFlag {
54
25
SecurityFeatureFlag ( ) { this = "securityFeature" }
55
26
56
27
bindingset [ result ]
57
- override string getAFlagName ( ) { isSecurityFlagName ( result ) }
28
+ override string getAFlagName ( ) { result . regexpMatch ( "(?i).*(secure|(en|dis)able).*" ) }
58
29
}
59
30
60
- /**
61
- * Flags suggesting an optional feature, perhaps deliberately insecure.
62
- */
63
- string securityFeatureFlag ( ) { result = "securityFeature" }
64
-
65
31
/**
66
32
* Flags suggesting support for an old or legacy TLS version.
33
+ *
34
+ * We accept 'intermediate' because it appears to be common for TLS users
35
+ * to define three profiles: modern, intermediate, legacy/old, perhaps based
36
+ * on https://wiki.mozilla.org/Security/Server_Side_TLS (though note the
37
+ * 'intermediate' used there would now pass muster according to this query)
67
38
*/
68
39
class LegacyTlsVersionFlag extends FlagKind {
69
40
LegacyTlsVersionFlag ( ) { this = "legacyTlsVersion" }
70
41
71
42
bindingset [ result ]
72
- override string getAFlagName ( ) { isLegacyTlsFlagName ( result ) }
43
+ override string getAFlagName ( ) { result . regexpMatch ( "(?i).*(old|intermediate|legacy).*" ) }
73
44
}
74
45
75
- /**
76
- * Flags suggesting support for an old or legacy TLS version.
77
- */
78
- string legacyTlsVersionFlag ( ) { result = "legacyTlsVersion" }
79
-
80
46
/**
81
47
* Flags suggesting a deliberately insecure certificate setup.
82
48
*/
83
49
class InsecureCertificateFlag extends FlagKind {
84
50
InsecureCertificateFlag ( ) { this = "insecureCertificate" }
85
51
86
52
bindingset [ result ]
87
- override string getAFlagName ( ) { isCertificateFlagName ( result ) }
53
+ override string getAFlagName ( ) {
54
+ result .regexpMatch ( "(?i).*(selfCert|selfSign|validat|verif|trust).*" )
55
+ }
88
56
}
89
57
90
- /**
91
- * Flags suggesting support for an old or legacy feature.
92
- */
93
- string insecureCertificateFlag ( ) { result = "insecureCertificate" }
94
-
95
58
/** Gets a global value number representing a (likely) security flag. */
96
59
GVN getAFlag ( FlagKind flagKind ) {
97
60
// a call like `cfg.disableVerification()`
@@ -151,7 +114,7 @@ module InsecureFeatureFlag {
151
114
}
152
115
153
116
/**
154
- * Holds if `node` suggests an old TLS version according to `flagKind`.
117
+ * Holds if `node` involves a string of kind `flagKind`.
155
118
*/
156
119
predicate astNodeIsFlag ( AstNode node , FlagKind flagKind ) {
157
120
// Map literal flag: value or "flag": value
@@ -177,20 +140,20 @@ module InsecureFeatureFlag {
177
140
* Gets a control-flow node that represents a (likely) security feature-flag check
178
141
*/
179
142
ControlFlow:: ConditionGuardNode getASecurityFeatureFlagCheck ( ) {
180
- result .ensures ( getAFlag ( securityFeatureFlag ( ) ) .getANode ( ) , _)
143
+ result .ensures ( getAFlag ( any ( SecurityFeatureFlag f ) ) .getANode ( ) , _)
181
144
}
182
145
183
146
/**
184
147
* Gets a control-flow node that represents a (likely) flag controlling TLS version selection.
185
148
*/
186
149
ControlFlow:: ConditionGuardNode getALegacyTlsVersionCheck ( ) {
187
- result .ensures ( getAFlag ( legacyTlsVersionFlag ( ) ) .getANode ( ) , _)
150
+ result .ensures ( getAFlag ( any ( LegacyTlsVersionFlag f ) ) .getANode ( ) , _)
188
151
}
189
152
190
153
/**
191
154
* Gets a control-flow node that represents a (likely) flag controlling an insecure certificate setup.
192
155
*/
193
156
ControlFlow:: ConditionGuardNode getAnInsecureCertificateCheck ( ) {
194
- result .ensures ( getAFlag ( insecureCertificateFlag ( ) ) .getANode ( ) , _)
157
+ result .ensures ( getAFlag ( any ( InsecureCertificateFlag f ) ) .getANode ( ) , _)
195
158
}
196
159
}
0 commit comments