Skip to content

Commit 20a3211

Browse files
committed
move sanitizers from sharedxss::sanitizer to EscapeFunction::Range, added proper inline tests
1 parent 3e0ed00 commit 20a3211

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,20 @@ module Fasthttp {
148148
/**
149149
* A function that can be used as a sanitizer for XSS.
150150
*/
151-
class HtmlQuoteSanitizer extends SharedXss::Sanitizer {
151+
class HtmlQuoteSanitizer extends EscapeFunction::Range {
152+
boolean isHTMLEscape;
153+
152154
HtmlQuoteSanitizer() {
153-
exists(DataFlow::CallNode c |
154-
c.getTarget()
155-
.hasQualifiedName(packagePath(),
156-
["AppendHTMLEscape", "AppendHTMLEscapeBytes", "AppendQuotedArg"])
157-
|
158-
this = c.getArgument(1)
159-
)
155+
this.hasQualifiedName(packagePath(), ["AppendHTMLEscape", "AppendHTMLEscapeBytes"]) and
156+
isHTMLEscape = true
157+
or
158+
this.hasQualifiedName(packagePath(), "AppendQuotedArg") and isHTMLEscape = false
159+
}
160+
161+
override string kind() {
162+
isHTMLEscape = true and result = "html"
163+
or
164+
isHTMLEscape = false and result = "url"
160165
}
161166
}
162167

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
testFailures
2+
failures
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import go
2+
import TestUtilities.InlineExpectationsTest
3+
4+
module FasthttpTest implements TestSig {
5+
string getARelevantTag() { result = "Sanitizer" }
6+
7+
predicate hasActualResult(Location location, string element, string tag, string value) {
8+
exists(EscapeFunction ef, DataFlow::CallNode cn | cn = ef.getACall() |
9+
cn.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(),
10+
location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and
11+
element = cn.getArgument(1).toString() and
12+
value = cn.getArgument(1).toString() and
13+
tag = "Sanitizer"
14+
)
15+
}
16+
}
17+
18+
import MakeTest<FasthttpTest>

0 commit comments

Comments
 (0)