Interview Prep/DevSecOps/Pipeline Security Scanning

A workflow using `pull_request_target` checks out the PR head and runs tests. Why is this dangerous and what do you change?

AdvancedScenarioPipeline Security Scanning
Answer

Situation read → pull_request_target runs in the context of the base repo with secrets and a write token. Checking out untrusted fork code and executing it hands those to an attacker.

What I'd do →

  1. Switch to pull_request for building and testing fork code; it has no secrets and a read-only token.
  2. If you need privileged steps (labeling, comments), split into two workflows: untrusted build uploads an artifact, a second workflow_run workflow reads it as data only.
  3. Never interpolate PR titles or branch names directly in run:; pass them through env:.
  4. Set permissions: to the minimum.

Why → Untrusted code plus secrets is the root of most Actions compromises.

Interview tip → Name "pwn request" as the attack class.

All DevSecOps questions Roadmap: Security in the pipeline

More on Pipeline Security Scanning