Skip to content

Commit 714e1d6

Browse files
committed
Refactor: Create writesFieldOnSsaWithFields
1 parent 66d4fbc commit 714e1d6

File tree

6 files changed

+19
-27
lines changed

6 files changed

+19
-27
lines changed

go/ql/lib/semmle/go/controlflow/ControlFlowGraph.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ module ControlFlow {
152152
)
153153
}
154154

155+
/**
156+
* Holds if this node sets the value of field `f` on `v` to `rhs`.
157+
*/
158+
predicate writesFieldOnSsaWithFields(SsaWithFields v, Field f, DataFlow::Node rhs) {
159+
exists(IR::Instruction insn | this.writesFieldInsn(insn, f, rhs.asInstruction()) |
160+
v.getAUse().asInstruction() = insn
161+
)
162+
}
163+
155164
private predicate writesFieldInsn(IR::Instruction base, Field f, IR::Instruction rhs) {
156165
exists(IR::FieldTarget trg | trg = super.getLhs() |
157166
(

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,9 @@ module OpenUrlRedirect {
9090
*/
9191
class PathAssignmentBarrier extends Barrier, Read {
9292
PathAssignmentBarrier() {
93-
exists(Write w, DataFlow::Node base, SsaWithFields var |
93+
exists(Write w, SsaWithFields var |
9494
hasHostnameSanitizingSubstring(w.getRhs()) and
95-
w.writesField(base, any(Field f | f.getName() = "Path"), _) and
96-
[base, base.(DataFlow::PostUpdateNode).getPreUpdateNode()] = var.getAUse() and
95+
w.writesFieldOnSsaWithFields(var, any(Field f | f.getName() = "Path"), _) and
9796
useIsDominated(var, w, this)
9897
)
9998
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,8 @@ module RequestForgery {
2727

2828
predicate isAdditionalFlowStep(DataFlow::Node pred, DataFlow::Node succ) {
2929
// propagate to a URL when its host is assigned to
30-
exists(Write w, DataFlow::Node base, Field f, SsaWithFields v |
31-
f.hasQualifiedName("net/url", "URL", "Host")
32-
|
33-
w.writesField(base, f, pred) and
34-
[base, base.(DataFlow::PostUpdateNode).getPreUpdateNode()] = v.getAUse() and
30+
exists(Write w, Field f, SsaWithFields v | f.hasQualifiedName("net/url", "URL", "Host") |
31+
w.writesFieldOnSsaWithFields(v, f, pred) and
3532
succ = v.getAUse()
3633
)
3734
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@ module SafeUrlFlow {
2323

2424
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
2525
// propagate to a URL when its host is assigned to
26-
exists(Write w, DataFlow::Node base, Field f, SsaWithFields v |
27-
f.hasQualifiedName("net/url", "URL", "Host")
28-
|
29-
w.writesField(base, f, node1) and
30-
[base, base.(DataFlow::PostUpdateNode).getPreUpdateNode()] = v.getAUse() and
26+
exists(Write w, Field f, SsaWithFields v | f.hasQualifiedName("net/url", "URL", "Host") |
27+
w.writesFieldOnSsaWithFields(v, f, node1) and
3128
node2 = v.getAUse()
3229
)
3330
}

go/ql/src/Security/CWE-322/InsecureHostKeyCallback.ql

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,8 @@ predicate hostCheckReachesSink(Flow::PathNode sink) {
9898
Flow::flowPath(source, otherSink) and
9999
Config::writeIsSink(sink.getNode(), sinkWrite) and
100100
Config::writeIsSink(otherSink.getNode(), otherSinkWrite) and
101-
exists(DataFlow::Node base1 |
102-
sinkWrite.writesField(base1, _, sink.getNode()) and
103-
[base1, base1.(DataFlow::PostUpdateNode).getPreUpdateNode()] = sinkAccessPath.getAUse()
104-
) and
105-
exists(DataFlow::Node base2 |
106-
otherSinkWrite.writesField(base2, _, otherSink.getNode()) and
107-
[base2, base2.(DataFlow::PostUpdateNode).getPreUpdateNode()] =
108-
otherSinkAccessPath.getAUse()
109-
) and
101+
sinkWrite.writesFieldOnSsaWithFields(sinkAccessPath, _, sink.getNode()) and
102+
otherSinkWrite.writesFieldOnSsaWithFields(otherSinkAccessPath, _, otherSink.getNode()) and
110103
otherSinkAccessPath = sinkAccessPath.similar()
111104
)
112105
)

go/ql/src/experimental/CWE-918/SSRF.qll

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ module ServerSideRequestForgery {
2222

2323
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
2424
// propagate to a URL when its host is assigned to
25-
exists(Write w, DataFlow::Node base, Field f, SsaWithFields v |
26-
f.hasQualifiedName("net/url", "URL", "Host")
27-
|
28-
w.writesField(base, f, node1) and
29-
[base, base.(DataFlow::PostUpdateNode).getPreUpdateNode()] = v.getAUse() and
25+
exists(Write w, Field f, SsaWithFields v | f.hasQualifiedName("net/url", "URL", "Host") |
26+
w.writesFieldOnSsaWithFields(v, f, node1) and
3027
node2 = v.getAUse()
3128
)
3229
}

0 commit comments

Comments
 (0)