-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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
40250f0
commit 29ca81d
Showing
2 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
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
88 changes: 88 additions & 0 deletions
88
test/src/test/java/jenkins/security/stapler/Security914Test.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,88 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2018, 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. | ||
*/ | ||
package jenkins.security.stapler; | ||
|
||
import com.gargoylesoftware.htmlunit.Page; | ||
import com.gargoylesoftware.htmlunit.WebRequest; | ||
import hudson.Functions; | ||
import org.junit.Assume; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.Issue; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.TestPluginManager; | ||
|
||
import java.net.URL; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotEquals; | ||
|
||
@Issue("SECURITY-914") | ||
public class Security914Test { | ||
|
||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
@Test | ||
public void cannotUseInvalidLocale_toTraverseFolder() throws Exception { | ||
Assume.assumeTrue(Functions.isWindows()); | ||
|
||
if (j.jenkins.pluginManager.getPlugin("credentials") == null) { | ||
((TestPluginManager) j.jenkins.pluginManager).installDetachedPlugin("credentials"); | ||
} | ||
j.createWebClient().goTo("plugin/credentials/images/24x24/credentials.png", "image/png"); | ||
|
||
JenkinsRule.WebClient wc = j.createWebClient(); | ||
wc.getOptions().setThrowExceptionOnFailingStatusCode(false); | ||
WebRequest request = new WebRequest(new URL(j.getURL() + "plugin/credentials/.xml")); | ||
// plugin deployed in: test\target\jenkins7375296945862059919tmp | ||
// rootDir is in : test\target\jenkinsTests.tmp\jenkins1274934531848159942test | ||
// j.jenkins.getRootDir().getName() = jenkins1274934531848159942test | ||
request.setAdditionalHeader("Accept-Language", "../../../../jenkinsTests.tmp/" + j.jenkins.getRootDir().getName() + "/config"); | ||
|
||
Page p = wc.getPage(request); | ||
assertEquals(p.getWebResponse().getStatusCode(), 404); | ||
assertNotEquals(p.getWebResponse().getContentType(), "application/xml"); | ||
} | ||
|
||
@Test | ||
public void cannotUseInvalidLocale_toAnyFileInSystem() throws Exception { | ||
Assume.assumeTrue(Functions.isWindows()); | ||
|
||
if (j.jenkins.pluginManager.getPlugin("credentials") == null) { | ||
((TestPluginManager) j.jenkins.pluginManager).installDetachedPlugin("credentials"); | ||
} | ||
j.createWebClient().goTo("plugin/credentials/images/24x24/credentials.png", "image/png"); | ||
|
||
JenkinsRule.WebClient wc = j.createWebClient(); | ||
wc.getOptions().setThrowExceptionOnFailingStatusCode(false); | ||
WebRequest request = new WebRequest(new URL(j.getURL() + "plugin/credentials/.ini")); | ||
// ../ can be multiply to infinity, no impact, we just need to have enough to reach the root | ||
request.setAdditionalHeader("Accept-Language", "../../../../../../../../../../../../windows/win"); | ||
|
||
Page p = wc.getPage(request); | ||
assertEquals(p.getWebResponse().getStatusCode(), 404); | ||
assertEquals(p.getWebResponse().getContentType(), "text/html"); | ||
} | ||
} |