Skip to content

Commit

Permalink
JENKINS-62708 PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkRx committed Jan 11, 2022
1 parent ee148dd commit f7c7de9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -706,16 +706,14 @@ public synchronized String[] getAclApprovedSignatures() {
public synchronized void setApprovedScriptHashes(String[] scriptHashes) throws IOException {
Jenkins.getInstance().checkPermission(Jenkins.RUN_SCRIPTS);
approvedScriptHashes.clear();
List<String> goodScriptHashes = new ArrayList<>(scriptHashes.length);
Pattern sha1Pattern = Pattern.compile("^[a-fA-F0-9]{40}$");
Pattern sha1Pattern = Pattern.compile("[a-fA-F0-9]{40}");
for (String scriptHash : scriptHashes) {
if (scriptHash != null && sha1Pattern.matcher(scriptHash).matches()) {
goodScriptHashes.add(scriptHash);
approvedScriptHashes.add(scriptHash);
} else {
LOG.warning("Ignoring malformed script hash: " + scriptHash);
LOG.warning(() -> "Ignoring malformed script hash: " + scriptHash);
}
}
approvedScriptHashes.addAll(goodScriptHashes);
save();
reconfigure();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ public void upgradeSmokes() throws Exception {
new SecureGroovyScript("jenkins.model.Jenkins.instance", true, null)));
p.getPublishersList().add(new TestGroovyRecorder(
new SecureGroovyScript("println(jenkins.model.Jenkins.instance.getLabels())", false, null)));
r.assertLogNotContains("org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: "
+ "Scripts not permitted to use staticMethod jenkins.model.Jenkins getInstance",
r.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0).get()));
r.assertLogNotContains("org.jenkinsci.plugins.scriptsecurity.scripts.UnapprovedUsageException: script not yet approved for use",
r.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0).get()));
}
Expand Down

0 comments on commit f7c7de9

Please sign in to comment.