Skip to content

Commit 3c68245

Browse files
committed
Java: apply query alert restrictions
1 parent b1a3a2e commit 3c68245

File tree

60 files changed

+243
-13
lines changed

Some content is hidden

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

60 files changed

+243
-13
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ abstract class Storable extends Call {
3636
abstract Expr getAStore();
3737
}
3838

39-
private module SensitiveSourceFlowConfig implements DataFlow::ConfigSig {
39+
/** Flow configuration for sensitive data flowing into cleartext storage. */
40+
module SensitiveSourceFlowConfig implements DataFlow::ConfigSig {
4041
predicate isSource(DataFlow::Node src) { src.asExpr() instanceof SensitiveExpr }
4142

4243
predicate isSink(DataFlow::Node sink) { sink instanceof CleartextStorageSink }

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ private import semmle.code.java.security.InformationLeak
77
/**
88
* One of the `printStackTrace()` overloads on `Throwable`.
99
*/
10-
private class PrintStackTraceMethod extends Method {
10+
class PrintStackTraceMethod extends Method {
1111
PrintStackTraceMethod() {
1212
this.getDeclaringType()
1313
.getSourceDeclaration()
@@ -17,7 +17,11 @@ private class PrintStackTraceMethod extends Method {
1717
}
1818
}
1919

20-
private module ServletWriterSourceToPrintStackTraceMethodFlowConfig implements DataFlow::ConfigSig {
20+
/**
21+
* Flow configuration for xss vulnerable writer source flowing to `Throwable.printStackTrace()` on
22+
* a stream that is connected to external output.
23+
*/
24+
module ServletWriterSourceToPrintStackTraceMethodFlowConfig implements DataFlow::ConfigSig {
2125
predicate isSource(DataFlow::Node src) { src instanceof XssVulnerableWriterSourceNode }
2226

2327
predicate isSink(DataFlow::Node sink) {
@@ -55,7 +59,10 @@ private predicate printWriterOnStringWriter(Expr printWriter, Variable stringWri
5559
)
5660
}
5761

58-
private predicate stackTraceExpr(Expr exception, MethodCall stackTraceString) {
62+
/**
63+
* Holds if `stackTraceString` writes the stack trace from `exception` to a string.
64+
*/
65+
predicate stackTraceExpr(Expr exception, MethodCall stackTraceString) {
5966
exists(Expr printWriter, Variable stringWriterVar, MethodCall printStackCall |
6067
printWriterOnStringWriter(printWriter, stringWriterVar) and
6168
printStackCall.getMethod() instanceof PrintStackTraceMethod and
@@ -66,7 +73,8 @@ private predicate stackTraceExpr(Expr exception, MethodCall stackTraceString) {
6673
)
6774
}
6875

69-
private module StackTraceStringToHttpResponseSinkFlowConfig implements DataFlow::ConfigSig {
76+
/** Flow configuration for stack trace flowing to http response. */
77+
module StackTraceStringToHttpResponseSinkFlowConfig implements DataFlow::ConfigSig {
7078
predicate isSource(DataFlow::Node src) { stackTraceExpr(_, src.asExpr()) }
7179

7280
predicate isSink(DataFlow::Node sink) { sink instanceof InformationLeakSink }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ deprecated class UnsafeDeserializationConfig extends TaintTracking::Configuratio
334334
}
335335

336336
/** Tracks flows from remote user input to a deserialization sink. */
337-
private module UnsafeDeserializationConfig implements DataFlow::ConfigSig {
337+
module UnsafeDeserializationConfig implements DataFlow::ConfigSig {
338338
predicate isSource(DataFlow::Node source) { source instanceof ThreatModelFlowSource }
339339

340340
predicate isSink(DataFlow::Node sink) { sink instanceof UnsafeDeserializationSink }

java/ql/src/Likely Bugs/Arithmetic/InformationLoss.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Variable getVariable(Expr dest) {
3535

3636
from DangerousAssignOpExpr a, Expr e, Top v
3737
where
38+
AlertFiltering::filterByLocation(a.getLocation()) and
3839
e = a.getSource() and
3940
problematicCasting(a.getDest().getType(), e) and
4041
(

java/ql/src/Security/CWE/CWE-020/OverlyLargeRange.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* external/cwe/cwe-020
1313
*/
1414

15+
private import semmle.code.java.AlertFiltering
1516
private import semmle.code.java.regex.RegexTreeView::RegexTreeView as TreeView
1617
import codeql.regex.OverlyLargeRangeQuery::Make<TreeView>
1718

@@ -22,6 +23,7 @@ TreeView::RegExpCharacterClass potentialMisparsedCharClass() {
2223

2324
from TreeView::RegExpCharacterRange range, string reason
2425
where
26+
AlertFiltering::filterByLocation(range.getLocation()) and
2527
problem(range, reason) and
2628
not range.getParent() = potentialMisparsedCharClass()
2729
select range, "Suspicious character range that " + reason + "."

java/ql/src/Security/CWE/CWE-022/TaintedPath.ql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
import java
1717
import semmle.code.java.security.PathCreation
1818
import semmle.code.java.security.TaintedPathQuery
19+
20+
module TaintedPathFlow = TaintTracking::Global<DataFlow::FilteredConfig<TaintedPathConfig>>;
21+
1922
import TaintedPathFlow::PathGraph
2023

2124
from TaintedPathFlow::PathNode source, TaintedPathFlow::PathNode sink

java/ql/src/Security/CWE/CWE-022/ZipSlip.ql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
import java
1616
import semmle.code.java.security.ZipSlipQuery
17+
18+
module ZipSlipFlow = TaintTracking::Global<DataFlow::FilteredConfig<ZipSlipConfig>>;
19+
1720
import ZipSlipFlow::PathGraph
1821

1922
from ZipSlipFlow::PathNode source, ZipSlipFlow::PathNode sink

java/ql/src/Security/CWE/CWE-023/PartialPathTraversalFromRemote.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
*/
1212

1313
import semmle.code.java.security.PartialPathTraversalQuery
14+
15+
module PartialPathTraversalFromRemoteFlow =
16+
TaintTracking::Global<DataFlow::FilteredConfig<PartialPathTraversalFromRemoteConfig>>;
17+
1418
import PartialPathTraversalFromRemoteFlow::PathGraph
1519

1620
from

java/ql/src/Security/CWE/CWE-074/JndiInjection.ql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
import java
1515
import semmle.code.java.security.JndiInjectionQuery
16+
17+
module JndiInjectionFlow = TaintTracking::Global<DataFlow::FilteredConfig<JndiInjectionFlowConfig>>;
18+
1619
import JndiInjectionFlow::PathGraph
1720

1821
from JndiInjectionFlow::PathNode source, JndiInjectionFlow::PathNode sink

java/ql/src/Security/CWE/CWE-074/XsltInjection.ql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
import java
1515
import semmle.code.java.security.XsltInjectionQuery
16+
17+
module XsltInjectionFlow = TaintTracking::Global<DataFlow::FilteredConfig<XsltInjectionFlowConfig>>;
18+
1619
import XsltInjectionFlow::PathGraph
1720

1821
from XsltInjectionFlow::PathNode source, XsltInjectionFlow::PathNode sink

0 commit comments

Comments
 (0)