Skip to content

Commit bfe0d40

Browse files
committed
using isAdditionalTaintStep
1 parent 3a2a99e commit bfe0d40

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

java/ql/src/experimental/Security/CWE/CWE-094/JShellInjection.ql

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import java
1414
import JShellInjection
15+
import semmle.code.java.dataflow.DataFlow2
1516
import semmle.code.java.dataflow.FlowSources
1617
import DataFlow::PathGraph
1718

@@ -23,15 +24,12 @@ class JShellInjectionConfiguration extends TaintTracking::Configuration {
2324
override predicate isSink(DataFlow::Node sink) { sink instanceof JShellInjectionSink }
2425

2526
override predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
26-
exists(MethodAccess ma |
27-
ma.getMethod().hasName("analyzeCompletion") and
28-
ma.getMethod().getNumberOfParameters() = 1 and
29-
ma.getMethod()
30-
.getDeclaringType()
31-
.getASupertype*()
32-
.hasQualifiedName("jdk.jshell", "SourceCodeAnalysis") and
33-
ma.getArgument(0) = pred.asExpr() and
34-
ma = succ.asExpr()
27+
exists(
28+
SourceCodeAnalysisAnalyzeCompletionCall scaacc, CompletionInfoSourceOrRemainingCall cisorc
29+
|
30+
scaacc.getArgument(0) = pred.asExpr() and
31+
cisorc = succ.asExpr() and
32+
DataFlow2::localExprFlow(scaacc, cisorc.getQualifier())
3533
)
3634
}
3735
}

java/ql/src/experimental/Security/CWE/CWE-094/JShellInjection.qll

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,11 @@ class JShellInjectionSink extends DataFlow::Node {
77
this.asExpr() = any(JShellEvalCall jsec).getArgument(0)
88
or
99
this.asExpr() = any(SourceCodeAnalysisWrappersCall scawc).getArgument(0)
10-
or
11-
exists(MethodAccess ma |
12-
ma.getMethod().hasName("source") and
13-
ma.getMethod().getNumberOfParameters() = 0 and
14-
ma.getMethod()
15-
.getDeclaringType()
16-
.getASupertype*()
17-
.hasQualifiedName("jdk.jshell", "SourceCodeAnalysis$CompletionInfo") and
18-
ma.getQualifier() = this.asExpr() and
19-
(
20-
ma = any(JShellEvalCall jsec).getArgument(0)
21-
or
22-
ma = any(SourceCodeAnalysisWrappersCall scawc).getArgument(0)
23-
)
24-
)
2510
}
2611
}
2712

2813
/** A call to `JShell.eval`. */
29-
class JShellEvalCall extends MethodAccess {
14+
private class JShellEvalCall extends MethodAccess {
3015
JShellEvalCall() {
3116
this.getMethod().hasName("eval") and
3217
this.getMethod().getDeclaringType().hasQualifiedName("jdk.jshell", "JShell") and
@@ -35,10 +20,34 @@ class JShellEvalCall extends MethodAccess {
3520
}
3621

3722
/** A call to `SourceCodeAnalysis.wrappers`. */
38-
class SourceCodeAnalysisWrappersCall extends MethodAccess {
23+
private class SourceCodeAnalysisWrappersCall extends MethodAccess {
3924
SourceCodeAnalysisWrappersCall() {
4025
this.getMethod().hasName("wrappers") and
4126
this.getMethod().getDeclaringType().hasQualifiedName("jdk.jshell", "SourceCodeAnalysis") and
4227
this.getMethod().getNumberOfParameters() = 1
4328
}
4429
}
30+
31+
/** A call to `SourceCodeAnalysis.analyzeCompletion`. */
32+
class SourceCodeAnalysisAnalyzeCompletionCall extends MethodAccess {
33+
SourceCodeAnalysisAnalyzeCompletionCall() {
34+
this.getMethod().hasName("analyzeCompletion") and
35+
this.getMethod()
36+
.getDeclaringType()
37+
.getASupertype*()
38+
.hasQualifiedName("jdk.jshell", "SourceCodeAnalysis") and
39+
this.getMethod().getNumberOfParameters() = 1
40+
}
41+
}
42+
43+
/** A call to `CompletionInfo.source` or `CompletionInfo.remaining`. */
44+
class CompletionInfoSourceOrRemainingCall extends MethodAccess {
45+
CompletionInfoSourceOrRemainingCall() {
46+
this.getMethod().getName() in ["source", "remaining"] and
47+
this.getMethod()
48+
.getDeclaringType()
49+
.getASupertype*()
50+
.hasQualifiedName("jdk.jshell", "SourceCodeAnalysis$CompletionInfo") and
51+
this.getMethod().getNumberOfParameters() = 0
52+
}
53+
}

0 commit comments

Comments
 (0)