Skip to content

Commit

Permalink
[SECURITY-3498]
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-beck authored and jenkinsci-cert-ci committed Feb 25, 2025
1 parent 68425e2 commit 84ef1a4
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions core/src/main/java/jenkins/model/Jenkins.java
Original file line number Diff line number Diff line change
Expand Up @@ -4165,6 +4165,7 @@ public synchronized HttpRedirect doCancelQuietDown() {
return new HttpRedirect(".");
}

@POST
public HttpResponse doToggleCollapse() throws ServletException, IOException {
final StaplerRequest2 request = Stapler.getCurrentRequest2();
final String paneId = request.getParameter("paneId");
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/resources/lib/hudson/executors.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ THE SOFTWARE.
${executorDetails}
</span>
</j:if>
<a class="collapse" href="${rootURL}/toggleCollapse?paneId=executors"
<st:adjunct includes="lib.form.link.link"/>
<!-- TODO improve l:link so the `a` can be changed to `l:link`. -->
<a class="collapse post" href="${rootURL}/toggleCollapse?paneId=executors"
tooltip="${paneIsCollapsed ? '%Expand' : '%Collapse'}" data-tooltip-append-to-parent="true">
<j:set var="svgIconId" value="${paneIsCollapsed ? 'chevron-up' : 'chevron-down'}" />
<l:icon src="symbol-${svgIconId}" />
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/resources/lib/layout/pane.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ THE SOFTWARE.
</span>

<j:if test="${attrs.id != null}">
<a class="collapse" href="${rootURL}/toggleCollapse?paneId=${attrs.id}"
<st:adjunct includes="lib.form.link.link"/>
<!-- TODO improve l:link so the `a` can be changed to `l:link`. -->
<a class="collapse post" href="${rootURL}/toggleCollapse?paneId=${attrs.id}"
title="${paneIsCollapsed ? '%expand' : '%collapse'}">

<j:set var="svgIconId" value="${paneIsCollapsed ? 'chevron-up' : 'chevron-down'}" />
Expand Down
2 changes: 1 addition & 1 deletion test/src/test/java/hudson/model/ComputerSetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void testTerminatedNodeAjaxExecutorsDoesNotShowTrace() throws Exception {
new OfflineCause.ChannelTermination(new RuntimeException(message))
);

WebClient wc = j.createWebClient();
WebClient wc = j.createWebClient().withJavaScriptEnabled(false);
Page page = wc.getPage(wc.createCrumbedUrl(HasWidgetHelper.getWidget(j.jenkins.getComputer(), ExecutorsWidget.class).orElseThrow().getUrl() + "ajax"));
String content = page.getWebResponse().getContentAsString();
assertThat(content, not(containsString(message)));
Expand Down
2 changes: 1 addition & 1 deletion test/src/test/java/hudson/model/ComputerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public void testTerminatedNodeAjaxExecutorsDoesNotShowTrace() throws Exception {
new OfflineCause.ChannelTermination(new RuntimeException(message))
);

WebClient wc = j.createWebClient();
WebClient wc = j.createWebClient().withJavaScriptEnabled(false);
Page page = wc.getPage(wc.createCrumbedUrl(HasWidgetHelper.getWidget(agent.toComputer(), ExecutorsWidget.class).orElseThrow().getUrl() + "ajax"));
String content = page.getWebResponse().getContentAsString();
assertThat(content, not(containsString(message)));
Expand Down
11 changes: 11 additions & 0 deletions test/src/test/java/jenkins/model/JenkinsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import hudson.util.FormValidation;
import hudson.util.HttpResponses;
import hudson.util.VersionNumber;
import jakarta.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
Expand Down Expand Up @@ -130,6 +131,16 @@ public class JenkinsTest {
@Rule
public TemporaryFolder tmp = new TemporaryFolder();

@Test
@Issue("SECURITY-3498")
public void testPaneToggleCollapse() throws Exception {
try (WebClient wc = j.createWebClient()) {
final FailingHttpStatusCodeException ex = assertThrows(FailingHttpStatusCodeException.class, () -> wc.goTo("toggleCollapse?paneId=foo"));
// @POST responds 404 when the verb is wrong; @RequirePOST would respond 405.
assertThat(ex.getStatusCode(), is(HttpServletResponse.SC_NOT_FOUND));
}
}

@Test
@Issue("SECURITY-3073")
public void verifyUploadedFingerprintFilePermission() throws Exception {
Expand Down
4 changes: 2 additions & 2 deletions test/src/test/java/lib/layout/AjaxTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class AjaxTest {
@Test
@Issue("JENKINS-65288")
public void ajaxPageRenderingPossibleWithoutJellyTrace() throws Exception {
JenkinsRule.WebClient wc = r.createWebClient();
JenkinsRule.WebClient wc = r.createWebClient().withJavaScriptEnabled(false);
HtmlPage htmlPage = wc.goTo(getExecutorsWidgetAjaxViewUrl());
r.assertGoodStatus(htmlPage);
}
Expand All @@ -76,7 +76,7 @@ public void ajaxPageRenderingPossibleWithJellyTrace() throws Exception {
try {
JellyFacet.TRACE = true;

JenkinsRule.WebClient wc = r.createWebClient();
JenkinsRule.WebClient wc = r.createWebClient().withJavaScriptEnabled(false);
HtmlPage htmlPage = wc.goTo(getExecutorsWidgetAjaxViewUrl());
r.assertGoodStatus(htmlPage);
} finally {
Expand Down

0 comments on commit 84ef1a4

Please sign in to comment.