Skip to content

fix(ci): stop interpolating helm-diff output directly into a bash script - #21

Merged
jonathandieu merged 1 commit into
mainfrom
fix-ci-helm-diff-script-injection
Aug 5, 2026
Merged

fix(ci): stop interpolating helm-diff output directly into a bash script#21
jonathandieu merged 1 commit into
mainfrom
fix-ci-helm-diff-script-injection

Conversation

@jonathandieu

Copy link
Copy Markdown
Owner

Found while debugging why PR #20's helm-diff check failed with POD_NAMESPACE: command not found.

The Format diff comment step does result="${{ steps.diff.outputs.result }}", which splices the raw diff text directly into the script body before bash runs it. Any rendered manifest containing $(...) syntax gets executed as a real command substitution once it lands in that double-quoted string. cert-manager's own stock chart legitimately uses this syntax in container args (--cluster-resource-namespace=$(POD_NAMESPACE)) - the step broke the moment cert-manager's rendered output first appeared in a diff (PR #20 touches its values.yaml for the first time).

Fix: pass the value through env: instead, so it's set as-is with no re-parsing - the standard mitigation for this class of GitHub Actions script-injection bug.

Non-blocking today (the job already has continue-on-error: true and there's no branch protection on main), but worth fixing since it'll keep tripping on any future diff containing this common Kubernetes env-var pattern.

result="${{ steps.diff.outputs.result }}" splices the raw diff text into
the script body before bash ever runs it. Any rendered manifest
containing $(...) syntax - which cert-manager's own stock chart uses
legitimately in container args (--cluster-resource-namespace=$(POD_NAMESPACE))
- gets executed as a real command substitution once it lands in that
double-quoted string, breaking the step (command not found) the moment
such a chart shows up in a diff for the first time. Passing it through
env: instead means the value is set as-is with no re-parsing.
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

Helm template diff

diff -u --recursive --label base --label head base head
--- base
+++ head
@@ -218,7 +218,7 @@
     app.kubernetes.io/managed-by: Helm
 type: Opaque
 data:
-  SECRET_KEY_BASE: bWl0dW16RWZWM1d5ZHdDOEpWR0Q1TUdPbFMwdWE3UG1OOWZPUVppY1lySkRDY2xtcEF1RjNnV2NSb0JPdVNQQzNkV2xCUFBsM242UkdkN3hteDR3dUF3d0do
+  SECRET_KEY_BASE: SU4wWUVZVnJsZHZRTHYxTllSRzBIdlg1SnlUNzRkdjVkOHBXVkREQjZMNm1LeUlpUVFWY1o3U3UyRld3Q0g2bmVGVm5CM0QwQnFuNjIxTFJ2YUtxVW5kZjFo
   TOTP_VAULT_KEY: ZHN4dmJuM2p4RGQxNmF6MlFwc1g1QjhPK2xseGpRMlNKRTJpNUJ6eDM4ST0=
   DATABASE_URL: cG9zdGdyZXM6Ly9wb3N0Z3Jlczpwb3N0Z3Jlc0BwbGF1c2libGUtYW5hbHl0aWNzLXBvc3RncmVzcWw6NTQzMi9wbGF1c2libGVfZGI=
   CLICKHOUSE_DATABASE_URL: aHR0cDovL2NsaWNraG91c2U6cGFzc3dvcmRAcGxhdXNpYmxlLWFuYWx5dGljcy1jbGlja2hvdXNlOjgxMjMvcGxhdXNpYmxlX2V2ZW50c19kYg==

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the CI workflow’s “Format diff comment” step by preventing helm-diff output from being interpolated into the bash script body (avoiding command-substitution/script-injection hazards when the diff contains $(...)-style text).

Changes:

  • Pass steps.diff.outputs.result into the step via env: (DIFF_RESULT) instead of assigning it inside the run: script.
  • Update the formatting logic to reference $DIFF_RESULT for both the “no changes” check and the printf that writes the PR comment body.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jonathandieu
jonathandieu merged commit 6041ed4 into main Aug 5, 2026
11 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants