-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-20393][Webu UI] Strengthen Spark to prevent XSS vulnerabilities #17686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6bdc629
UIUtils.stripXSS added for each page calling request.getParameter.
n-marion c812f2e
Perform stripXSS on creation of allParameters mapping
n-marion 06a6791
getParameterMap returns Array[String], created new function to handle
n-marion d50c0c2
Clean up method. Change variable names. Add space in comment to match…
n-marion 19d6f86
Cleanup stripXSS and remove redundant (_)
n-marion ff7be45
Remove additional array function. Add 4 tests to UIUtilsSuite.
n-marion 18dbd6f
Change to regex, add case-insensitivity to regex, create new testcase…
n-marion 39824a8
Fix Scalastyle errors.
n-marion ef1cc25
ScalaStyle fix for imports on UIUtils.
n-marion 8ed9c76
Fix scalastyle for new tests.
n-marion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,13 +27,16 @@ import scala.xml.transform.{RewriteRule, RuleTransformer} | |
|
|
||
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.ui.scope.RDDOperationGraph | ||
| import org.apache.commons.lang3.StringEscapeUtils | ||
|
|
||
| /** Utility functions for generating XML pages with spark content. */ | ||
| private[spark] object UIUtils extends Logging { | ||
| val TABLE_CLASS_NOT_STRIPED = "table table-bordered table-condensed" | ||
| val TABLE_CLASS_STRIPED = TABLE_CLASS_NOT_STRIPED + " table-striped" | ||
| val TABLE_CLASS_STRIPED_SORTABLE = TABLE_CLASS_STRIPED + " sortable" | ||
|
|
||
| private val NEWLINE_AND_SINGLE_QUOTE_REGEX = "(\r\n|\n|\r|%0D%0A|%0A|%0D|'|%27)" | ||
|
|
||
| // SimpleDateFormat is not thread-safe. Don't expose it to avoid improper use. | ||
| private val dateFormat = new ThreadLocal[SimpleDateFormat]() { | ||
| override def initialValue(): SimpleDateFormat = | ||
|
|
@@ -527,4 +530,20 @@ private[spark] object UIUtils extends Logging { | |
| origHref | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Remove suspicious characters of user input to prevent Cross-Site scripting (XSS) attacks | ||
| * | ||
| * For more information about XSS testing: | ||
| * https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet and | ||
| * https://www.owasp.org/index.php/Testing_for_Reflected_Cross_site_scripting_(OTG-INPVAL-001) | ||
| */ | ||
| def stripXSS(requestParameter: String): String = { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you would, add a couple brief tests of this to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll work on some. |
||
| if (requestParameter == null) { | ||
| null | ||
| } else { | ||
| // Remove new lines and single quotes, followed by escaping HTML version 4.0 | ||
| StringEscapeUtils.escapeHtml4( | ||
| requestParameter.replaceAll(NEWLINE_AND_SINGLE_QUOTE_REGEX, "")) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think it's worth making this a regex object if you're going to bother, but otherwise LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will attempt. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regex created. Changed replaceAll string method to replaceAllIn regex method. Added new test case for new line in parameter.