Skip to content

Commit 2dd5eda

Browse files
committed
[SECURITY-2342]
1 parent a892158 commit 2dd5eda

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/main/java/org/jenkinsci/plugins/credentialsbinding/impl/ZipFileBinding.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@
3636
import java.io.InputStream;
3737
import java.util.Collections;
3838

39+
import jenkins.model.Jenkins;
3940
import org.apache.commons.io.IOUtils;
4041
import org.jenkinsci.Symbol;
4142
import org.jenkinsci.plugins.credentialsbinding.BindingDescriptor;
4243
import org.jenkinsci.plugins.plaincredentials.FileCredentials;
4344
import org.kohsuke.stapler.AncestorInPath;
4445
import org.kohsuke.stapler.DataBoundConstructor;
4546
import org.kohsuke.stapler.QueryParameter;
47+
import org.kohsuke.stapler.StaplerRequest;
4648

4749
public class ZipFileBinding extends AbstractOnDiskBinding<FileCredentials> {
4850

@@ -72,7 +74,22 @@ public class ZipFileBinding extends AbstractOnDiskBinding<FileCredentials> {
7274
return Messages.ZipFileBinding_secret_zip_file();
7375
}
7476

75-
public FormValidation doCheckCredentialsId(@AncestorInPath Item owner, @QueryParameter String value) {
77+
// @RequirePOST
78+
public FormValidation doCheckCredentialsId(StaplerRequest req, @AncestorInPath Item owner, @QueryParameter String value) {
79+
//TODO due to weird behavior in c:select, there are initial calls using GET
80+
// so using this approach will prevent 405 errors
81+
if (!req.getMethod().equals("POST")) {
82+
return FormValidation.ok();
83+
}
84+
if (owner == null) {
85+
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
86+
return FormValidation.ok();
87+
}
88+
} else {
89+
if (!owner.hasPermission(Item.EXTENDED_READ) && !owner.hasPermission(CredentialsProvider.USE_ITEM)) {
90+
return FormValidation.ok();
91+
}
92+
}
7693
for (FileCredentials c : CredentialsProvider.lookupCredentials(FileCredentials.class, owner, null, Collections.<DomainRequirement>emptyList())) {
7794
if (c.getId().equals(value)) {
7895
InputStream is = null;

src/main/resources/org/jenkinsci/plugins/credentialsbinding/MultiBinding/config.jelly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ THE SOFTWARE.
2626
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:st="jelly:stapler" xmlns:c="/lib/credentials">
2727
<st:include page="config-variables.jelly" class="${descriptor.clazz}"/>
2828
<f:entry title="${%Credentials}" field="credentialsId">
29-
<c:select expressionAllowed="${expressionAllowed}"/>
29+
<c:select expressionAllowed="${expressionAllowed}" checkMethod="post"/>
3030
</f:entry>
3131
<st:include page="config-details.jelly" class="${descriptor.clazz}" optional="true"/>
3232
</j:jelly>

0 commit comments

Comments
 (0)