Skip to content

Commit 52e050e

Browse files
authored
Update Winstone to 8.1026.v31def012a_f48, add test confirming the CSP response header can be >30KB (jenkinsci#25901)
Co-authored-by: Daniel Beck <[email protected]>
1 parent 1134354 commit 52e050e

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ THE SOFTWARE.
9898
<spotless.check.skip>false</spotless.check.skip>
9999
<ban-junit4-imports.skip>false</ban-junit4-imports.skip>
100100
<!-- Make sure to keep the jetty-ee9-maven-plugin version in war/pom.xml in sync with the Jetty release in Winstone: -->
101-
<winstone.version>8.1023.v8b_42b_1b_79b_f7</winstone.version>
101+
<winstone.version>8.1026.v31def012a_f48</winstone.version>
102102
<node.version>24.11.1</node.version>
103103
</properties>
104104

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package jenkins.security.csp;
2+
3+
import static org.hamcrest.MatcherAssert.assertThat;
4+
import static org.hamcrest.Matchers.containsString;
5+
import static org.hamcrest.Matchers.greaterThan;
6+
import static org.hamcrest.Matchers.hasLength;
7+
import static org.hamcrest.Matchers.is;
8+
9+
import org.htmlunit.FailingHttpStatusCodeException;
10+
import org.htmlunit.WebClient;
11+
import org.htmlunit.html.HtmlPage;
12+
import org.junit.jupiter.api.Test;
13+
import org.junit.jupiter.api.extension.RegisterExtension;
14+
import org.jvnet.hudson.test.junit.jupiter.RealJenkinsExtension;
15+
16+
public class WinstoneResponseHeaderLengthTest {
17+
18+
@RegisterExtension
19+
public RealJenkinsExtension extension = new RealJenkinsExtension().addSyntheticPlugin(new RealJenkinsExtension.SyntheticPlugin(jenkins.security.csp.winstoneResponseHeaderLengthTest.ContributorImpl.class));
20+
21+
@Test
22+
void testLength() throws Exception {
23+
extension.startJenkins();
24+
String lastHeader = "";
25+
try (WebClient wc = new WebClient()) {
26+
// Hopefully speed this up a bit:
27+
wc.getOptions().setJavaScriptEnabled(false);
28+
wc.getOptions().setCssEnabled(false);
29+
wc.getOptions().setDownloadImages(false);
30+
wc.getPage(extension.getUrl()); // request once outside try/catch to ensure it works in principle
31+
try {
32+
while (true) {
33+
final HtmlPage htmlPage = wc.getPage(extension.getUrl());
34+
lastHeader = htmlPage.getWebResponse().getResponseHeaderValue("Content-Security-Policy");
35+
}
36+
} catch (FailingHttpStatusCodeException e) {
37+
assertThat(e.getStatusCode(), is(500));
38+
assertThat(e.getResponse().getContentAsString(), containsString("Error 500 Response Header Fields Too Large"));
39+
40+
assertThat(lastHeader, hasLength(greaterThan(30_000)));
41+
}
42+
}
43+
}
44+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package jenkins.security.csp.winstoneResponseHeaderLengthTest;
2+
3+
import hudson.Extension;
4+
import jenkins.model.Jenkins;
5+
import jenkins.security.csp.Contributor;
6+
import jenkins.security.csp.CspBuilder;
7+
import jenkins.security.csp.Directive;
8+
9+
public class ContributorImpl implements Contributor {
10+
private int count = 0;
11+
12+
@Override
13+
public void apply(CspBuilder cspBuilder) {
14+
count++;
15+
for (int i = 0; i < count; i++) {
16+
cspBuilder.add(Directive.IMG_SRC, "img" + i + ".example.com");
17+
}
18+
}
19+
20+
@Extension
21+
public static ContributorImpl getInstance() {
22+
// Only load this extension if it's in the synthetic plugin, otherwise it will affect other tests
23+
if (Jenkins.get().getPluginManager().whichPlugin(ContributorImpl.class) == null) {
24+
return null;
25+
}
26+
return new ContributorImpl();
27+
}
28+
}

0 commit comments

Comments
 (0)