You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
jenkins: fix shell-injection risk in cgSign/cgVerify image arg
Both helpers built their sh script with a Groovy GString and inlined
the caller-supplied `image` value inside a single-quoted shell string:
IMAGE='${image}'
If `image` ever contained a single quote (or other shell metacharacter)
it would break out of the quoting and be parsed as shell. Switch the
sh body to a single-quoted Groovy string (no Groovy interpolation) and
pass `image` through the sh step's environment via withEnv. The shell
then references "$IMAGE" with normal double-quoting, which is safe
regardless of contents.
While here, drop the local `def org = env.CHAINGUARD_ORG` indirection
in favor of referencing $CHAINGUARD_ORG directly from the shell —
Jenkins already exposes env entries to the sh step, so there's no
need to Groovy-interpolate that one either. Same class of issue,
though that value is controller-set rather than caller-supplied.
Behavior for well-formed image refs is unchanged.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: jenkins/shared-libraries/cg-images/vars/cgSign.groovy
+43-39Lines changed: 43 additions & 39 deletions
Original file line number
Diff line number
Diff line change
@@ -39,44 +39,48 @@ def call(String image) {
39
39
if (!image?.trim()) {
40
40
error('cgSign: image argument is required')
41
41
}
42
-
def org = env.CHAINGUARD_ORG
43
-
if (!org) error('cgSign: env.CHAINGUARD_ORG is empty — JCasC globalNodeProperties should set it from the controller env (jenkins/casc/jenkins.yaml). Re-run setup.sh.')
if (!env.CHAINGUARD_ORG) error('cgSign: env.CHAINGUARD_ORG is empty — JCasC globalNodeProperties should set it from the controller env (jenkins/casc/jenkins.yaml). Re-run setup.sh.')
43
+
// Pass `image` through the sh step's environment rather than interpolating
44
+
// it into the script body — otherwise an image ref containing a single
45
+
// quote (or other shell metacharacter) could break out of the surrounding
46
+
// quoting. CHAINGUARD_ORG is already exposed to the shell by Jenkins.
Copy file name to clipboardExpand all lines: jenkins/shared-libraries/cg-images/vars/cgVerify.groovy
+32-30Lines changed: 32 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -25,35 +25,37 @@ def call(String image) {
25
25
if (!image?.trim()) {
26
26
error('cgVerify: image argument is required')
27
27
}
28
-
def org = env.CHAINGUARD_ORG
29
-
if (!org) error('cgVerify: env.CHAINGUARD_ORG is empty — JCasC globalNodeProperties should set it from the controller env (jenkins/casc/jenkins.yaml). Re-run setup.sh.')
if (!env.CHAINGUARD_ORG) error('cgVerify: env.CHAINGUARD_ORG is empty — JCasC globalNodeProperties should set it from the controller env (jenkins/casc/jenkins.yaml). Re-run setup.sh.')
29
+
// Pass `image` through the sh step's environment rather than interpolating
30
+
// it into the script body — see cgSign.groovy for the same reasoning.
0 commit comments