Skip to content

Commit cbed6e8

Browse files
committed
Python: Add html.escape as HTML sanitizer
1 parent 6533269 commit cbed6e8

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

python/ql/lib/semmle/python/frameworks/Stdlib.qll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4842,6 +4842,23 @@ module StdlibPrivate {
48424842
override predicate isShellInterpreted(DataFlow::Node arg) { arg = this.getCommand() }
48434843
}
48444844
}
4845+
4846+
// ---------------------------------------------------------------------------
4847+
// html
4848+
// ---------------------------------------------------------------------------
4849+
/**
4850+
* A call to 'html.escape'.
4851+
* See https://docs.python.org/3/library/html.html#html.escape
4852+
*/
4853+
private class HtmlEscapeCall extends Escaping::Range, API::CallNode {
4854+
HtmlEscapeCall() { this = API::moduleImport("html").getMember("escape").getACall() }
4855+
4856+
override DataFlow::Node getAnInput() { result = this.getParameter(0, "s").asSink() }
4857+
4858+
override DataFlow::Node getOutput() { result = this }
4859+
4860+
override string getKind() { result = Escaping::getHtmlKind() }
4861+
}
48454862
}
48464863

48474864
// ---------------------------------------------------------------------------
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import html
2+
3+
s = "tainted"
4+
5+
html.escape(s) # $ escapeInput=s escapeKind=html escapeOutput=html.escape(..)
6+
html.escape(s, True) # $ escapeInput=s escapeKind=html escapeOutput=html.escape(..)
7+
html.escape(s, False) # $ escapeInput=s escapeKind=html escapeOutput=html.escape(..)
8+
html.escape(s, quote=False) # $ escapeInput=s escapeKind=html escapeOutput=html.escape(..)

0 commit comments

Comments
 (0)