File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -115,9 +115,23 @@ module InsecureFeatureFlag {
115115 }
116116
117117 /**
118- * Gets a guard that represents a (likely) security feature-flag check.
118+ * Holds if `block` is controlled by a flag of kind `flagKind`.
119+ *
120+ * For a switch case expression, only the matching branch is controlled by that flag. Other
121+ * branches, including the default case, are reached when the flag does not match.
119122 */
120- Guard getASecurityFeatureFlagCheck ( ) {
121- result = any ( SecurityFeatureFlag f ) .getAFlag ( ) .getANode ( ) .asExpr ( )
123+ predicate flagControls ( FlagKind flagKind , BasicBlock block ) {
124+ exists ( GVN flag , Guard guard , boolean branch |
125+ flag = flagKind .getAFlag ( ) and
126+ guard = flag .getANode ( ) .asExpr ( ) and
127+ guard .controls ( block , branch ) and
128+ (
129+ branch = true
130+ or
131+ not exists ( Expr caseExpr |
132+ caseExpr = flag .getANode ( ) .asExpr ( ) and caseExpr .getParent ( ) instanceof CaseClause
133+ )
134+ )
135+ )
122136 }
123137}
Original file line number Diff line number Diff line change @@ -50,13 +50,6 @@ class InsecureCertificateFlag extends FlagKind {
5050 }
5151}
5252
53- /**
54- * Gets a guard that represents a (likely) flag controlling an insecure certificate setup.
55- */
56- Guard getAnInsecureCertificateCheck ( ) {
57- result = any ( InsecureCertificateFlag f ) .getAFlag ( ) .getANode ( ) .asExpr ( )
58- }
59-
6053/**
6154 * Returns flag kinds relevant to this query: a generic security feature flag, or one
6255 * specifically controlling insecure certificate configuration.
8174 f .hasQualifiedName ( "crypto/tls" , "Config" , "InsecureSkipVerify" ) and
8275 rhs .getBoolValue ( ) = true and
8376 // exclude writes guarded by a feature flag
84- not [ getASecurityFeatureFlagCheck ( ) , getAnInsecureCertificateCheck ( ) ]
85- .controls ( w .getBasicBlock ( ) , _) and
77+ not flagControls ( securityOrTlsVersionFlag ( ) , w .getBasicBlock ( ) ) and
8678 // exclude results in functions whose name documents the insecurity
8779 not exists ( FuncDef fn | fn = w .getRoot ( ) |
8880 isSecurityOrCertificateConfigFlag ( fn .getEnclosingFunction * ( ) .getName ( ) )
Original file line number Diff line number Diff line change @@ -247,13 +247,6 @@ class LegacyTlsVersionFlag extends FlagKind {
247247 override string getAFlagName ( ) { result .regexpMatch ( "(?i).*(old|intermediate|legacy).*" ) }
248248}
249249
250- /**
251- * Gets a guard that represents a (likely) flag controlling TLS version selection.
252- */
253- Guard getALegacyTlsVersionCheck ( ) {
254- result = any ( LegacyTlsVersionFlag f ) .getAFlag ( ) .getANode ( ) .asExpr ( )
255- }
256-
257250/**
258251 * Returns flag kinds relevant to this query: a generic security feature flag, or one
259252 * specifically controlling TLS version selection.
@@ -276,8 +269,7 @@ where
276269 isInsecureTlsCipherFlow ( source .asPathNode2 ( ) , sink .asPathNode2 ( ) , message )
277270 ) and
278271 // Exclude sources or sinks guarded by a feature or legacy flag
279- not [ getASecurityFeatureFlagCheck ( ) , getALegacyTlsVersionCheck ( ) ]
280- .controls ( [ source , sink ] .getNode ( ) .getBasicBlock ( ) , _) and
272+ not flagControls ( securityOrTlsVersionFlag ( ) , [ source , sink ] .getNode ( ) .getBasicBlock ( ) ) and
281273 // Exclude sources or sinks that occur lexically within a block related to a feature or legacy flag
282274 not astNodeIsFlag ( [ source , sink ] .getNode ( ) .asExpr ( ) .getParent * ( ) , securityOrTlsVersionFlag ( ) ) and
283275 // Exclude results in functions whose name documents insecurity
You can’t perform that action at this time.
0 commit comments