Skip to content

Commit 9e29847

Browse files
committed
Java: Fix identification of supported endpoints in framework mode
1 parent 73ebd21 commit 9e29847

File tree

3 files changed

+42
-29
lines changed

3 files changed

+42
-29
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,40 @@
11
private import java
2+
private import semmle.code.java.dataflow.ExternalFlow
3+
private import semmle.code.java.dataflow.FlowSources
4+
private import semmle.code.java.dataflow.internal.DataFlowPrivate
25
private import ModelEditor
36

47
/**
58
* A class of effectively public callables in library code.
69
*/
710
class ExternalEndpoint extends Endpoint {
811
ExternalEndpoint() { not this.fromSource() }
12+
13+
/** Gets a node that is an input to a call to this API. */
14+
private DataFlow::Node getAnInput() {
15+
exists(Call call | call.getCallee().getSourceDeclaration() = this |
16+
result.asExpr().(Argument).getCall() = call or
17+
result.(ArgumentNode).getCall().asCall() = call
18+
)
19+
}
20+
21+
/** Gets a node that is an output from a call to this API. */
22+
private DataFlow::Node getAnOutput() {
23+
exists(Call call | call.getCallee().getSourceDeclaration() = this |
24+
result.asExpr() = call or
25+
result.(DataFlow::PostUpdateNode).getPreUpdateNode().(ArgumentNode).getCall().asCall() = call
26+
)
27+
}
28+
29+
override predicate hasSummary() {
30+
Endpoint.super.hasSummary()
31+
or
32+
TaintTracking::localAdditionalTaintStep(this.getAnInput(), _)
33+
}
34+
35+
override predicate isSource() {
36+
this.getAnOutput() instanceof RemoteFlowSource or sourceNode(this.getAnOutput(), _)
37+
}
38+
39+
override predicate isSink() { sinkNode(this.getAnInput(), _) }
940
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
private import java
2+
private import semmle.code.java.dataflow.internal.DataFlowPrivate
3+
private import semmle.code.java.dataflow.internal.FlowSummaryImplSpecific
24
private import semmle.code.java.dataflow.internal.ModelExclusions
35
private import ModelEditor
46

57
/**
68
* A class of effectively public callables from source code.
79
*/
8-
class PublicEndpointFromSource extends Endpoint, ModelApi { }
10+
class PublicEndpointFromSource extends Endpoint, ModelApi {
11+
override predicate isSource() { sourceElement(this, _, _, _) }
12+
13+
override predicate isSink() { sinkElement(this, _, _, _) }
14+
}

java/ql/src/utils/modeleditor/ModelEditor.qll

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
/** Provides classes and predicates related to handling APIs for the VS Code extension. */
22

33
private import java
4-
private import semmle.code.java.dataflow.DataFlow
54
private import semmle.code.java.dataflow.ExternalFlow
6-
private import semmle.code.java.dataflow.FlowSources
75
private import semmle.code.java.dataflow.FlowSummary
8-
private import semmle.code.java.dataflow.internal.DataFlowPrivate
9-
private import semmle.code.java.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
106
private import semmle.code.java.dataflow.TaintTracking
117
private import semmle.code.java.dataflow.internal.ModelExclusions
128

@@ -58,37 +54,17 @@ class Endpoint extends Callable {
5854
not exists(this.getJarVersion()) and result = ""
5955
}
6056

61-
/** Gets a node that is an input to a call to this API. */
62-
private DataFlow::Node getAnInput() {
63-
exists(Call call | call.getCallee().getSourceDeclaration() = this |
64-
result.asExpr().(Argument).getCall() = call or
65-
result.(ArgumentNode).getCall().asCall() = call
66-
)
67-
}
68-
69-
/** Gets a node that is an output from a call to this API. */
70-
private DataFlow::Node getAnOutput() {
71-
exists(Call call | call.getCallee().getSourceDeclaration() = this |
72-
result.asExpr() = call or
73-
result.(DataFlow::PostUpdateNode).getPreUpdateNode().(ArgumentNode).getCall().asCall() = call
74-
)
75-
}
76-
7757
/** Holds if this API has a supported summary. */
7858
pragma[nomagic]
79-
predicate hasSummary() {
80-
this = any(SummarizedCallable sc).asCallable() or
81-
TaintTracking::localAdditionalTaintStep(this.getAnInput(), _)
82-
}
59+
predicate hasSummary() { this = any(SummarizedCallable sc).asCallable() }
8360

61+
/** Holds if this API is a known source. */
8462
pragma[nomagic]
85-
predicate isSource() {
86-
this.getAnOutput() instanceof RemoteFlowSource or sourceNode(this.getAnOutput(), _)
87-
}
63+
abstract predicate isSource();
8864

8965
/** Holds if this API is a known sink. */
9066
pragma[nomagic]
91-
predicate isSink() { sinkNode(this.getAnInput(), _) }
67+
abstract predicate isSink();
9268

9369
/** Holds if this API is a known neutral. */
9470
pragma[nomagic]

0 commit comments

Comments
 (0)