Skip to content

Commit 50a9219

Browse files
committed
C#: Re-factor most of the logic out of the model editor query files.
1 parent 45432f2 commit 50a9219

File tree

4 files changed

+67
-61
lines changed

4 files changed

+67
-61
lines changed

csharp/ql/src/utils/modeleditor/ApplicationModeEndpoints.ql

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,9 @@
77
* @tags modeleditor endpoints application-mode
88
*/
99

10-
private import csharp
11-
private import semmle.code.csharp.dataflow.ExternalFlow
12-
private import semmle.code.csharp.dataflow.FlowSummary
13-
private import semmle.code.csharp.dataflow.internal.DataFlowDispatch as DataFlowDispatch
14-
private import semmle.code.csharp.dataflow.internal.DataFlowPrivate
15-
private import semmle.code.csharp.dataflow.internal.DataFlowImplCommon as DataFlowImplCommon
16-
private import semmle.code.csharp.dataflow.internal.TaintTrackingPrivate
17-
private import semmle.code.csharp.security.dataflow.flowsources.Remote
18-
private import ModelEditor
19-
20-
class ExternalEndpoint extends Endpoint {
21-
ExternalEndpoint() { this.fromLibrary() }
22-
23-
/** Gets a node that is an input to a call to this API. */
24-
private ArgumentNode getAnInput() {
25-
result
26-
.getCall()
27-
.(DataFlowDispatch::NonDelegateDataFlowCall)
28-
.getATarget(_)
29-
.getUnboundDeclaration() = this
30-
}
31-
32-
/** Gets a node that is an output from a call to this API. */
33-
private DataFlow::Node getAnOutput() {
34-
exists(
35-
Call c, DataFlowDispatch::NonDelegateDataFlowCall dc, DataFlowImplCommon::ReturnKindExt ret
36-
|
37-
dc.getDispatchCall().getCall() = c and
38-
c.getTarget().getUnboundDeclaration() = this
39-
|
40-
result = ret.getAnOutNode(dc)
41-
)
42-
}
43-
44-
override predicate hasSummary() {
45-
this instanceof SummarizedCallable
46-
or
47-
defaultAdditionalTaintStep(this.getAnInput(), _)
48-
}
49-
50-
override predicate isSource() {
51-
this.getAnOutput() instanceof RemoteFlowSource or sourceNode(this.getAnOutput(), _)
52-
}
53-
54-
override predicate isSink() { sinkNode(this.getAnInput(), _) }
55-
}
10+
import csharp
11+
import ApplicationModeEndpointsQuery
12+
import ModelEditor
5613

5714
private Call aUsage(ExternalEndpoint api) { result.getTarget().getUnboundDeclaration() = api }
5815

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
private import csharp
2+
private import semmle.code.csharp.dataflow.ExternalFlow
3+
private import semmle.code.csharp.dataflow.FlowSummary
4+
private import semmle.code.csharp.dataflow.internal.DataFlowDispatch as DataFlowDispatch
5+
private import semmle.code.csharp.dataflow.internal.DataFlowPrivate
6+
private import semmle.code.csharp.dataflow.internal.DataFlowImplCommon as DataFlowImplCommon
7+
private import semmle.code.csharp.dataflow.internal.TaintTrackingPrivate
8+
private import semmle.code.csharp.security.dataflow.flowsources.Remote
9+
private import ModelEditor
10+
11+
class ExternalEndpoint extends Endpoint {
12+
ExternalEndpoint() { this.fromLibrary() }
13+
14+
/** Gets a node that is an input to a call to this API. */
15+
private ArgumentNode getAnInput() {
16+
result
17+
.getCall()
18+
.(DataFlowDispatch::NonDelegateDataFlowCall)
19+
.getATarget(_)
20+
.getUnboundDeclaration() = this
21+
}
22+
23+
/** Gets a node that is an output from a call to this API. */
24+
private DataFlow::Node getAnOutput() {
25+
exists(
26+
Call c, DataFlowDispatch::NonDelegateDataFlowCall dc, DataFlowImplCommon::ReturnKindExt ret
27+
|
28+
dc.getDispatchCall().getCall() = c and
29+
c.getTarget().getUnboundDeclaration() = this
30+
|
31+
result = ret.getAnOutNode(dc)
32+
)
33+
}
34+
35+
override predicate hasSummary() {
36+
this instanceof SummarizedCallable
37+
or
38+
defaultAdditionalTaintStep(this.getAnInput(), _)
39+
}
40+
41+
override predicate isSource() {
42+
this.getAnOutput() instanceof RemoteFlowSource or sourceNode(this.getAnOutput(), _)
43+
}
44+
45+
override predicate isSink() { sinkNode(this.getAnInput(), _) }
46+
}

csharp/ql/src/utils/modeleditor/FrameworkModeEndpoints.ql

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,9 @@
77
* @tags modeleditor endpoints framework-mode
88
*/
99

10-
private import csharp
11-
private import semmle.code.csharp.dataflow.ExternalFlow
12-
private import semmle.code.csharp.dataflow.FlowSummary
13-
private import semmle.code.csharp.frameworks.Test
14-
private import ModelEditor
15-
16-
class PublicEndpointFromSource extends Endpoint {
17-
PublicEndpointFromSource() { this.fromSource() and not this.getFile() instanceof TestFile }
18-
19-
override predicate hasSummary() { this instanceof SummarizedCallable }
20-
21-
override predicate isSource() { this instanceof SourceCallable }
22-
23-
override predicate isSink() { this instanceof SinkCallable }
24-
}
10+
import csharp
11+
import FrameworkModeEndpointsQuery
12+
import ModelEditor
2513

2614
from PublicEndpointFromSource endpoint, string apiName, boolean supported, string type
2715
where
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
private import csharp
2+
private import semmle.code.csharp.dataflow.ExternalFlow
3+
private import semmle.code.csharp.dataflow.FlowSummary
4+
private import semmle.code.csharp.frameworks.Test
5+
private import ModelEditor
6+
7+
class PublicEndpointFromSource extends Endpoint {
8+
PublicEndpointFromSource() { this.fromSource() and not this.getFile() instanceof TestFile }
9+
10+
override predicate hasSummary() { this instanceof SummarizedCallable }
11+
12+
override predicate isSource() { this instanceof SourceCallable }
13+
14+
override predicate isSink() { this instanceof SinkCallable }
15+
}

0 commit comments

Comments
 (0)