Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d2a5d19

Browse files
committed
Make SafeUrlFlow use new API
1 parent 97c3297 commit d2a5d19

3 files changed

Lines changed: 31 additions & 8 deletions

File tree

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ module SafeUrlFlow {
1717
import SafeUrlFlowCustomizations::SafeUrlFlow
1818

1919
/**
20+
* DEPRECATED: Use `Flow` instead.
21+
*
2022
* A taint-tracking configuration for reasoning about safe URLs.
2123
*/
22-
class Configuration extends TaintTracking::Configuration {
24+
deprecated class Configuration extends TaintTracking::Configuration {
2325
Configuration() { this = "SafeUrlFlow" }
2426

2527
override predicate isSource(DataFlow::Node source) { source instanceof Source }
@@ -42,4 +44,28 @@ module SafeUrlFlow {
4244
node instanceof SanitizerEdge
4345
}
4446
}
47+
48+
private module Config implements DataFlow::ConfigSig {
49+
predicate isSource(DataFlow::Node source) { source instanceof Source }
50+
51+
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
52+
53+
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
54+
// propagate to a URL when its host is assigned to
55+
exists(Write w, Field f, SsaWithFields v | f.hasQualifiedName("net/url", "URL", "Host") |
56+
w.writesField(v.getAUse(), f, node1) and node2 = v.getAUse()
57+
)
58+
}
59+
60+
predicate isBarrierOut(DataFlow::Node node) {
61+
// block propagation of this safe value when its host is overwritten
62+
exists(Write w, Field f | f.hasQualifiedName("net/url", "URL", "Host") |
63+
w.writesField(node.getASuccessor(), f, _)
64+
)
65+
or
66+
node instanceof SanitizerEdge
67+
}
68+
}
69+
70+
module Flow = TaintTracking::Global<Config>;
4571
}

go/ql/src/Security/CWE-601/OpenUrlRedirect.ql

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ import semmle.go.security.OpenUrlRedirect::OpenUrlRedirect
1616
import semmle.go.security.SafeUrlFlow
1717
import DataFlow::PathGraph
1818

19-
from
20-
Configuration cfg, SafeUrlFlow::Configuration scfg, DataFlow::PathNode source,
21-
DataFlow::PathNode sink
19+
from Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
2220
where
2321
cfg.hasFlowPath(source, sink) and
2422
// this excludes flow from safe parts of request URLs, for example the full URL when the
2523
// doing a redirect from `http://<path>` to `https://<path>`
26-
not scfg.hasFlow(_, sink.getNode())
24+
not SafeUrlFlow::Flow::flow(_, sink.getNode())
2725
select sink.getNode(), source, sink, "This path to an untrusted URL redirection depends on a $@.",
2826
source.getNode(), "user-provided value"

go/ql/src/Security/CWE-918/RequestForgery.ql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ import semmle.go.security.SafeUrlFlow
1616
import RequestForgery::Flow::PathGraph
1717

1818
from
19-
SafeUrlFlow::Configuration scfg, RequestForgery::Flow::PathNode source,
20-
RequestForgery::Flow::PathNode sink, DataFlow::Node request
19+
RequestForgery::Flow::PathNode source, RequestForgery::Flow::PathNode sink, DataFlow::Node request
2120
where
2221
RequestForgery::Flow::flowPath(source, sink) and
2322
request = sink.getNode().(RequestForgery::Sink).getARequest() and
2423
// this excludes flow from safe parts of request URLs, for example the full URL
25-
not scfg.hasFlow(_, sink.getNode())
24+
not SafeUrlFlow::Flow::flow(_, sink.getNode())
2625
select request, source, sink, "The $@ of this request depends on a $@.", sink.getNode(),
2726
sink.getNode().(RequestForgery::Sink).getKind(), source, "user-provided value"

0 commit comments

Comments
 (0)