Skip to content

Commit 1071421

Browse files
committed
Add utility functions definining XSS-vulnerable content-types
1 parent 450eebc commit 1071421

File tree

1 file changed

+17
-0
lines changed
  • java/ql/src/semmle/code/java/security

1 file changed

+17
-0
lines changed

java/ql/src/semmle/code/java/security/XSS.qll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,20 @@ class ServletWriterSource extends MethodAccess {
150150
)
151151
}
152152
}
153+
154+
/**
155+
* Holds if `s` is an HTTP Content-Type vulnerable to XSS.
156+
*/
157+
bindingset[s]
158+
predicate isXssVulnerableContentType(string s) {
159+
s.regexpMatch("(?i)text/(html|xml|xsl|rdf|vtt|cache-manifest).*") or
160+
s.regexpMatch("(?i)application/(.*\\+)?xml.*") or
161+
s.regexpMatch("(?i)cache-manifest.*") or
162+
s.regexpMatch("(?i)image/svg\\+xml.*")
163+
}
164+
165+
/**
166+
* Holds if `s` is an HTTP Content-Type that is not vulnerable to XSS.
167+
*/
168+
bindingset[s]
169+
predicate isXssSafeContentType(string s) { not isXssVulnerableContentType(s) }

0 commit comments

Comments
 (0)