Interview Prep/GitHub Actions/Triggers & Events

When should you use `workflow_run`, and what is its security trap?

AdvancedConceptTriggers & Events
Answer

workflow_run starts a workflow when another workflow completes, in the base repo's privileged context. The common safe pattern: an unprivileged pull_request workflow builds and uploads results as an artifact, and a privileged workflow_run workflow posts the PR comment.

on:
  workflow_run:
    workflows: ["CI"]
    types: [completed]

Trap: the artifact is attacker-controlled. Downloading it and executing it, or source-ing values from it into scripts, or extracting it into the workspace over trusted files, is a pwn request. Treat artifact content as data, validate it (for example, a PR number must be an integer), and never run it.

All GitHub Actions questions Roadmap: GitHub Actions

More on Triggers & Events