Skip to content

Commit befccac

Browse files
owen-mcaschackmull
authored andcommitted
Convert XSS barrier to MaD
1 parent cec0f73 commit befccac

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

java/ql/lib/ext/hudson.model.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ extensions:
5050
- ["hudson", "FilePath", False, "readToString", "", "", "ReturnValue", "file", "manual"]
5151
- ["hudson", "Plugin", True, "configure", "", "", "Parameter", "remote", "manual"]
5252
- ["hudson", "Plugin", True, "newInstance", "", "", "Parameter", "remote", "manual"]
53+
- addsTo:
54+
pack: codeql/java-all
55+
extensible: barrierModel
56+
data:
57+
- ["hudson", "Util", True, "escape", "(String)", "", "ReturnValue", "html-injection", "manual"]
58+
# Not including xmlEscape because it only accounts for >, <, and &. It does not account for ", or ', which makes it an incomplete XSS sanitizer.
5359
- addsTo:
5460
pack: codeql/java-all
5561
extensible: summaryModel

java/ql/lib/semmle/code/java/frameworks/hudson/Hudson.qll

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,3 @@ class HudsonWebMethod extends Method {
1414
this.getDeclaringType().getASourceSupertype*().hasQualifiedName("hudson.model", "Descriptor")
1515
}
1616
}
17-
18-
private class HudsonUtilXssSanitizer extends XssSanitizer {
19-
HudsonUtilXssSanitizer() {
20-
this.asExpr()
21-
.(MethodCall)
22-
.getMethod()
23-
// Not including xmlEscape because it only accounts for >, <, and &.
24-
// It does not account for ", or ', which makes it an incomplete XSS sanitizer.
25-
.hasQualifiedName("hudson", "Util", "escape")
26-
}
27-
}

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,24 @@ private class DefaultXssSink extends XssSink {
5454
}
5555
}
5656

57-
/** A default sanitizer that considers numeric and boolean typed data safe for writing to output. */
5857
private class DefaultXssSanitizer extends XssSanitizer {
59-
DefaultXssSanitizer() {
58+
DefaultXssSanitizer() { barrierNode(this, ["html-injection", "js-injection"]) }
59+
}
60+
61+
/** A sanitizer that considers numeric and boolean typed data safe for writing to output. */
62+
private class PrimitiveSanitizer extends XssSanitizer {
63+
PrimitiveSanitizer() {
6064
this.getType() instanceof NumericType or
61-
this.getType() instanceof BooleanType or
62-
// Match `org.springframework.web.util.HtmlUtils.htmlEscape` and possibly other methods like it.
65+
this.getType() instanceof BooleanType
66+
}
67+
}
68+
69+
/**
70+
* A call to `org.springframework.web.util.HtmlUtils.htmlEscape`, or possibly
71+
* other methods like it, considered as a sanitizer for XSS.
72+
*/
73+
private class HtmlEscapeXssSanitizer extends XssSanitizer {
74+
HtmlEscapeXssSanitizer() {
6375
this.asExpr().(MethodCall).getMethod().getName().regexpMatch("(?i)html_?escape.*")
6476
}
6577
}

0 commit comments

Comments
 (0)