Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 4f3854c

Browse files
author
Sauyon Lee
committed
ReflectedXSS: Ignore whitespace for HTML content type detection
1 parent 1853e99 commit 4f3854c

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

ql/src/semmle/go/security/ReflectedXssCustomizations.qll

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,18 @@ module ReflectedXss {
6464
or
6565
exists(DataFlow::CallNode call | call.getTarget().hasQualifiedName("fmt", "Fprintf") |
6666
body = call.getAnArgument() and
67-
// checks that the format value does not start with:
67+
// checks that the format value does not start with (ignoring whitespace as defined by
68+
// https://mimesniff.spec.whatwg.org/#whitespace-byte):
6869
// - '<', which could lead to an HTML content type being detected, or
6970
// - '%', which could be a format string.
70-
call.getArgument(1).getStringValue().regexpMatch("(?s)^[^<%].*")
71+
call.getArgument(1).getStringValue().regexpMatch("(?s)[\\t\\n\\x0c\\r ]*+[^<%].*")
7172
)
7273
or
7374
exists(DataFlow::Node pred | body = pred.getASuccessor*() |
74-
// data starting with a character other than `<` cannot cause an HTML content type to be detected.
75-
pred.getStringValue().regexpMatch("(?s)^[^<].*")
75+
// data starting with a character other than `<` (ignoring whitespace as defined by
76+
// https://mimesniff.spec.whatwg.org/#whitespace-byte) cannot cause an HTML content type to
77+
// be detected.
78+
pred.getStringValue().regexpMatch("(?s)[\\t\\n\\x0c\\r ]*+[^<].*")
7679
or
7780
// json data cannot begin with `<`
7881
exists(EncodingJson::MarshalFunction mf | pred = mf.getOutput().getNode(mf.getACall()))

0 commit comments

Comments
 (0)