Skip to content

Commit

Permalink
SECURITY-2467
Browse files Browse the repository at this point in the history
  • Loading branch information
Pldi23 committed Dec 20, 2021
1 parent 95d5766 commit a596f65
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Expand Up @@ -121,6 +121,7 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.interceptor.RequirePOST;

/**
* SCM source implementation for Bitbucket.
Expand Down Expand Up @@ -1191,6 +1192,7 @@ public ListBoxModel doFillCredentialsIdItems(@AncestorInPath SCMSourceOwner cont
}

@SuppressWarnings("unused") // used By stapler
@RequirePOST
public ListBoxModel doFillRepositoryItems(@AncestorInPath SCMSourceOwner context,
@QueryParameter String serverUrl,
@QueryParameter String credentialsId,
Expand Down
@@ -0,0 +1,39 @@
package com.cloudbees.jenkins.plugins.bitbucket;

import com.gargoylesoftware.htmlunit.html.HtmlPage;
import java.net.HttpURLConnection;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject;
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.MockAuthorizationStrategy;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;

public class Security2467Test {

@Rule
public JenkinsRule j = new JenkinsRule();

@Issue("SECURITY-2467")
@Test
public void doFillRepositoryItemsWhenInvokedUsingGetMethodThenReturnMethodNotAllowed() throws Exception {
String admin = "Admin";
String projectName = "p";
WorkflowMultiBranchProject pr = j.jenkins.createProject(WorkflowMultiBranchProject.class, projectName);
j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
j.jenkins.setAuthorizationStrategy(new MockAuthorizationStrategy().
grant(Jenkins.ADMINISTER).everywhere().to(admin));

JenkinsRule.WebClient webClient = j.createWebClient().withThrowExceptionOnFailingStatusCode(false);
webClient.login(admin);
HtmlPage htmlPage = webClient.goTo("job/" + projectName +"/descriptorByName/com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource/fillRepositoryItems?serverUrl=http://hacker:9000&credentialsId=ID_Admin&repoOwner=admin");

assertThat(htmlPage.getWebResponse().getStatusCode(), is(HttpURLConnection.HTTP_BAD_METHOD));
assertThat(htmlPage.getWebResponse().getContentAsString(), containsString("This URL requires POST"));
}
}

0 comments on commit a596f65

Please sign in to comment.