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 →
- Switch to
pull_requestfor building and testing fork code; it has no secrets and a read-only token. - If you need privileged steps (labeling, comments), split into two workflows: untrusted build uploads an artifact, a second
workflow_runworkflow reads it as data only. - Never interpolate PR titles or branch names directly in
run:; pass them throughenv:. - 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.
More on Pipeline Security Scanning
You are asked to add security to an existing CI pipeline. Where do SAST, SCA, secrets scanning and DAST each go?BeginnerGitleaks flags an AWS access key in a pull request. The developer says it is a test key. What do you do?BeginnerDevelopers fear security scans will slow the pipeline from 6 to 20 minutes. How do you roll them out?BeginnerA SAST tool reports 2,000 findings on a legacy repo the first time you run it. How do you introduce it without freezing delivery?IntermediateA developer insists a scanner finding is a false positive. What is your process?BeginnerSCA flags a critical CVE in a transitive dependency and no patched version exists. What are your options?Intermediate