Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 4b6810e

Browse files
committed
InsecureFeatureFlag: make getAFlag a member of FlagKind
1 parent 7dd2010 commit 4b6810e

File tree

3 files changed

+51
-51
lines changed

3 files changed

+51
-51
lines changed

ql/src/Security/CWE-295/DisabledCertificateCheck.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class InsecureCertificateFlag extends FlagKind {
5252
* Gets a control-flow node that represents a (likely) flag controlling an insecure certificate setup.
5353
*/
5454
ControlFlow::ConditionGuardNode getAnInsecureCertificateCheck() {
55-
result.ensures(getAFlag(any(InsecureCertificateFlag f)).getANode(), _)
55+
result.ensures(any(InsecureCertificateFlag f).getAFlag().getANode(), _)
5656
}
5757

5858
/**

ql/src/Security/CWE-327/InsecureTLS.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class LegacyTlsVersionFlag extends FlagKind {
261261
* Gets a control-flow node that represents a (likely) flag controlling TLS version selection.
262262
*/
263263
ControlFlow::ConditionGuardNode getALegacyTlsVersionCheck() {
264-
result.ensures(getAFlag(any(LegacyTlsVersionFlag f)).getANode(), _)
264+
result.ensures(any(LegacyTlsVersionFlag f).getAFlag().getANode(), _)
265265
}
266266

267267
/**

ql/src/semmle/go/security/InsecureFeatureFlag.qll

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,54 @@ module InsecureFeatureFlag {
1616
* Returns a flag name of this type.
1717
*/
1818
abstract string getAFlagName();
19+
20+
/** Gets a global value number representing a (likely) security flag. */
21+
GVN getAFlag() {
22+
// a call like `cfg.disableVerification()`
23+
exists(DataFlow::CallNode c | c.getTarget().getName() = getAFlagName() |
24+
result = globalValueNumber(c)
25+
)
26+
or
27+
// a variable or field like `insecure`
28+
exists(ValueEntity flag | flag.getName() = getAFlagName() |
29+
result = globalValueNumber(flag.getARead())
30+
)
31+
or
32+
// a string constant such as `"insecure"` or `"skipVerification"`
33+
exists(DataFlow::Node const | const.getStringValue() = getAFlagName() |
34+
result = globalValueNumber(const)
35+
)
36+
or
37+
// track feature flags through various operations
38+
exists(DataFlow::Node flag | flag = getAFlag().getANode() |
39+
// tuple destructurings
40+
result = globalValueNumber(DataFlow::extractTupleElement(flag, _))
41+
or
42+
// type casts
43+
exists(DataFlow::TypeCastNode tc |
44+
tc.getOperand() = flag and
45+
result = globalValueNumber(tc)
46+
)
47+
or
48+
// pointer dereferences
49+
exists(DataFlow::PointerDereferenceNode deref |
50+
deref.getOperand() = flag and
51+
result = globalValueNumber(deref)
52+
)
53+
or
54+
// calls like `os.Getenv("DISABLE_TLS_VERIFICATION")`
55+
exists(DataFlow::CallNode call |
56+
call.getAnArgument() = flag and
57+
result = globalValueNumber(call)
58+
)
59+
or
60+
// comparisons like `insecure == true`
61+
exists(DataFlow::EqualityTestNode eq |
62+
eq.getAnOperand() = flag and
63+
result = globalValueNumber(eq)
64+
)
65+
)
66+
}
1967
}
2068

2169
/**
@@ -28,54 +76,6 @@ module InsecureFeatureFlag {
2876
override string getAFlagName() { result.regexpMatch("(?i).*(secure|(en|dis)able).*") }
2977
}
3078

31-
/** Gets a global value number representing a (likely) security flag. */
32-
GVN getAFlag(FlagKind flagKind) {
33-
// a call like `cfg.disableVerification()`
34-
exists(DataFlow::CallNode c | c.getTarget().getName() = flagKind.getAFlagName() |
35-
result = globalValueNumber(c)
36-
)
37-
or
38-
// a variable or field like `insecure`
39-
exists(ValueEntity flag | flag.getName() = flagKind.getAFlagName() |
40-
result = globalValueNumber(flag.getARead())
41-
)
42-
or
43-
// a string constant such as `"insecure"` or `"skipVerification"`
44-
exists(DataFlow::Node const | const.getStringValue() = flagKind.getAFlagName() |
45-
result = globalValueNumber(const)
46-
)
47-
or
48-
// track feature flags through various operations
49-
exists(DataFlow::Node flag | flag = getAFlag(flagKind).getANode() |
50-
// tuple destructurings
51-
result = globalValueNumber(DataFlow::extractTupleElement(flag, _))
52-
or
53-
// type casts
54-
exists(DataFlow::TypeCastNode tc |
55-
tc.getOperand() = flag and
56-
result = globalValueNumber(tc)
57-
)
58-
or
59-
// pointer dereferences
60-
exists(DataFlow::PointerDereferenceNode deref |
61-
deref.getOperand() = flag and
62-
result = globalValueNumber(deref)
63-
)
64-
or
65-
// calls like `os.Getenv("DISABLE_TLS_VERIFICATION")`
66-
exists(DataFlow::CallNode call |
67-
call.getAnArgument() = flag and
68-
result = globalValueNumber(call)
69-
)
70-
or
71-
// comparisons like `insecure == true`
72-
exists(DataFlow::EqualityTestNode eq |
73-
eq.getAnOperand() = flag and
74-
result = globalValueNumber(eq)
75-
)
76-
)
77-
}
78-
7979
/**
8080
* Holds for string literals or named values matching `flagKind` and their fields.
8181
*/
@@ -113,6 +113,6 @@ module InsecureFeatureFlag {
113113
* Gets a control-flow node that represents a (likely) security feature-flag check
114114
*/
115115
ControlFlow::ConditionGuardNode getASecurityFeatureFlagCheck() {
116-
result.ensures(getAFlag(any(SecurityFeatureFlag f)).getANode(), _)
116+
result.ensures(any(SecurityFeatureFlag f).getAFlag().getANode(), _)
117117
}
118118
}

0 commit comments

Comments
 (0)