-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c8d014
commit df600eb
Showing
3 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
test/src/test/java/lib/form/ExpandableTextboxSEC1498Test.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package lib.form; | ||
|
||
import com.gargoylesoftware.htmlunit.html.HtmlElementUtil; | ||
import com.gargoylesoftware.htmlunit.html.HtmlInput; | ||
import com.gargoylesoftware.htmlunit.html.HtmlPage; | ||
import hudson.model.FreeStyleProject; | ||
import hudson.model.Job; | ||
import jenkins.model.OptionalJobProperty; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.TestExtension; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
//TODO meant to be merged back into ExpandableTextboxTest after security release to avoid conflict during the upmerge process | ||
public class ExpandableTextboxSEC1498Test { | ||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
@Test | ||
public void noXssUsingInputValue() throws Exception { | ||
XssProperty xssProperty = new XssProperty("</textarea><h1>HACK</h1>"); | ||
FreeStyleProject p = j.createFreeStyleProject(); | ||
p.addProperty(xssProperty); | ||
|
||
JenkinsRule.WebClient wc = j.createWebClient(); | ||
HtmlPage configurePage = wc.getPage(p, "configure"); | ||
|
||
int numberOfH1Before = configurePage.getElementsByTagName("h1").size(); | ||
|
||
HtmlInput xssInput = configurePage.getElementByName("_.xss"); | ||
HtmlInput expandButton = (HtmlInput) xssInput.getParentNode().getNextSibling().getFirstChild(); | ||
HtmlElementUtil.click(expandButton); | ||
|
||
// no additional h1, meaning the "payload" is not interpreted | ||
int numberOfH1After = configurePage.getElementsByTagName("h1").size(); | ||
|
||
assertEquals(numberOfH1Before, numberOfH1After); | ||
} | ||
|
||
public static final class XssProperty extends OptionalJobProperty<Job<?,?>> { | ||
|
||
private String xss; | ||
|
||
public XssProperty(String xss){ | ||
this.xss = xss; | ||
} | ||
|
||
public String getXss() { | ||
return xss; | ||
} | ||
|
||
@TestExtension("noXssUsingInputValue") | ||
public static class DescriptorImpl extends OptionalJobProperty.OptionalJobPropertyDescriptor { | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...src/test/resources/lib/form/ExpandableTextboxSEC1498Test/XssProperty/config-details.jelly
This file contains 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!-- | ||
The MIT License | ||
Copyright (c) 2019, CloudBees, Inc. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
--> | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form"> | ||
<f:entry field="xss"> | ||
<f:expandableTextbox /> | ||
</f:entry> | ||
</j:jelly> |
This file contains 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