Skip to content

Commit

Permalink
Merge pull request #14472 from egregius313/egregius313/sync-local-and…
Browse files Browse the repository at this point in the history
…-remote-queries

Java: Synchronize `*Local` versions of queries with their remote counterpart
  • Loading branch information
egregius313 authored Oct 16, 2023
2 parents 822f371 + 31c04b5 commit 21bea38
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* 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.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module ArithmeticTaintedLocalOverflowConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node sink) { overflowSink(_, sink.asExpr()) }

predicate isBarrier(DataFlow::Node n) { overflowBarrier(n) }

predicate isBarrierIn(DataFlow::Node node) { isSource(node) }
}

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

predicate isBarrier(DataFlow::Node n) { underflowBarrier(n) }

predicate isBarrierIn(DataFlow::Node node) { isSource(node) }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ module ExternallyControlledFormatStringLocalConfig implements DataFlow::ConfigSi
predicate isSink(DataFlow::Node sink) {
sink.asExpr() = any(StringFormat formatCall).getFormatArgument()
}

predicate isBarrier(DataFlow::Node node) {
node.getType() instanceof NumericType or node.getType() instanceof BooleanType
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ module ImproperValidationOfArrayIndexLocalConfig implements DataFlow::ConfigSig
predicate isSink(DataFlow::Node sink) {
any(CheckableArrayAccess caa).canThrowOutOfBounds(sink.asExpr())
}

predicate isBarrier(DataFlow::Node node) { node.getType() instanceof BooleanType }

predicate isBarrierIn(DataFlow::Node node) { isSource(node) }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,20 @@ module NumericCastLocalFlowConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node src) { src instanceof LocalUserInput }

predicate isSink(DataFlow::Node sink) {
sink.asExpr() = any(NumericNarrowingCastExpr cast).getExpr()
sink.asExpr() = any(NumericNarrowingCastExpr cast).getExpr() and
sink.asExpr() instanceof VarAccess
}

predicate isBarrier(DataFlow::Node node) {
boundedRead(node.asExpr()) or
castCheck(node.asExpr()) or
node.getType() instanceof SmallType or
smallExpr(node.asExpr()) or
node.getEnclosingCallable() instanceof HashCodeMethod
node.getEnclosingCallable() instanceof HashCodeMethod or
exists(RightShiftOp e | e.getShiftedVariable().getAnAccess() = node.asExpr())
}

predicate isBarrierIn(DataFlow::Node node) { isSource(node) }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,21 @@ module ResponseSplittingLocalConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node sink) { sink instanceof HeaderSplittingSink }

predicate isBarrier(DataFlow::Node node) {
node.getType() instanceof PrimitiveType or
node.getType() instanceof PrimitiveType
or
node.getType() instanceof BoxedType
or
exists(MethodAccess ma, string methodName, CompileTimeConstantExpr target |
node.asExpr() = ma and
ma.getMethod().hasQualifiedName("java.lang", "String", methodName) and
target = ma.getArgument(0) and
(
methodName = "replace" and target.getIntValue() = [10, 13] // 10 == "\n", 13 == "\r"
or
methodName = "replaceAll" and
target.getStringValue().regexpMatch(".*([\n\r]|\\[\\^[^\\]\r\n]*\\]).*")
)
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ module LocalUserInputToQueryInjectionFlowConfig implements DataFlow::ConfigSig {
predicate isSink(DataFlow::Node sink) { sink instanceof QueryInjectionSink }

predicate isBarrier(DataFlow::Node node) {
node.getType() instanceof PrimitiveType or node.getType() instanceof BoxedType
node.getType() instanceof PrimitiveType or
node.getType() instanceof BoxedType or
node.getType() instanceof NumberType
}

predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
Expand Down
8 changes: 8 additions & 0 deletions java/ql/lib/semmle/code/java/security/XssLocalQuery.qll
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ module XssLocalConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) { source instanceof LocalUserInput }

predicate isSink(DataFlow::Node sink) { sink instanceof XssSink }

predicate isBarrier(DataFlow::Node node) { node instanceof XssSanitizer }

predicate isBarrierOut(DataFlow::Node node) { node instanceof XssSinkBarrier }

predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
any(XssAdditionalTaintStep s).step(node1, node2)
}
}

/**
Expand Down

0 comments on commit 21bea38

Please sign in to comment.