Allow non-query-specific MaD sanitizers

This commit is contained in:
Owen Mansel-Chan
2025-12-16 17:10:08 +00:00
parent 1fbc28b753
commit 1e6410804f
11 changed files with 46 additions and 0 deletions

View File

@@ -29,6 +29,12 @@ module XPath {
DefaultXPathExpressionString() { sinkNode(this, "xpath-injection") }
}
}
abstract class Sanitizer extends DataFlow::Node { }
private class ExternalSanitizer extends Sanitizer {
ExternalSanitizer() { barrierNode(this, "xpath-injection") }
}
}
/**

View File

@@ -47,6 +47,10 @@ module CommandInjection {
override predicate doubleDashIsSanitizing() { exec.doubleDashIsSanitizing() }
}
private class ExternalSanitizer extends Sanitizer {
ExternalSanitizer() { barrierNode(this, "command-injection") }
}
/**
* A call to a regexp match function, considered as a barrier guard for command injection.
*/

View File

@@ -47,6 +47,13 @@ module HardcodedCredentials {
CredentialsSink() { exists(string s | s.matches("credentials-%") | sinkNode(this, s)) }
}
/** A use of a credential. */
private class ExternalCredentialsSanitizer extends Sanitizer {
ExternalCredentialsSanitizer() {
exists(string s | s.matches("credentials-%") | barrierNode(this, s))
}
}
/**
* Holds if the guard `g` in its branch `branch` validates the expression `e`
* by comparing it to a literal.

View File

@@ -20,6 +20,8 @@ module MissingJwtSignatureCheck {
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
any(AdditionalFlowStep s).step(nodeFrom, nodeTo)
}

View File

@@ -54,4 +54,8 @@ module MissingJwtSignatureCheck {
private class DefaultSink extends Sink {
DefaultSink() { sinkNode(this, "jwt") }
}
private class ExternalSanitizer extends Sanitizer {
ExternalSanitizer() { barrierNode(this, "jwt") }
}
}

View File

@@ -75,6 +75,10 @@ module OpenUrlRedirect {
}
}
private class ExternalBarrier extends Barrier {
ExternalBarrier() { barrierNode(this, "url-redirection") }
}
/**
* An assignment of a safe value to the field `Path`, considered as a barrier for sanitizing
* untrusted URLs.

View File

@@ -94,6 +94,10 @@ module RequestForgery {
HostnameSanitizer() { hostnameSanitizingPrefixEdge(this, _) }
}
private class ExternalRequestForgerySanitizer extends Sanitizer {
ExternalRequestForgerySanitizer() { barrierNode(this, "request-forgery") }
}
/**
* A call to a function called `isLocalUrl`, `isValidRedirect`, or similar, which is
* considered a barrier guard.

View File

@@ -43,6 +43,10 @@ module SqlInjection {
/** DEPRECATED: Use `SimpleTypeSanitizer` from semmle.go.security.Sanitizers instead. */
deprecated class NumericOrBooleanSanitizer = SimpleTypeSanitizer;
private class ExternalSanitizer extends Sanitizer {
ExternalSanitizer() { barrierNode(this, ["nosql-injection", "sql-injection"]) }
}
/**
* A numeric- or boolean-typed node, considered a sanitizer for sql injection.
*/

View File

@@ -57,6 +57,10 @@ module TaintedPath {
PathAsSink() { this = any(FileSystemAccess fsa).getAPathArgument() }
}
private class ExternalSanitizer extends Sanitizer {
ExternalSanitizer() { barrierNode(this, "path-injection") }
}
/**
* A numeric- or boolean-typed node, considered a sanitizer for path traversal.
*/

View File

@@ -34,4 +34,7 @@ module XPathInjection {
/** An XPath expression string, considered as a taint sink for XPath injection. */
class XPathExpressionStringAsSink extends Sink instanceof XPath::XPathExpressionString { }
/** An XPath expression string, considered as a taint sink for XPath injection. */
class XPathSanitizer extends Sanitizer instanceof XPath::Sanitizer { }
}

View File

@@ -88,6 +88,10 @@ module SharedXss {
body.getAContentType().regexpMatch("(?i).*html.*")
}
private class ExternalSanitizer extends Sanitizer {
ExternalSanitizer() { barrierNode(this, ["html-injection", "js-injection"]) }
}
/**
* A JSON marshaler, acting to sanitize a possible XSS vulnerability because the
* marshaled value is very unlikely to be returned as an HTML content-type.