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+
814 /**
915 * Holds if `name` may be the name of a feature flag that controls whether certificate checking is
1016 * enabled.
1117 */
1218 bindingset [ name]
13- predicate isFeatureFlagName ( string name ) {
14- name .regexpMatch ( "(?i).*(secure| selfCert|selfSign|validat|verif|trust|(en|dis)able ).*" )
19+ predicate isCertificateFlagName ( string name ) {
20+ name .regexpMatch ( "(?i).*(selfCert|selfSign|validat|verif|trust).*" )
1521 }
1622
1723 /**
18- * Holds if `name` suggests an old or legacy version.
24+ * Holds if `name` suggests an old or legacy version of TLS .
1925 *
2026 * We accept 'intermediate' because it appears to be common for TLS users
2127 * to define three profiles: modern, intermediate, legacy/old, perhaps based
2228 * on https://wiki.mozilla.org/Security/Server_Side_TLS (though note the
2329 * 'intermediate' used there would now pass muster according to this query)
2430 */
2531 bindingset [ name]
26- predicate isLegacyFlagName ( string name ) { name .regexpMatch ( "(?i).*(old|intermediate|legacy).*" ) }
32+ predicate isLegacyTlsFlagName ( string name ) {
33+ name .regexpMatch ( "(?i).*(old|intermediate|legacy).*" )
34+ }
2735
2836 /**
2937 * A kind of flag that may indicate security expectations regarding the code it guards.
3038 */
3139 abstract class FlagKind extends string {
32- FlagKind ( ) { this = "feature" or this = "legacy" }
40+ FlagKind ( ) {
41+ this = "securityFeature" or this = "legacyTlsVersion" or this = "insecureCertificate"
42+ }
3343
3444 /**
3545 * Returns a flag name of this type.
@@ -40,32 +50,47 @@ module InsecureFeatureFlag {
4050 /**
4151 * Flags suggesting an optional feature, perhaps deliberately insecure.
4252 */
43- class FeatureFlag extends FlagKind {
44- FeatureFlag ( ) { this = "feature " }
53+ class SecurityFeatureFlag extends FlagKind {
54+ SecurityFeatureFlag ( ) { this = "securityFeature " }
4555
4656 bindingset [ result ]
47- override string getAFlagName ( ) { isFeatureFlagName ( result ) }
57+ override string getAFlagName ( ) { isSecurityFlagName ( result ) }
4858 }
4959
5060 /**
5161 * Flags suggesting an optional feature, perhaps deliberately insecure.
5262 */
53- string featureFlag ( ) { result = "feature " }
63+ string securityFeatureFlag ( ) { result = "securityFeature " }
5464
5565 /**
56- * Flags suggesting support for an old or legacy feature .
66+ * Flags suggesting support for an old or legacy TLS version .
5767 */
58- class LegacyFlag extends FlagKind {
59- LegacyFlag ( ) { this = "legacy " }
68+ class LegacyTlsVersionFlag extends FlagKind {
69+ LegacyTlsVersionFlag ( ) { this = "legacyTlsVersion " }
6070
6171 bindingset [ result ]
62- override string getAFlagName ( ) { isLegacyFlagName ( result ) }
72+ override string getAFlagName ( ) { isLegacyTlsFlagName ( result ) }
73+ }
74+
75+ /**
76+ * Flags suggesting support for an old or legacy TLS version.
77+ */
78+ string legacyTlsVersionFlag ( ) { result = "legacyTlsVersion" }
79+
80+ /**
81+ * Flags suggesting a deliberately insecure certificate setup.
82+ */
83+ class InsecureCertificateFlag extends FlagKind {
84+ InsecureCertificateFlag ( ) { this = "insecureCertificate" }
85+
86+ bindingset [ result ]
87+ override string getAFlagName ( ) { isCertificateFlagName ( result ) }
6388 }
6489
6590 /**
6691 * Flags suggesting support for an old or legacy feature.
6792 */
68- string legacyFlag ( ) { result = "legacy " }
93+ string insecureCertificateFlag ( ) { result = "insecureCertificate " }
6994
7095 /** Gets a global value number representing a (likely) security flag. */
7196 GVN getAFlag ( FlagKind flagKind ) {
@@ -149,16 +174,23 @@ module InsecureFeatureFlag {
149174 }
150175
151176 /**
152- * Gets a control-flow node that represents a (likely) feature-flag check for certificate checking.
177+ * Gets a control-flow node that represents a (likely) security feature-flag check
178+ */
179+ ControlFlow:: ConditionGuardNode getASecurityFeatureFlagCheck ( ) {
180+ result .ensures ( getAFlag ( securityFeatureFlag ( ) ) .getANode ( ) , _)
181+ }
182+
183+ /**
184+ * Gets a control-flow node that represents a (likely) flag controlling TLS version selection.
153185 */
154- ControlFlow:: ConditionGuardNode getAFeatureFlagCheck ( ) {
155- result .ensures ( getAFlag ( featureFlag ( ) ) .getANode ( ) , _)
186+ ControlFlow:: ConditionGuardNode getALegacyTlsVersionCheck ( ) {
187+ result .ensures ( getAFlag ( legacyTlsVersionFlag ( ) ) .getANode ( ) , _)
156188 }
157189
158190 /**
159- * Gets a control-flow node that represents a (likely) feature- flag check for certificate checking .
191+ * Gets a control-flow node that represents a (likely) flag controlling an insecure certificate setup .
160192 */
161- ControlFlow:: ConditionGuardNode getALegacyVersionCheck ( ) {
162- result .ensures ( getAFlag ( legacyFlag ( ) ) .getANode ( ) , _)
193+ ControlFlow:: ConditionGuardNode getAnInsecureCertificateCheck ( ) {
194+ result .ensures ( getAFlag ( insecureCertificateFlag ( ) ) .getANode ( ) , _)
163195 }
164196}
0 commit comments