Skip to content

Commit 2d5b350

Browse files
authored
Merge pull request github#12721 from egregius313/egregius313/java/move-configurations-to-libraries
Java: Move more dataflow configurations to `*Query.qll` files
2 parents e32e28d + 5f3c8fe commit 2d5b350

File tree

62 files changed

+1440
-1076
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1440
-1076
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added the `ArithmeticCommon.qll` library to provide predicates for reasoning about arithmetic operations.
5+
* Added the `ArithmeticTaintedLocalQuery.qll` library to provide the `ArithmeticTaintedLocalOverflowFlow` and `ArithmeticTaintedLocalUnderflowFlow` taint-tracking modules to reason about arithmetic with unvalidated user input.
6+
* Added the `ArithmeticTaintedQuery.qll` library to provide the `RemoteUserInputOverflow` and `RemoteUserInputUnderflow` taint-tracking modules to reason about arithmetic with unvalidated user input.
7+
* Added the `ArithmeticUncontrolledQuery.qll` library to provide the `ArithmeticUncontrolledOverflowFlow` and `ArithmeticUncontrolledUnderflowFlow` taint-tracking modules to reason about arithmetic with uncontrolled user input.
8+
* Added the `ArithmeticWithExtremeValuesQuery.qll` library to provide the `MaxValueFlow` and `MinValueFlow` dataflow modules to reason about arithmetic with extreme values.
9+
* Added the `BrokenCryptoAlgorithmQuery.qll` library to provide the `InsecureCryptoFlow` taint-tracking module to reason about broken cryptographic algorithm vulnerabilities.
10+
* Added the `ExecTaintedLocalQuery.qll` library to provide the `LocalUserInputToArgumentToExecFlow` taint-tracking module to reason about command injection vulnerabilities caused by local data flow.
11+
* Added the `ExternallyControlledFormatStringLocalQuery.qll` library to provide the `ExternallyControlledFormatStringLocalFlow` taint-tracking module to reason about format string vulnerabilities caused by local data flow.
12+
* Added the `ImproperValidationOfArrayConstructionCodeSpecifiedQuery.qll` library to provide the `BoundedFlowSourceFlow` dataflow module to reason about improper validation of code-specified sizes used for array construction.
13+
* Added the `ImproperValidationOfArrayConstructionLocalQuery.qll` library to provide the `ImproperValidationOfArrayConstructionLocalFlow` taint-tracking module to reason about improper validation of local user-provided sizes used for array construction caused by local data flow.
14+
* Added the `ImproperValidationOfArrayConstructionQuery.qll` library to provide the `ImproperValidationOfArrayConstructionFlow` taint-tracking module to reason about improper validation of user-provided size used for array construction.
15+
* Added the `ImproperValidationOfArrayIndexCodeSpecifiedQuery.qll` library to provide the `BoundedFlowSourceFlow` data flow module to reason about about improper validation of code-specified array index.
16+
* Added the `ImproperValidationOfArrayIndexLocalQuery.qll` library to provide the `ImproperValidationOfArrayIndexLocalFlow` taint-tracking module to reason about improper validation of a local user-provided array index.
17+
* Added the `ImproperValidationOfArrayIndexQuery.qll` library to provide the `ImproperValidationOfArrayIndexFlow` taint-tracking module to reason about improper validation of user-provided array index.
18+
* Added the `InsecureCookieQuery.qll` library to provide the `SecureCookieFlow` taint-tracking module to reason about insecure cookie vulnerabilities.
19+
* Added the `MaybeBrokenCryptoAlgorithmQuery.qll` library to provide the `InsecureCryptoFlow` taint-tracking module to reason about broken cryptographic algorithm vulnerabilities.
20+
* Added the `NumericCastTaintedQuery.qll` library to provide the `NumericCastTaintedFlow` taint-tracking module to reason about numeric cast vulnerabilities.
21+
* Added the `ResponseSplittingLocalQuery.qll` library to provide the `ResponseSplittingLocalFlow` taint-tracking module to reason about response splitting vulnerabilities caused by local data flow.
22+
* Added the `SqlConcatenatedQuery.qll` library to provide the `UncontrolledStringBuilderSourceFlow` taint-tracking module to reason about SQL injection vulnerabilities caused by concatenating untrusted strings.
23+
* Added the `SqlTaintedLocalQuery.qll` library to provide the `LocalUserInputToArgumentToSqlFlow` taint-tracking module to reason about SQL injection vulnerabilities caused by local data flow.
24+
* Added the `StackTraceExposureQuery.qll` library to provide the `printsStackExternally`, `stringifiedStackFlowsExternally`, and `getMessageFlowsExternally` predicates to reason about stack trace exposure vulnerabilities.
25+
* Added the `TaintedPermissionQuery.qll` library to provide the `TaintedPermissionFlow` taint-tracking module to reason about tainted permission vulnerabilities.
26+
* Added the `TempDirLocalInformationDisclosureQuery.qll` library to provide the `TempDirSystemGetPropertyToCreate` taint-tracking module to reason about local information disclosure vulnerabilities caused by local data flow.
27+
* Added the `UnsafeHostnameVerificationQuery.qll` library to provide the `TrustAllHostnameVerifierFlow` taint-tracking module to reason about insecure hostname verification vulnerabilities.
28+
* Added the `UrlRedirectLocalQuery.qll` library to provide the `UrlRedirectLocalFlow` taint-tracking module to reason about URL redirection vulnerabilities caused by local data flow.
29+
* Added the `UrlRedirectQuery.qll` library to provide the `UrlRedirectFlow` taint-tracking module to reason about URL redirection vulnerabilities.
30+
* Added the `XPathInjectionQuery.qll` library to provide the `XPathInjectionFlow` taint-tracking module to reason about XPath injection vulnerabilities.
31+
* Added the `XssLocalQuery.qll` library to provide the `XssLocalFlow` taint-tracking module to reason about XSS vulnerabilities caused by local data flow.

java/ql/src/Security/CWE/CWE-190/ArithmeticCommon.qll renamed to java/ql/lib/semmle/code/java/security/ArithmeticCommon.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/** Provides guards and predicates to reason about arithmetic. */
2+
13
import semmle.code.java.arithmetic.Overflow
24
import semmle.code.java.controlflow.Guards
35
private import semmle.code.java.dataflow.SSA
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/** Provides taint-tracking configurations to reason about arithmetic using local-user-controlled data. */
2+
3+
import java
4+
private import semmle.code.java.dataflow.FlowSources
5+
private import semmle.code.java.security.ArithmeticCommon
6+
7+
/**
8+
* A taint-tracking configuration to reason about arithmetic overflow using local-user-controlled data.
9+
*/
10+
module ArithmeticTaintedLocalOverflowConfig implements DataFlow::ConfigSig {
11+
predicate isSource(DataFlow::Node source) { source instanceof LocalUserInput }
12+
13+
predicate isSink(DataFlow::Node sink) { overflowSink(_, sink.asExpr()) }
14+
15+
predicate isBarrier(DataFlow::Node n) { overflowBarrier(n) }
16+
}
17+
18+
/**
19+
* Taint-tracking flow for arithmetic overflow using local-user-controlled data.
20+
*/
21+
module ArithmeticTaintedLocalOverflowFlow =
22+
TaintTracking::Global<ArithmeticTaintedLocalOverflowConfig>;
23+
24+
/**
25+
* A taint-tracking configuration to reason about arithmetic underflow using local-user-controlled data.
26+
*/
27+
module ArithmeticTaintedLocalUnderflowConfig implements DataFlow::ConfigSig {
28+
predicate isSource(DataFlow::Node source) { source instanceof LocalUserInput }
29+
30+
predicate isSink(DataFlow::Node sink) { underflowSink(_, sink.asExpr()) }
31+
32+
predicate isBarrier(DataFlow::Node n) { underflowBarrier(n) }
33+
}
34+
35+
/**
36+
* Taint-tracking flow for arithmetic underflow using local-user-controlled data.
37+
*/
38+
module ArithmeticTaintedLocalUnderflowFlow =
39+
TaintTracking::Global<ArithmeticTaintedLocalUnderflowConfig>;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/** Provides taint-tracking configurations to reason about arithmetic with unvalidated user input. */
2+
3+
import java
4+
private import semmle.code.java.dataflow.FlowSources
5+
private import semmle.code.java.security.ArithmeticCommon
6+
7+
/** A taint-tracking configuration to reason about overflow from unvalidated user input. */
8+
module RemoteUserInputOverflowConfig implements DataFlow::ConfigSig {
9+
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
10+
11+
predicate isSink(DataFlow::Node sink) { overflowSink(_, sink.asExpr()) }
12+
13+
predicate isBarrier(DataFlow::Node n) { overflowBarrier(n) }
14+
}
15+
16+
/** A taint-tracking configuration to reason about underflow from unvalidated user input. */
17+
module RemoteUserInputUnderflowConfig implements DataFlow::ConfigSig {
18+
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
19+
20+
predicate isSink(DataFlow::Node sink) { underflowSink(_, sink.asExpr()) }
21+
22+
predicate isBarrier(DataFlow::Node n) { underflowBarrier(n) }
23+
}
24+
25+
/** Taint-tracking flow for overflow from unvalidated user input. */
26+
module RemoteUserInputOverflow = TaintTracking::Global<RemoteUserInputOverflowConfig>;
27+
28+
/** Taint-tracking flow for underflow from unvalidated user input. */
29+
module RemoteUserInputUnderflow = TaintTracking::Global<RemoteUserInputUnderflowConfig>;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/** Provides taint-tracking configuration to reason about arithmetic with uncontrolled values. */
2+
3+
import java
4+
private import semmle.code.java.dataflow.TaintTracking
5+
private import semmle.code.java.security.RandomQuery
6+
private import semmle.code.java.security.SecurityTests
7+
private import semmle.code.java.security.ArithmeticCommon
8+
9+
private class TaintSource extends DataFlow::ExprNode {
10+
TaintSource() {
11+
exists(RandomDataSource m | not m.resultMayBeBounded() | m.getOutput() = this.getExpr())
12+
}
13+
}
14+
15+
/** A taint-tracking configuration to reason about overflow from arithmetic with uncontrolled values. */
16+
module ArithmeticUncontrolledOverflowConfig implements DataFlow::ConfigSig {
17+
predicate isSource(DataFlow::Node source) { source instanceof TaintSource }
18+
19+
predicate isSink(DataFlow::Node sink) { overflowSink(_, sink.asExpr()) }
20+
21+
predicate isBarrier(DataFlow::Node n) { overflowBarrier(n) }
22+
}
23+
24+
/** Taint-tracking flow to reason about overflow from arithmetic with uncontrolled values. */
25+
module ArithmeticUncontrolledOverflowFlow =
26+
TaintTracking::Global<ArithmeticUncontrolledOverflowConfig>;
27+
28+
/** A taint-tracking configuration to reason about underflow from arithmetic with uncontrolled values. */
29+
module ArithmeticUncontrolledUnderflowConfig implements DataFlow::ConfigSig {
30+
predicate isSource(DataFlow::Node source) { source instanceof TaintSource }
31+
32+
predicate isSink(DataFlow::Node sink) { underflowSink(_, sink.asExpr()) }
33+
34+
predicate isBarrier(DataFlow::Node n) { underflowBarrier(n) }
35+
}
36+
37+
/** Taint-tracking flow to reason about underflow from arithmetic with uncontrolled values. */
38+
module ArithmeticUncontrolledUnderflowFlow =
39+
TaintTracking::Global<ArithmeticUncontrolledUnderflowConfig>;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/** Provides predicates and classes for reasoning about arithmetic with extreme values. */
2+
3+
import java
4+
private import semmle.code.java.dataflow.DataFlow
5+
private import semmle.code.java.security.ArithmeticCommon
6+
7+
/**
8+
* A field representing an extreme value.
9+
*
10+
* For example, `Integer.MAX_VALUE` or `Long.MIN_VALUE`.
11+
*/
12+
abstract class ExtremeValueField extends Field {
13+
ExtremeValueField() { this.getType() instanceof IntegralType }
14+
}
15+
16+
/** A field representing the minimum value of a primitive type. */
17+
private class MinValueField extends ExtremeValueField {
18+
MinValueField() { this.getName() = "MIN_VALUE" }
19+
}
20+
21+
/** A field representing the maximum value of a primitive type. */
22+
private class MaxValueField extends ExtremeValueField {
23+
MaxValueField() { this.getName() = "MAX_VALUE" }
24+
}
25+
26+
/** A variable access that refers to an extreme value. */
27+
class ExtremeSource extends VarAccess {
28+
ExtremeSource() { this.getVariable() instanceof ExtremeValueField }
29+
}
30+
31+
/** A dataflow configuration which tracks flow from maximum values to an overflow. */
32+
module MaxValueFlowConfig implements DataFlow::ConfigSig {
33+
predicate isSource(DataFlow::Node source) {
34+
source.asExpr().(ExtremeSource).getVariable() instanceof MaxValueField
35+
}
36+
37+
predicate isSink(DataFlow::Node sink) { overflowSink(_, sink.asExpr()) }
38+
39+
predicate isBarrierIn(DataFlow::Node n) { isSource(n) }
40+
41+
predicate isBarrier(DataFlow::Node n) { overflowBarrier(n) }
42+
}
43+
44+
/** Dataflow from maximum values to an underflow. */
45+
module MaxValueFlow = DataFlow::Global<MaxValueFlowConfig>;
46+
47+
/** A dataflow configuration which tracks flow from minimum values to an underflow. */
48+
module MinValueFlowConfig implements DataFlow::ConfigSig {
49+
predicate isSource(DataFlow::Node source) {
50+
source.asExpr().(ExtremeSource).getVariable() instanceof MinValueField
51+
}
52+
53+
predicate isSink(DataFlow::Node sink) { underflowSink(_, sink.asExpr()) }
54+
55+
predicate isBarrierIn(DataFlow::Node n) { isSource(n) }
56+
57+
predicate isBarrier(DataFlow::Node n) { underflowBarrier(n) }
58+
}
59+
60+
/** Dataflow from minimum values to an underflow. */
61+
module MinValueFlow = DataFlow::Global<MinValueFlowConfig>;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/** Provides to taint-tracking configuration to reason about the use of broken or risky cryptographic algorithms. */
2+
3+
import java
4+
private import semmle.code.java.security.Encryption
5+
private import semmle.code.java.dataflow.TaintTracking
6+
7+
private class ShortStringLiteral extends StringLiteral {
8+
ShortStringLiteral() { this.getValue().length() < 100 }
9+
}
10+
11+
/**
12+
* A string literal that may refer to a broken or risky cryptographic algorithm.
13+
*/
14+
class BrokenAlgoLiteral extends ShortStringLiteral {
15+
BrokenAlgoLiteral() {
16+
this.getValue().regexpMatch(getInsecureAlgorithmRegex()) and
17+
// Exclude German and French sentences.
18+
not this.getValue().regexpMatch(".*\\p{IsLowercase} des \\p{IsLetter}.*")
19+
}
20+
}
21+
22+
/**
23+
* A taint-tracking configuration to reason about the use of broken or risky cryptographic algorithms.
24+
*/
25+
module InsecureCryptoConfig implements DataFlow::ConfigSig {
26+
predicate isSource(DataFlow::Node n) { n.asExpr() instanceof BrokenAlgoLiteral }
27+
28+
predicate isSink(DataFlow::Node n) { exists(CryptoAlgoSpec c | n.asExpr() = c.getAlgoSpec()) }
29+
30+
predicate isBarrier(DataFlow::Node node) {
31+
node.getType() instanceof PrimitiveType or node.getType() instanceof BoxedType
32+
}
33+
}
34+
35+
/**
36+
* Taint-tracking flow for use of broken or risky cryptographic algorithms.
37+
*/
38+
module InsecureCryptoFlow = TaintTracking::Global<InsecureCryptoConfig>;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/** Provides a taint-tracking configuration to reason about use of externally controlled strings for command injection vulnerabilities. */
2+
3+
import java
4+
private import semmle.code.java.dataflow.FlowSources
5+
private import semmle.code.java.security.ExternalProcess
6+
private import semmle.code.java.security.CommandArguments
7+
8+
/** A taint-tracking configuration to reason about use of externally controlled strings to make command line commands. */
9+
module ExecTaintedLocalConfig implements DataFlow::ConfigSig {
10+
predicate isSource(DataFlow::Node src) { src instanceof LocalUserInput }
11+
12+
predicate isSink(DataFlow::Node sink) { sink.asExpr() instanceof ArgumentToExec }
13+
14+
predicate isBarrier(DataFlow::Node node) {
15+
node.getType() instanceof PrimitiveType
16+
or
17+
node.getType() instanceof BoxedType
18+
or
19+
isSafeCommandArgument(node.asExpr())
20+
}
21+
}
22+
23+
/**
24+
* Taint-tracking flow for use of externally controlled strings to make command line commands.
25+
*/
26+
module ExecTaintedLocalFlow = TaintTracking::Global<ExecTaintedLocalConfig>;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/** Provides a taint-tracking configuration to reason about externally-controlled format strings from local sources. */
2+
3+
import java
4+
private import semmle.code.java.dataflow.FlowSources
5+
private import semmle.code.java.StringFormat
6+
7+
/** A taint-tracking configuration to reason about externally-controlled format strings from local sources. */
8+
module ExternallyControlledFormatStringLocalConfig implements DataFlow::ConfigSig {
9+
predicate isSource(DataFlow::Node source) { source instanceof LocalUserInput }
10+
11+
predicate isSink(DataFlow::Node sink) {
12+
sink.asExpr() = any(StringFormat formatCall).getFormatArgument()
13+
}
14+
}
15+
16+
/**
17+
* Taint-tracking flow for externally-controlled format strings from local sources.
18+
*/
19+
module ExternallyControlledFormatStringLocalFlow =
20+
TaintTracking::Global<ExternallyControlledFormatStringLocalConfig>;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/** Provides a dataflow configuration to reason about improper validation of code-specified size used for array construction. */
2+
3+
import java
4+
private import semmle.code.java.security.internal.ArraySizing
5+
private import semmle.code.java.dataflow.TaintTracking
6+
7+
/**
8+
* A dataflow configuration to reason about improper validation of code-specified size used for array construction.
9+
*/
10+
module BoundedFlowSourceConfig implements DataFlow::ConfigSig {
11+
predicate isSource(DataFlow::Node source) {
12+
source instanceof BoundedFlowSource and
13+
// There is not a fixed lower bound which is greater than zero.
14+
not source.(BoundedFlowSource).lowerBound() > 0
15+
}
16+
17+
predicate isSink(DataFlow::Node sink) {
18+
any(CheckableArrayAccess caa).canThrowOutOfBoundsDueToEmptyArray(sink.asExpr(), _)
19+
}
20+
}
21+
22+
/**
23+
* Dataflow flow for improper validation of code-specified size used for array construction.
24+
*/
25+
module BoundedFlowSourceFlow = DataFlow::Global<BoundedFlowSourceConfig>;

0 commit comments

Comments
 (0)