mirror of
https://github.com/github/codeql.git
synced 2025-12-18 01:33:15 +01:00
Python: Require quote escaping for html.escape
This commit is contained in:
@@ -4851,7 +4851,19 @@ module StdlibPrivate {
|
||||
* See https://docs.python.org/3/library/html.html#html.escape
|
||||
*/
|
||||
private class HtmlEscapeCall extends Escaping::Range, API::CallNode {
|
||||
HtmlEscapeCall() { this = API::moduleImport("html").getMember("escape").getACall() }
|
||||
HtmlEscapeCall() {
|
||||
this = API::moduleImport("html").getMember("escape").getACall() and
|
||||
// if quote escaping is disabled, that might lead to XSS if the result is inserted
|
||||
// in the attribute value of a tag, such as `<foo bar="escape_result">`. Since we
|
||||
// don't know how values are being inserted, and we don't want to lose these
|
||||
// results (FNs), we require quote escaping to be enabled. This might lead to some
|
||||
// FPs, so we might need to revisit this in the future.
|
||||
not this.getParameter(1, "quote")
|
||||
.getAValueReachingSink()
|
||||
.asExpr()
|
||||
.(ImmutableLiteral)
|
||||
.booleanValue() = false
|
||||
}
|
||||
|
||||
override DataFlow::Node getAnInput() { result = this.getParameter(0, "s").asSink() }
|
||||
|
||||
|
||||
@@ -4,5 +4,6 @@ s = "tainted"
|
||||
|
||||
html.escape(s) # $ escapeInput=s escapeKind=html escapeOutput=html.escape(..)
|
||||
html.escape(s, True) # $ escapeInput=s escapeKind=html escapeOutput=html.escape(..)
|
||||
html.escape(s, False) # $ escapeInput=s escapeKind=html escapeOutput=html.escape(..)
|
||||
html.escape(s, quote=False) # $ escapeInput=s escapeKind=html escapeOutput=html.escape(..)
|
||||
# not considered html escapes, since they don't escape all relevant characters
|
||||
html.escape(s, False)
|
||||
html.escape(s, quote=False)
|
||||
|
||||
Reference in New Issue
Block a user