Skip to content

Commit 18dbd6f

Browse files
committed
Change to regex, add case-insensitivity to regex, create new testcase for newline in parameter.
1 parent ff7be45 commit 18dbd6f

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

core/src/main/scala/org/apache/spark/ui/UIUtils.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private[spark] object UIUtils extends Logging {
3535
val TABLE_CLASS_STRIPED = TABLE_CLASS_NOT_STRIPED + " table-striped"
3636
val TABLE_CLASS_STRIPED_SORTABLE = TABLE_CLASS_STRIPED + " sortable"
3737

38-
private val NEWLINE_AND_SINGLE_QUOTE_REGEX = "(\r\n|\n|\r|%0D%0A|%0A|%0D|'|%27)"
38+
private val NEWLINE_AND_SINGLE_QUOTE_REGEX = raw"(?i)(\r\n|\n|\r|%0D%0A|%0A|%0D|'|%27)".r
3939

4040
// SimpleDateFormat is not thread-safe. Don't expose it to avoid improper use.
4141
private val dateFormat = new ThreadLocal[SimpleDateFormat]() {
@@ -544,6 +544,6 @@ private[spark] object UIUtils extends Logging {
544544
} else {
545545
// Remove new lines and single quotes, followed by escaping HTML version 4.0
546546
StringEscapeUtils.escapeHtml4(
547-
requestParameter.replaceAll(NEWLINE_AND_SINGLE_QUOTE_REGEX, ""))
547+
NEWLINE_AND_SINGLE_QUOTE_REGEX.replaceAllIn(requestParameter, ""))
548548
}
549549
}

core/src/test/scala/org/apache/spark/ui/UIUtilsSuite.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ class UIUtilsSuite extends SparkFunSuite {
133133
assert(decoded2 === decodeURLParameter(decoded2))
134134
}
135135

136+
test("SPARK-20393: Prevent newline characters in parameters.") {
137+
val encoding = "Encoding:base64%0d%0a%0d%0aPGh0bWw%2bjcmlwdD48L2h0bWw%2b"
138+
val stripEncoding = "Encoding:base64PGh0bWw%2bjcmlwdD48L2h0bWw%2b"
139+
140+
assert(stripEncoding === stripXSS(encoding))
141+
}
142+
136143
test("SPARK-20393: Prevent script from parameters running on page.") {
137144
val scriptAlert = """>"'><script>alert(401)<%2Fscript>"""
138145
val stripScriptAlert = "&gt;&quot;&gt;&lt;script&gt;alert(401)&lt;%2Fscript&gt;"

0 commit comments

Comments
 (0)