Skip to content

Commit 21bea38

Browse files
authored
Merge pull request github#14472 from egregius313/egregius313/sync-local-and-remote-queries
Java: Synchronize `*Local` versions of queries with their remote counterpart
2 parents 822f371 + 31c04b5 commit 21bea38

8 files changed

+47
-4
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The `isBarrier`, `isBarrierIn`, `isBarrierOut`, and `isAdditionalFlowStep` methods of the taint-tracking configurations for local queries in the `ArithmeticTaintedLocalQuery`, `ExternallyControlledFormatStringLocalQuery`, `ImproperValidationOfArrayIndexQuery`, `NumericCastTaintedQuery`, `ResponseSplittingLocalQuery`, `SqlTaintedLocalQuery`, and `XssLocalQuery` libraries have been changed to match their remote counterpart configurations.

java/ql/lib/semmle/code/java/security/ArithmeticTaintedLocalQuery.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ module ArithmeticTaintedLocalOverflowConfig implements DataFlow::ConfigSig {
1313
predicate isSink(DataFlow::Node sink) { overflowSink(_, sink.asExpr()) }
1414

1515
predicate isBarrier(DataFlow::Node n) { overflowBarrier(n) }
16+
17+
predicate isBarrierIn(DataFlow::Node node) { isSource(node) }
1618
}
1719

1820
/**
@@ -30,6 +32,8 @@ module ArithmeticTaintedLocalUnderflowConfig implements DataFlow::ConfigSig {
3032
predicate isSink(DataFlow::Node sink) { underflowSink(_, sink.asExpr()) }
3133

3234
predicate isBarrier(DataFlow::Node n) { underflowBarrier(n) }
35+
36+
predicate isBarrierIn(DataFlow::Node node) { isSource(node) }
3337
}
3438

3539
/**

java/ql/lib/semmle/code/java/security/ExternallyControlledFormatStringLocalQuery.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ module ExternallyControlledFormatStringLocalConfig implements DataFlow::ConfigSi
1111
predicate isSink(DataFlow::Node sink) {
1212
sink.asExpr() = any(StringFormat formatCall).getFormatArgument()
1313
}
14+
15+
predicate isBarrier(DataFlow::Node node) {
16+
node.getType() instanceof NumericType or node.getType() instanceof BooleanType
17+
}
1418
}
1519

1620
/**

java/ql/lib/semmle/code/java/security/ImproperValidationOfArrayIndexLocalQuery.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ module ImproperValidationOfArrayIndexLocalConfig implements DataFlow::ConfigSig
1313
predicate isSink(DataFlow::Node sink) {
1414
any(CheckableArrayAccess caa).canThrowOutOfBounds(sink.asExpr())
1515
}
16+
17+
predicate isBarrier(DataFlow::Node node) { node.getType() instanceof BooleanType }
18+
19+
predicate isBarrierIn(DataFlow::Node node) { isSource(node) }
1620
}
1721

1822
/**

java/ql/lib/semmle/code/java/security/NumericCastTaintedQuery.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,20 @@ module NumericCastLocalFlowConfig implements DataFlow::ConfigSig {
117117
predicate isSource(DataFlow::Node src) { src instanceof LocalUserInput }
118118

119119
predicate isSink(DataFlow::Node sink) {
120-
sink.asExpr() = any(NumericNarrowingCastExpr cast).getExpr()
120+
sink.asExpr() = any(NumericNarrowingCastExpr cast).getExpr() and
121+
sink.asExpr() instanceof VarAccess
121122
}
122123

123124
predicate isBarrier(DataFlow::Node node) {
124125
boundedRead(node.asExpr()) or
125126
castCheck(node.asExpr()) or
126127
node.getType() instanceof SmallType or
127128
smallExpr(node.asExpr()) or
128-
node.getEnclosingCallable() instanceof HashCodeMethod
129+
node.getEnclosingCallable() instanceof HashCodeMethod or
130+
exists(RightShiftOp e | e.getShiftedVariable().getAnAccess() = node.asExpr())
129131
}
132+
133+
predicate isBarrierIn(DataFlow::Node node) { isSource(node) }
130134
}
131135

132136
/**

java/ql/lib/semmle/code/java/security/ResponseSplittingLocalQuery.qll

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,21 @@ module ResponseSplittingLocalConfig implements DataFlow::ConfigSig {
1313
predicate isSink(DataFlow::Node sink) { sink instanceof HeaderSplittingSink }
1414

1515
predicate isBarrier(DataFlow::Node node) {
16-
node.getType() instanceof PrimitiveType or
16+
node.getType() instanceof PrimitiveType
17+
or
1718
node.getType() instanceof BoxedType
19+
or
20+
exists(MethodAccess ma, string methodName, CompileTimeConstantExpr target |
21+
node.asExpr() = ma and
22+
ma.getMethod().hasQualifiedName("java.lang", "String", methodName) and
23+
target = ma.getArgument(0) and
24+
(
25+
methodName = "replace" and target.getIntValue() = [10, 13] // 10 == "\n", 13 == "\r"
26+
or
27+
methodName = "replaceAll" and
28+
target.getStringValue().regexpMatch(".*([\n\r]|\\[\\^[^\\]\r\n]*\\]).*")
29+
)
30+
)
1831
}
1932
}
2033

java/ql/lib/semmle/code/java/security/SqlTaintedLocalQuery.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ module LocalUserInputToQueryInjectionFlowConfig implements DataFlow::ConfigSig {
1717
predicate isSink(DataFlow::Node sink) { sink instanceof QueryInjectionSink }
1818

1919
predicate isBarrier(DataFlow::Node node) {
20-
node.getType() instanceof PrimitiveType or node.getType() instanceof BoxedType
20+
node.getType() instanceof PrimitiveType or
21+
node.getType() instanceof BoxedType or
22+
node.getType() instanceof NumberType
2123
}
2224

2325
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {

java/ql/lib/semmle/code/java/security/XssLocalQuery.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ module XssLocalConfig implements DataFlow::ConfigSig {
1212
predicate isSource(DataFlow::Node source) { source instanceof LocalUserInput }
1313

1414
predicate isSink(DataFlow::Node sink) { sink instanceof XssSink }
15+
16+
predicate isBarrier(DataFlow::Node node) { node instanceof XssSanitizer }
17+
18+
predicate isBarrierOut(DataFlow::Node node) { node instanceof XssSinkBarrier }
19+
20+
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
21+
any(XssAdditionalTaintStep s).step(node1, node2)
22+
}
1523
}
1624

1725
/**

0 commit comments

Comments
 (0)