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

Skip to content

Commit 39762da

Browse files
committed
Make DsnInjection use new API
1 parent a53da37 commit 39762da

3 files changed

Lines changed: 27 additions & 10 deletions

File tree

go/ql/src/experimental/CWE-74/DsnInjection.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
*/
1111

1212
import go
13-
import DataFlow::PathGraph
1413
import DsnInjectionCustomizations
14+
import DsnInjectionFlow::PathGraph
1515

1616
/** An untrusted flow source taken as a source for the `DsnInjection` taint-flow configuration. */
1717
private class UntrustedFlowAsSource extends Source instanceof UntrustedFlowSource { }
1818

19-
from DsnInjection cfg, DataFlow::PathNode source, DataFlow::PathNode sink
20-
where cfg.hasFlowPath(source, sink)
19+
from DsnInjectionFlow::PathNode source, DsnInjectionFlow::PathNode sink
20+
where DsnInjectionFlow::flowPath(source, sink)
2121
select sink.getNode(), source, sink, "Data-Source Name is built using $@.", source.getNode(),
2222
"untrusted user input"

go/ql/src/experimental/CWE-74/DsnInjectionCustomizations.qll

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
/** Provides a taint-tracking model to reason about Data-Source name injection vulnerabilities. */
22

33
import go
4-
import DataFlow::PathGraph
54
import semmle.go.dataflow.barrierguardutil.RegexpCheck
65

76
/** A source for `DsnInjection` taint-flow configuration. */
87
abstract class Source extends DataFlow::Node { }
98

10-
/** A taint-tracking configuration to reason about Data Source Name injection vulnerabilities. */
11-
class DsnInjection extends TaintTracking::Configuration {
9+
/**
10+
* DEPRECATED: Use `DsnInjectionFlow` instead.
11+
*
12+
* A taint-tracking configuration to reason about Data Source Name injection vulnerabilities.
13+
*/
14+
deprecated class DsnInjection extends TaintTracking::Configuration {
1215
DsnInjection() { this = "DsnInjection" }
1316

1417
override predicate isSource(DataFlow::Node node) { node instanceof Source }
@@ -25,6 +28,20 @@ class DsnInjection extends TaintTracking::Configuration {
2528
override predicate isSanitizer(DataFlow::Node node) { node instanceof RegexpCheckBarrier }
2629
}
2730

31+
private module DsnInjectionConfig implements DataFlow::ConfigSig {
32+
predicate isSource(DataFlow::Node source) { source instanceof Source }
33+
34+
predicate isSink(DataFlow::Node sink) {
35+
exists(Function f | f.hasQualifiedName("database/sql", "Open") |
36+
sink = f.getACall().getArgument(1)
37+
)
38+
}
39+
40+
predicate isBarrier(DataFlow::Node node) { node instanceof RegexpCheckBarrier }
41+
}
42+
43+
module DsnInjectionFlow = TaintTracking::Global<DsnInjectionConfig>;
44+
2845
/** A model of a function which decodes or unmarshals a tainted input, propagating taint from any argument to either the method receiver or return value. */
2946
private class DecodeFunctionModel extends TaintTracking::FunctionModel {
3047
DecodeFunctionModel() {

go/ql/src/experimental/CWE-74/DsnInjectionLocal.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
*/
1111

1212
import go
13-
import DataFlow::PathGraph
1413
import DsnInjectionCustomizations
14+
import DsnInjectionFlow::PathGraph
1515

16-
/** An argument passed via the command line taken as a source for the `DsnInjection` taint-flow configuration. */
16+
/** An argument passed via the command line taken as a source for the `DsnInjectionFlow` taint-flow. */
1717
private class OsArgsSource extends Source {
1818
OsArgsSource() { this = any(Variable c | c.hasQualifiedName("os", "Args")).getARead() }
1919
}
2020

21-
from DsnInjection cfg, DataFlow::PathNode source, DataFlow::PathNode sink
22-
where cfg.hasFlowPath(source, sink)
21+
from DsnInjectionFlow::PathNode source, DsnInjectionFlow::PathNode sink
22+
where DsnInjectionFlow::flowPath(source, sink)
2323
select sink.getNode(), source, sink, "This query depends on a $@.", source.getNode(),
2424
"user-provided value"

0 commit comments

Comments
 (0)