Skip to content

Commit 3a8f7ee

Browse files
committed
prevent accidential admin auto-approval
1 parent 3d3347a commit 3a8f7ee

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/main/java/org/jenkinsci/plugins/scriptsecurity/scripts/ScriptApproval.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,8 @@ boolean isEmpty() {
581581
pendingClasspathEntries.isEmpty();
582582
}
583583

584-
/**
584+
585+
/**
585586
* Used when someone is configuring a script.
586587
* Typically you would call this from a {@link DataBoundConstructor}.
587588
* It should also be called from a {@code readResolve} method (which may then simply return {@code this}),
@@ -594,15 +595,16 @@ boolean isEmpty() {
594595
* @param language the language in which it is written
595596
* @param context any additional information about how where or by whom this is being configured
596597
* @param approveIfAdmin indicates whether script should be approved if current user has admin permissions
598+
* @param ignoreAdmin indicates whether auto approval should be ignored, regardless of any configurations.
597599
* @return {@code script}, for convenience
598600
*/
599-
public synchronized String configuring(@NonNull String script, @NonNull Language language, @NonNull ApprovalContext context, boolean approveIfAdmin) {
601+
public synchronized String configuring(@NonNull String script, @NonNull Language language, @NonNull ApprovalContext context, boolean approveIfAdmin, boolean ignoreAdmin) {
600602
final ConversionCheckResult result = checkAndConvertApprovedScript(script, language);
601603
if (!result.approved) {
602-
if (!Jenkins.get().isUseSecurity() ||
604+
if (!Jenkins.get().isUseSecurity() ||
603605
(ALLOW_ADMIN_APPROVAL_ENABLED &&
604606
((Jenkins.getAuthentication2() != ACL.SYSTEM2 && Jenkins.get().hasPermission(Jenkins.ADMINISTER))
605-
&& (ADMIN_AUTO_APPROVAL_ENABLED || approveIfAdmin)))) {
607+
&& (ADMIN_AUTO_APPROVAL_ENABLED || approveIfAdmin) && !ignoreAdmin))) {
606608
approvedScriptHashes.add(result.newHash);
607609
//Pending scripts are not stored with a precalculated hash, so no need to remove any old hashes
608610
removePendingScript(result.newHash);
@@ -618,6 +620,14 @@ public synchronized String configuring(@NonNull String script, @NonNull Language
618620
return script;
619621
}
620622

623+
/**
624+
* @deprecated Use {@link #configuring(String, Language, ApprovalContext, boolean, boolean)} instead
625+
*/
626+
@Deprecated
627+
public synchronized String configuring(@NonNull String script, @NonNull Language language, @NonNull ApprovalContext context, boolean approveIfAdmin) {
628+
return configuring(script, language, context, approveIfAdmin, false);
629+
}
630+
621631
/**
622632
* @deprecated Use {@link #configuring(String, Language, ApprovalContext, boolean)} instead
623633
*/
@@ -644,7 +654,9 @@ public synchronized String using(@NonNull String script, @NonNull Language langu
644654
// Usually. this method is called once the job configuration with the script is saved.
645655
// If a script was previously pending and is now deleted, however, it would require to re-configure the job.
646656
// That's why we call it again if it is unapproved in a running job.
647-
this.configuring(script, language, ApprovalContext.create(), false);
657+
// 'ignoreAdmin' is set to true, so that administrators
658+
// do not accidentally approve scripts when running a job.
659+
this.configuring(script, language, ApprovalContext.create(), false, true);
648660
throw new UnapprovedUsageException(result.newHash);
649661
}
650662
return script;

0 commit comments

Comments
 (0)