Skip to content

Commit

Permalink
Check Run Scripts permission in CAS 1.0 form validation (SECURITY-488)
Browse files Browse the repository at this point in the history
  • Loading branch information
fcrespel committed May 8, 2017
1 parent 79a9bd1 commit d8aba2a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import hudson.Util;
import hudson.model.Descriptor;
import hudson.util.FormValidation;
import jenkins.model.Jenkins;

/**
* CAS 1.0 protocol support.
Expand Down Expand Up @@ -74,10 +75,13 @@ public FormValidation doTestScript(
@QueryParameter("rolesValidationScript") final String rolesValidationScript,
@QueryParameter("testValidationResponse") final String testValidationResponse,
@QueryParameter("sandbox") final boolean sandbox) {
if (!canRunScripts()) {
return FormValidation.error(Messages.Cas10Protocol_rolesValidationScript_noRunScriptPermissionError());
}
try {
Collection roles = Cas10RoleParsingTicketValidator.parseRolesFromValidationResponse(getSecureGroovyScript(rolesValidationScript, sandbox), testValidationResponse);
if (roles == null) {
return FormValidation.error(Messages.Cas10Protocol_rolesValidationScript_noResult());
return FormValidation.warning(Messages.Cas10Protocol_rolesValidationScript_noResult());
}
return FormValidation.ok(Messages.Cas10Protocol_rolesValidationScript_result() + ": " + roles);
} catch (CompilationFailedException e) {
Expand All @@ -94,6 +98,10 @@ public FormValidation doTestScript(
return FormValidation.error(Messages.Cas10Protocol_rolesValidationScript_unknownError() + ": " + e);
}
}

private boolean canRunScripts() {
return Jenkins.getInstance().getACL().hasPermission(Jenkins.RUN_SCRIPTS);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CasSecurityRealm.casServerUrl.cannotGetResponse=Problem getting a response from

Cas10Protocol.rolesValidationScript.result=Roles parsed from the test validation response
Cas10Protocol.rolesValidationScript.noResult=Roles Validation Script returned no result
Cas10Protocol.rolesValidationScript.noRunScriptPermissionError=Current user is missing Run Script permission
Cas10Protocol.rolesValidationScript.compilationError=Roles Validation Script failed to compile
Cas10Protocol.rolesValidationScript.returnTypeError=Roles Validation Script did not return a Collection
Cas10Protocol.rolesValidationScript.rejectedAccessError=Roles Validation Script uses forbidden language elements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CasSecurityRealm.casServerUrl.cannotGetResponse=Un probl

Cas10Protocol.rolesValidationScript.result=Rôles extraits de la réponse de validation de test
Cas10Protocol.rolesValidationScript.noResult=Le script de validation des rôles n''a retourné aucun résultat
Cas10Protocol.rolesValidationScript.noRunScriptPermissionError=L''utilisateur actuel n''a pas la permission d''exécuter des scripts
Cas10Protocol.rolesValidationScript.compilationError=Le script de validation des rôles n''a pas pu être compilé
Cas10Protocol.rolesValidationScript.returnTypeError=Le script de validation des rôles n''a pas retourné de Collection
Cas10Protocol.rolesValidationScript.rejectedAccessError=Le script de validation des rôles utilise des éléments interdits du langage
Expand Down

0 comments on commit d8aba2a

Please sign in to comment.