Skip to content

Commit ff7be45

Browse files
committed
Remove additional array function. Add 4 tests to UIUtilsSuite.
1 parent 19d6f86 commit ff7be45

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

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

Lines changed: 1 addition & 5 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-
val NEWLINE_AND_SINGLE_QUOTE_REGEX = "(\r\n|\n|\r|%0D%0A|%0A|%0D|'|%27)"
38+
private val NEWLINE_AND_SINGLE_QUOTE_REGEX = "(\r\n|\n|\r|%0D%0A|%0A|%0D|'|%27)"
3939

4040
// SimpleDateFormat is not thread-safe. Don't expose it to avoid improper use.
4141
private val dateFormat = new ThreadLocal[SimpleDateFormat]() {
@@ -546,8 +546,4 @@ private[spark] object UIUtils extends Logging {
546546
StringEscapeUtils.escapeHtml4(
547547
requestParameter.replaceAll(NEWLINE_AND_SINGLE_QUOTE_REGEX, ""))
548548
}
549-
550-
def stripXSSArray(requestParameter: Array[String]): Array[String] = {
551-
requestParameter.map(stripXSS)
552-
}
553549
}

core/src/main/scala/org/apache/spark/ui/jobs/AllJobsPage.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private[ui] class AllJobsPage(parent: JobsTab) extends WebUIPage("") {
221221
jobs: Seq[JobUIData],
222222
killEnabled: Boolean): Seq[Node] = {
223223
// stripXSS is called to remove suspicious characters used in XSS attacks
224-
val allParameters = request.getParameterMap.asScala.toMap.mapValues(UIUtils.stripXSSArray)
224+
val allParameters = request.getParameterMap.asScala.toMap.mapValues(_.map(UIUtils.stripXSS))
225225
val parameterOtherTable = allParameters.filterNot(_._1.startsWith(jobTag))
226226
.map(para => para._1 + "=" + para._2(0))
227227

core/src/main/scala/org/apache/spark/ui/jobs/StageTable.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private[ui] class StageTableBase(
4343
killEnabled: Boolean,
4444
isFailedStage: Boolean) {
4545
// stripXSS is called to remove suspicious characters used in XSS attacks
46-
val allParameters = request.getParameterMap.asScala.toMap.mapValues(UIUtils.stripXSSArray)
46+
val allParameters = request.getParameterMap.asScala.toMap.mapValues(_.map(UIUtils.stripXSS))
4747
val parameterOtherTable = allParameters.filterNot(_._1.startsWith(stageTag))
4848
.map(para => para._1 + "=" + para._2(0))
4949

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

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

136+
test("SPARK-20393: Prevent script from parameters running on page.") {
137+
val scriptAlert = """>"'><script>alert(401)<%2Fscript>"""
138+
val stripScriptAlert = "&gt;&quot;&gt;&lt;script&gt;alert(401)&lt;%2Fscript&gt;"
139+
140+
assert(stripScriptAlert === stripXSS(scriptAlert))
141+
}
142+
143+
test("SPARK-20393: Prevent javascript from parameters running on page.") {
144+
val javascriptAlert =
145+
"""app-20161208133404-0002<iframe+src%3Djavascript%3Aalert(1705)>"""
146+
val stripJavascriptAlert =
147+
"app-20161208133404-0002&lt;iframe+src%3Djavascript%3Aalert(1705)&gt;"
148+
149+
assert(stripJavascriptAlert === stripXSS(javascriptAlert))
150+
}
151+
152+
test("SPARK-20393: Prevent links from parameters on page.") {
153+
val link =
154+
"""stdout'"><iframe+id%3D1131+src%3Dhttp%3A%2F%2Fdemo.testfire.net%2Fphishing.html>"""
155+
val stripLink =
156+
"stdout&quot;&gt;&lt;iframe+id%3D1131+src%3Dhttp%3A%2F%2Fdemo.testfire.net%2Fphishing.html&gt;"
157+
158+
assert(stripLink === stripXSS(link))
159+
}
160+
161+
test("SPARK-20393: Prevent popups from parameters on page.") {
162+
val popup = """stdout'%2Balert(60)%2B'"""
163+
val stripPopup = "stdout%2Balert(60)%2B"
164+
165+
assert(stripPopup === stripXSS(popup))
166+
}
167+
136168
private def verify(
137169
desc: String,
138170
expected: Node,

0 commit comments

Comments
 (0)