55import go
66
77module 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-
368 /**
379 * A kind of flag that may indicate security expectations regarding the code it guards.
3810 */
3911 abstract class FlagKind extends string {
40- FlagKind ( ) {
41- this = "securityFeature" or this = "legacyTlsVersion" or this = "insecureCertificate"
42- }
12+ bindingset [ this ]
13+ FlagKind ( ) { any ( ) }
4314
4415 /**
4516 * Returns a flag name of this type.
@@ -54,44 +25,36 @@ module InsecureFeatureFlag {
5425 SecurityFeatureFlag ( ) { this = "securityFeature" }
5526
5627 bindingset [ result ]
57- override string getAFlagName ( ) { isSecurityFlagName ( result ) }
28+ override string getAFlagName ( ) { result . regexpMatch ( "(?i).*(secure|(en|dis)able).*" ) }
5829 }
5930
60- /**
61- * Flags suggesting an optional feature, perhaps deliberately insecure.
62- */
63- string securityFeatureFlag ( ) { result = "securityFeature" }
64-
6531 /**
6632 * 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)
6738 */
6839 class LegacyTlsVersionFlag extends FlagKind {
6940 LegacyTlsVersionFlag ( ) { this = "legacyTlsVersion" }
7041
7142 bindingset [ result ]
72- override string getAFlagName ( ) { isLegacyTlsFlagName ( result ) }
43+ override string getAFlagName ( ) { result . regexpMatch ( "(?i).*(old|intermediate|legacy).*" ) }
7344 }
7445
75- /**
76- * Flags suggesting support for an old or legacy TLS version.
77- */
78- string legacyTlsVersionFlag ( ) { result = "legacyTlsVersion" }
79-
8046 /**
8147 * Flags suggesting a deliberately insecure certificate setup.
8248 */
8349 class InsecureCertificateFlag extends FlagKind {
8450 InsecureCertificateFlag ( ) { this = "insecureCertificate" }
8551
8652 bindingset [ result ]
87- override string getAFlagName ( ) { isCertificateFlagName ( result ) }
53+ override string getAFlagName ( ) {
54+ result .regexpMatch ( "(?i).*(selfCert|selfSign|validat|verif|trust).*" )
55+ }
8856 }
8957
90- /**
91- * Flags suggesting support for an old or legacy feature.
92- */
93- string insecureCertificateFlag ( ) { result = "insecureCertificate" }
94-
9558 /** Gets a global value number representing a (likely) security flag. */
9659 GVN getAFlag ( FlagKind flagKind ) {
9760 // a call like `cfg.disableVerification()`
@@ -151,7 +114,7 @@ module InsecureFeatureFlag {
151114 }
152115
153116 /**
154- * Holds if `node` suggests an old TLS version according to `flagKind`.
117+ * Holds if `node` involves a string of kind `flagKind`.
155118 */
156119 predicate astNodeIsFlag ( AstNode node , FlagKind flagKind ) {
157120 // Map literal flag: value or "flag": value
@@ -177,20 +140,20 @@ module InsecureFeatureFlag {
177140 * Gets a control-flow node that represents a (likely) security feature-flag check
178141 */
179142 ControlFlow:: ConditionGuardNode getASecurityFeatureFlagCheck ( ) {
180- result .ensures ( getAFlag ( securityFeatureFlag ( ) ) .getANode ( ) , _)
143+ result .ensures ( getAFlag ( any ( SecurityFeatureFlag f ) ) .getANode ( ) , _)
181144 }
182145
183146 /**
184147 * Gets a control-flow node that represents a (likely) flag controlling TLS version selection.
185148 */
186149 ControlFlow:: ConditionGuardNode getALegacyTlsVersionCheck ( ) {
187- result .ensures ( getAFlag ( legacyTlsVersionFlag ( ) ) .getANode ( ) , _)
150+ result .ensures ( getAFlag ( any ( LegacyTlsVersionFlag f ) ) .getANode ( ) , _)
188151 }
189152
190153 /**
191154 * Gets a control-flow node that represents a (likely) flag controlling an insecure certificate setup.
192155 */
193156 ControlFlow:: ConditionGuardNode getAnInsecureCertificateCheck ( ) {
194- result .ensures ( getAFlag ( insecureCertificateFlag ( ) ) .getANode ( ) , _)
157+ result .ensures ( getAFlag ( any ( InsecureCertificateFlag f ) ) .getANode ( ) , _)
195158 }
196159}
0 commit comments