Skip to content

Commit 1e64108

Browse files
committed
Allow non-query-specific MaD sanitizers
1 parent 1fbc28b commit 1e64108

11 files changed

+46
-0
lines changed

go/ql/lib/semmle/go/frameworks/XPath.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ module XPath {
2929
DefaultXPathExpressionString() { sinkNode(this, "xpath-injection") }
3030
}
3131
}
32+
33+
abstract class Sanitizer extends DataFlow::Node { }
34+
35+
private class ExternalSanitizer extends Sanitizer {
36+
ExternalSanitizer() { barrierNode(this, "xpath-injection") }
37+
}
3238
}
3339

3440
/**

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ module CommandInjection {
4747
override predicate doubleDashIsSanitizing() { exec.doubleDashIsSanitizing() }
4848
}
4949

50+
private class ExternalSanitizer extends Sanitizer {
51+
ExternalSanitizer() { barrierNode(this, "command-injection") }
52+
}
53+
5054
/**
5155
* A call to a regexp match function, considered as a barrier guard for command injection.
5256
*/

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ module HardcodedCredentials {
4747
CredentialsSink() { exists(string s | s.matches("credentials-%") | sinkNode(this, s)) }
4848
}
4949

50+
/** A use of a credential. */
51+
private class ExternalCredentialsSanitizer extends Sanitizer {
52+
ExternalCredentialsSanitizer() {
53+
exists(string s | s.matches("credentials-%") | barrierNode(this, s))
54+
}
55+
}
56+
5057
/**
5158
* Holds if the guard `g` in its branch `branch` validates the expression `e`
5259
* by comparing it to a literal.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ module MissingJwtSignatureCheck {
2020

2121
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
2222

23+
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
24+
2325
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
2426
any(AdditionalFlowStep s).step(nodeFrom, nodeTo)
2527
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,8 @@ module MissingJwtSignatureCheck {
5454
private class DefaultSink extends Sink {
5555
DefaultSink() { sinkNode(this, "jwt") }
5656
}
57+
58+
private class ExternalSanitizer extends Sanitizer {
59+
ExternalSanitizer() { barrierNode(this, "jwt") }
60+
}
5761
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ module OpenUrlRedirect {
7575
}
7676
}
7777

78+
private class ExternalBarrier extends Barrier {
79+
ExternalBarrier() { barrierNode(this, "url-redirection") }
80+
}
81+
7882
/**
7983
* An assignment of a safe value to the field `Path`, considered as a barrier for sanitizing
8084
* untrusted URLs.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ module RequestForgery {
9494
HostnameSanitizer() { hostnameSanitizingPrefixEdge(this, _) }
9595
}
9696

97+
private class ExternalRequestForgerySanitizer extends Sanitizer {
98+
ExternalRequestForgerySanitizer() { barrierNode(this, "request-forgery") }
99+
}
100+
97101
/**
98102
* A call to a function called `isLocalUrl`, `isValidRedirect`, or similar, which is
99103
* considered a barrier guard.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ module SqlInjection {
4343
/** DEPRECATED: Use `SimpleTypeSanitizer` from semmle.go.security.Sanitizers instead. */
4444
deprecated class NumericOrBooleanSanitizer = SimpleTypeSanitizer;
4545

46+
private class ExternalSanitizer extends Sanitizer {
47+
ExternalSanitizer() { barrierNode(this, ["nosql-injection", "sql-injection"]) }
48+
}
49+
4650
/**
4751
* A numeric- or boolean-typed node, considered a sanitizer for sql injection.
4852
*/

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ module TaintedPath {
5757
PathAsSink() { this = any(FileSystemAccess fsa).getAPathArgument() }
5858
}
5959

60+
private class ExternalSanitizer extends Sanitizer {
61+
ExternalSanitizer() { barrierNode(this, "path-injection") }
62+
}
63+
6064
/**
6165
* A numeric- or boolean-typed node, considered a sanitizer for path traversal.
6266
*/

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ module XPathInjection {
3434

3535
/** An XPath expression string, considered as a taint sink for XPath injection. */
3636
class XPathExpressionStringAsSink extends Sink instanceof XPath::XPathExpressionString { }
37+
38+
/** An XPath expression string, considered as a taint sink for XPath injection. */
39+
class XPathSanitizer extends Sanitizer instanceof XPath::Sanitizer { }
3740
}

0 commit comments

Comments
 (0)