Skip to content

Commit 0512940

Browse files
authored
Merge pull request #20075 from d10c/d10c/diff-informed-phase-3-go
Go: Diff-informed queries: phase 3 (non-trivial locations)
2 parents 8000e7c + 8824677 commit 0512940

16 files changed

+96
-0
lines changed

go/ql/lib/semmle/go/security/AllocationSizeOverflow.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ module AllocationSizeOverflow {
5656
succ = c
5757
)
5858
}
59+
60+
predicate observeDiffInformedIncrementalMode() { any() }
61+
62+
Location getASelectedSinkLocation(DataFlow::Node sink) {
63+
result = sink.getLocation()
64+
or
65+
exists(DataFlow::Node allocsz |
66+
isSinkWithAllocationSize(sink, allocsz) and
67+
result = allocsz.getLocation()
68+
)
69+
}
5970
}
6071

6172
/** Tracks taint flow to find allocation-size overflows. */

go/ql/lib/semmle/go/security/CommandInjection.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ module CommandInjection {
2424
}
2525

2626
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
27+
28+
predicate observeDiffInformedIncrementalMode() { any() }
2729
}
2830

2931
/**
@@ -80,6 +82,8 @@ module CommandInjection {
8082
node instanceof Sanitizer or
8183
node = any(ArgumentArrayWithDoubleDash array).getASanitizedElement()
8284
}
85+
86+
predicate observeDiffInformedIncrementalMode() { any() }
8387
}
8488

8589
/**

go/ql/lib/semmle/go/security/ExternalAPIs.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ private module UntrustedDataConfig implements DataFlow::ConfigSig {
186186
predicate isSource(DataFlow::Node source) { source instanceof ActiveThreatModelSource }
187187

188188
predicate isSink(DataFlow::Node sink) { sink instanceof ExternalApiDataNode }
189+
190+
predicate observeDiffInformedIncrementalMode() { any() }
189191
}
190192

191193
/**

go/ql/lib/semmle/go/security/HardcodedCredentials.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ module HardcodedCredentials {
3030
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
3131

3232
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
33+
34+
predicate observeDiffInformedIncrementalMode() { any() }
3335
}
3436

3537
/** Tracks taint flow for reasoning about hardcoded credentials. */

go/ql/lib/semmle/go/security/IncorrectIntegerConversionLib.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,12 @@ private module ConversionWithoutBoundsCheckConfig implements DataFlow::StateConf
440440
state2 = node2.(FlowStateTransformer).transform(state1) and
441441
DataFlow::simpleLocalFlowStep(node1, node2, _)
442442
}
443+
444+
predicate observeDiffInformedIncrementalMode() { any() }
445+
446+
Location getASelectedSinkLocation(DataFlow::Node sink) {
447+
result = sink.getASuccessor().getLocation()
448+
}
443449
}
444450

445451
/**

go/ql/lib/semmle/go/security/InsecureRandomness.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ module InsecureRandomness {
3939
n2.getType() instanceof IntegerType
4040
)
4141
}
42+
43+
predicate observeDiffInformedIncrementalMode() {
44+
none() // Can't have accurate sink location override because of secondary use of `flowPath` in select.
45+
}
4246
}
4347

4448
/**

go/ql/lib/semmle/go/security/ReflectedXss.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ module ReflectedXss {
2222
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
2323

2424
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
25+
26+
predicate observeDiffInformedIncrementalMode() { any() }
27+
28+
Location getASelectedSinkLocation(DataFlow::Node sink) {
29+
result = sink.getLocation()
30+
or
31+
result = sink.(SharedXss::Sink).getAssociatedLoc().getLocation()
32+
}
2533
}
2634

2735
/** Tracks taint flow from untrusted data to XSS attack vectors. */

go/ql/lib/semmle/go/security/RequestForgery.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ module RequestForgery {
3131
w.writesField(v.getAUse(), f, pred) and succ = v.getAUse()
3232
)
3333
}
34+
35+
predicate observeDiffInformedIncrementalMode() { any() }
36+
37+
Location getASelectedSinkLocation(DataFlow::Node sink) {
38+
result = sink.getLocation()
39+
or
40+
result = sink.(Sink).getARequest().getLocation()
41+
}
3442
}
3543

3644
/** Tracks taint flow from untrusted data to request forgery attack vectors. */

go/ql/lib/semmle/go/security/SafeUrlFlow.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ module SafeUrlFlow {
3636
or
3737
node instanceof SanitizerEdge
3838
}
39+
40+
predicate observeDiffInformedIncrementalMode() {
41+
none() // only used as secondary configuration
42+
}
3943
}
4044

4145
/** Tracks taint flow for reasoning about safe URLs. */

go/ql/src/InconsistentCode/UnhandledCloseWritableHandle.ql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ module UnhandledFileCloseConfig implements DataFlow::ConfigSig {
128128
predicate isSource(DataFlow::Node source) { isWritableFileHandle(source, _) }
129129

130130
predicate isSink(DataFlow::Node sink) { isCloseSink(sink, _) }
131+
132+
predicate observeDiffInformedIncrementalMode() { any() }
133+
134+
Location getASelectedSourceLocation(DataFlow::Node source) {
135+
exists(DataFlow::CallNode openCall | result = openCall.getLocation() |
136+
isWritableFileHandle(source, openCall)
137+
)
138+
}
131139
}
132140

133141
/**

0 commit comments

Comments
 (0)