Skip to content

Commit

Permalink
Security fixes (#180)
Browse files Browse the repository at this point in the history
Major security fixes
  • Loading branch information
mPokornyETM authored Dec 2, 2024
1 parent fa99297 commit c34d63a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
import hudson.util.FormValidation;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import jenkins.model.Jenkins;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.interceptor.RequirePOST;

/**
* Restricts the jobs execution by applying regular expressions to their names.
Expand Down Expand Up @@ -86,7 +88,9 @@ public String getDisplayName() {
return Messages.restrictions_Job_RegexName();
}

@RequirePOST
public FormValidation doCheckRegexExpression(@QueryParameter String regexExpression) {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);

Check warning on line 93 in src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/restrictions/job/RegexNameRestriction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 93 is not covered by tests
try {
Pattern.compile(regexExpression);
} catch (PatternSyntaxException exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.acegisecurity.userdetails.UsernameNotFoundException;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.interceptor.RequirePOST;
import org.springframework.dao.DataAccessException;

/**
Expand Down Expand Up @@ -96,7 +97,9 @@ public String getDisplayName() {
return "N/A";
}

@RequirePOST
public FormValidation doCheckSelectedGroupId(@QueryParameter String selectedGroupId) {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);

Check warning on line 102 in src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/util/GroupSelector.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 102 is not covered by tests
selectedGroupId = Util.fixEmptyAndTrim(selectedGroupId);
SecurityRealm sr = Jenkins.get().getSecurityRealm();
String eSelectedGroupId = Functions.escape(selectedGroupId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
import hudson.util.FormValidation;
import java.io.Serializable;
import java.util.Objects;
import jenkins.model.Jenkins;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.interceptor.RequirePOST;

/**
* Describable Item, which allows to configure a user.
Expand Down Expand Up @@ -91,7 +93,9 @@ public String getDisplayName() {
}

@Restricted(NoExternalUse.class) // Stapler only
@RequirePOST
public FormValidation doCheckSelectedUserId(@QueryParameter String selectedUserId) {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);

Check warning on line 98 in src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/util/UserSelector.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 98 is not covered by tests
selectedUserId = Util.fixEmptyAndTrim(selectedUserId);
if (selectedUserId == null) {
return FormValidation.error("Field is empty");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import jenkins.model.Jenkins;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.interceptor.RequirePOST;

/**
* Describable Item, which allows to select class.
Expand Down Expand Up @@ -89,7 +90,9 @@ public String getDisplayName() {
return "N/A";
}

@RequirePOST
public FormValidation doCheckSelectedClass(final @QueryParameter String selectedClass) {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);

Check warning on line 95 in src/main/java/io/jenkins/plugins/jobrestrictions/util/ClassSelector.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 95 is not covered by tests
String _selectedClass = Util.fixEmptyAndTrim(selectedClass);
if (_selectedClass == null) {
return FormValidation.error("Field is empty");
Expand Down

0 comments on commit c34d63a

Please sign in to comment.