Skip to content

Commit 5fa356e

Browse files
committed
[SECURITY-3251]
1 parent 969ccec commit 5fa356e

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/main/java/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.kohsuke.stapler.DataBoundSetter;
5555
import org.kohsuke.stapler.QueryParameter;
5656
import org.kohsuke.stapler.interceptor.RequirePOST;
57+
import org.kohsuke.stapler.verb.POST;
5758

5859
/**
5960
* Represents a GitLab Server instance.
@@ -504,6 +505,7 @@ public static class DescriptorImpl extends Descriptor<GitLabServer> {
504505
* @param serverUrl the URL to check.
505506
* @return the validation results.
506507
*/
508+
@POST
507509
public static FormValidation doCheckServerUrl(@QueryParameter String serverUrl) {
508510
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
509511
try {

src/main/resources/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer/config.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ f.entry(title: _("Display Name"), field: "name", "description": "A unique name f
1313
}
1414

1515
f.entry(title: _("Server URL"), field: "serverUrl", "description": "The url to the GitLab server") {
16-
f.textbox(default: GitLabServer.GITLAB_SERVER_URL)
16+
f.textbox(default: GitLabServer.GITLAB_SERVER_URL, checkMethod: 'post')
1717
}
1818

1919
f.entry(title: _("Credentials"), field: "credentialsId", "description": "The Personal Access Token for GitLab APIs access") {

src/test/java/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServerTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44
import static org.hamcrest.CoreMatchers.startsWith;
55
import static org.hamcrest.MatcherAssert.assertThat;
66
import static org.hamcrest.Matchers.is;
7+
import static org.junit.Assert.assertEquals;
78

9+
import java.io.IOException;
10+
import org.apache.http.HttpStatus;
11+
import org.htmlunit.html.HtmlPage;
812
import org.junit.ClassRule;
913
import org.junit.Test;
14+
import org.jvnet.hudson.test.Issue;
1015
import org.jvnet.hudson.test.JenkinsRule;
16+
import org.jvnet.hudson.test.JenkinsRule.WebClient;
17+
import org.xml.sax.SAXException;
1118

1219
public class GitLabServerTest {
1320

@@ -63,4 +70,17 @@ public void testFixEmptyAndTrimFive() throws Exception {
6370
assertThat(server.getCredentialsId(), is(""));
6471
assertThat(server.getHooksRootUrl(), nullValue());
6572
}
73+
74+
@Test
75+
@Issue("SECURITY-3251")
76+
public void testGetDoCheckServerUrl() throws IOException, SAXException {
77+
try (WebClient wc = j.createWebClient()) {
78+
wc.setThrowExceptionOnFailingStatusCode(false);
79+
HtmlPage page = wc.goTo(
80+
"descriptorByName/io.jenkins.plugins.gitlabserverconfig.servers.GitLabServer/checkServerUrl?serverUrl=http://attacker.example.com");
81+
assertEquals(
82+
HttpStatus.SC_NOT_FOUND,
83+
page.getWebResponse().getStatusCode()); // Should be 405 but Stapler doesn't work that way.
84+
}
85+
}
6686
}

0 commit comments

Comments
 (0)