Skip to content

Potential fix for code scanning alert no. 226: Artifact poisoning#525

Merged
Dargon789 merged 1 commit into
mainfrom
alert-autofix-226
May 7, 2026
Merged

Potential fix for code scanning alert no. 226: Artifact poisoning#525
Dargon789 merged 1 commit into
mainfrom
alert-autofix-226

Conversation

@Dargon789
Copy link
Copy Markdown
Owner

@Dargon789 Dargon789 commented May 7, 2026

Potential fix for https://github.com/Dargon789/foundry/security/code-scanning/226

The best fix is to remove untrusted artifact source selection from workflow_dispatch by refusing manual runs unless they are tied to a trusted workflow_run context, or at minimum by not accepting user-supplied run_id.
The least-disruptive, single best change here is:

  1. Keep workflow_dispatch if needed for operational reasons.
  2. Add a guard step before artifact download that fails when the event is workflow_dispatch.
  3. Make download-artifact always use github.event.workflow_run.id only.

This preserves existing publish logic for trusted workflow_run invocations, avoids changing downstream scripts, and closes both alert variants by eliminating the tainted flow from dispatch input to artifact consumption.

Edits are in .github/workflows/npm.yml around:

  • before Download Release Assets step (new guard step),
  • run-id in Download Release Assets step.

No new imports/dependencies are needed.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Summary by Sourcery

Enforce trusted workflow_run context for consuming release artifacts in the npm GitHub Actions workflow to mitigate artifact poisoning risk.

New Features:

  • Add a guard step that fails the npm workflow when artifacts are consumed outside of a workflow_run event context.

Bug Fixes:

  • Remove support for user-supplied run_id when downloading artifacts, ensuring artifacts are only fetched from the triggering workflow_run event.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Dargon789 <64915515+Dargon789@users.noreply.github.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
next Ready Ready Preview, Comment May 7, 2026 1:16am
react Ready Ready Preview, Comment May 7, 2026 1:16am

@gemini-code-assist
Copy link
Copy Markdown

Note

Gemini is unable to generate a review for this pull request due to the file types involved not being currently supported.

@snyk-io
Copy link
Copy Markdown

snyk-io Bot commented May 7, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 7, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR hardens the npm publish workflow against artifact poisoning by forbidding artifact consumption outside trusted workflow_run invocations and removing any user-controlled run_id from the artifact download step.

Sequence diagram for trusted artifact consumption in npm workflow

sequenceDiagram
  actor Maintainer
  participant GitHubActions
  participant NpmWorkflow
  participant GuardStep
  participant DownloadArtifactAction
  participant ArtifactStore

  Maintainer->>GitHubActions: trigger workflow_run or workflow_dispatch
  GitHubActions->>NpmWorkflow: start npm workflow with event context

  NpmWorkflow->>GuardStep: evaluate github.event_name
  alt event is workflow_run
    GuardStep-->>NpmWorkflow: allow artifact consumption
    NpmWorkflow->>DownloadArtifactAction: download-artifact with run-id github.event.workflow_run.id
    DownloadArtifactAction->>ArtifactStore: fetch artifacts for run
    ArtifactStore-->>DownloadArtifactAction: return artifacts
    DownloadArtifactAction-->>NpmWorkflow: artifacts extracted to artifact_dir
  else event is not workflow_run
    GuardStep-->>NpmWorkflow: refuse artifact consumption
    NpmWorkflow->>GitHubActions: exit 1 with error
  end
Loading

Flow diagram for guarded artifact download in npm workflow

flowchart TD
  Start[Start npm workflow]
  CheckEvent[Check github.event_name]
  IsWorkflowRun{Is event_name workflow_run}
  GuardStep[Guard step
Refuse artifacts outside workflow_run]
  Download[Download Release Assets
run-id = github.event.workflow_run.id]
  Fail[Fail job
exit 1]
  NextSteps[Subsequent npm publish steps]

  Start --> CheckEvent --> IsWorkflowRun
  IsWorkflowRun -- Yes --> Download --> NextSteps
  IsWorkflowRun -- No --> GuardStep --> Fail
Loading

File-Level Changes

Change Details Files
Enforce that artifacts are only consumed when the workflow is triggered via workflow_run.
  • Add a guard step before artifact download that checks github.event_name and fails the job if it is not workflow_run
  • Provide a clear error message explaining refusal to consume artifacts outside workflow_run context
.github/workflows/npm.yml
Eliminate user-supplied run_id from artifact downloads to remove tainted input.
  • Update the Download Release Assets step to always use github.event.workflow_run.id for run-id
  • Remove fallback to inputs.run_id so manual workflow_dispatch inputs cannot influence which artifacts are downloaded
.github/workflows/npm.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@Dargon789 Dargon789 marked this pull request as ready for review May 7, 2026 01:18
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • If workflow_dispatch is still intentionally supported, consider tightening the guard step condition to explicitly target workflow_dispatch (e.g. if: ${{ github.event_name == 'workflow_dispatch' }}) so other non-workflow_run event types do not get inadvertently blocked.
  • Now that run-id always uses github.event.workflow_run.id, you may want to remove or repurpose the inputs.run_id input from the workflow definition and any associated UI hints to avoid confusion about unused parameters.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- If `workflow_dispatch` is still intentionally supported, consider tightening the guard step condition to explicitly target `workflow_dispatch` (e.g. `if: ${{ github.event_name == 'workflow_dispatch' }}`) so other non-`workflow_run` event types do not get inadvertently blocked.
- Now that `run-id` always uses `github.event.workflow_run.id`, you may want to remove or repurpose the `inputs.run_id` input from the workflow definition and any associated UI hints to avoid confusion about unused parameters.

Fix all in Cursor


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Base automatically changed from master to main May 7, 2026 02:31
@Dargon789 Dargon789 merged commit 78ddeec into main May 7, 2026
18 of 20 checks passed
@Dargon789 Dargon789 deleted the alert-autofix-226 branch May 7, 2026 02:36
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.

1 participant