Skip to content

Commit

Permalink
[SECURITY-914]
Browse files Browse the repository at this point in the history
  • Loading branch information
Wadeck authored and daniel-beck committed Jun 19, 2018
1 parent 40250f0 commit 29ca81d
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ THE SOFTWARE.

<properties>
<staplerFork>true</staplerFork>
<stapler.version>1.250</stapler.version>
<stapler.version>1.250.1</stapler.version>
<spring.version>2.5.6.SEC03</spring.version>
<groovy.version>2.4.11</groovy.version>
<!-- TODO: Actually many issues are being filtered by src/findbugs/findbugs-excludes.xml -->
Expand Down
88 changes: 88 additions & 0 deletions test/src/test/java/jenkins/security/stapler/Security914Test.java
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");
}
}

0 comments on commit 29ca81d

Please sign in to comment.