Skip to content

Commit

Permalink
[SECURITY-2777]
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-beck authored and jenkinsci-cert-ci committed Jun 9, 2022
1 parent f71495a commit 37bd66a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
1 change: 0 additions & 1 deletion core/src/main/java/hudson/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -2360,7 +2360,6 @@ public static String tryGetIconPath(String iconGuess, JellyContext context) {
}

StaplerRequest currentRequest = Stapler.getCurrentRequest();
currentRequest.getWebApp().getDispatchValidator().allowDispatch(currentRequest, Stapler.getCurrentResponse());
String rootURL = currentRequest.getContextPath();
Icon iconMetadata = tryGetIcon(iconGuess);
String iconSource = null;
Expand Down
50 changes: 50 additions & 0 deletions test/src/test/java/jenkins/security/Security2777Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package jenkins.security;

import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import hudson.model.UnprotectedRootAction;
import java.io.IOException;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestExtension;

public class Security2777Test {
public static final String ACTION_URL = "security2777";

@Rule
public JenkinsRule j = new JenkinsRule();

@Test
public void testView() throws IOException {
final JenkinsRule.WebClient wc = j.createWebClient();

// no exception on action index page
wc.getPage(wc.getContextPath() + ACTION_URL);

final FailingHttpStatusCodeException ex2 = Assert.assertThrows("no icon, no response", FailingHttpStatusCodeException.class, () -> wc.getPage(wc.getContextPath() + ACTION_URL + "/fragmentWithoutIcon"));
Assert.assertEquals("it's 404", 404, ex2.getStatusCode());

final FailingHttpStatusCodeException ex3 = Assert.assertThrows("icon, still no response", FailingHttpStatusCodeException.class, () -> wc.getPage(wc.getContextPath() + ACTION_URL + "/fragmentWithIcon"));
Assert.assertEquals("it's 404", 404, ex3.getStatusCode());
}

@TestExtension
public static class ViewHolder implements UnprotectedRootAction {

@Override
public String getIconFileName() {
return null;
}

@Override
public String getDisplayName() {
return null;
}

@Override
public String getUrlName() {
return ACTION_URL;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout">
<j:new var="h" className="hudson.Functions" />
<l:icon src="lol" />
<h2>Help!</h2>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core">
<h2>Help!</h2>
<p>I'm just HTML!</p>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout">
<l:layout>
<l:main-panel>
<h1>Hello</h1>
</l:main-panel>
</l:layout>
</j:jelly>

0 comments on commit 37bd66a

Please sign in to comment.