Pull-request workflows and untrusted code
Treat pull-request code, metadata, and produced artifacts as untrusted until they pass the repository’s review and release process. Run verification with minimal authority and isolated resources. Privileged workflows must not execute or blindly consume untrusted PR content simply because a previous workflow completed.
Inside this article 6 sections +
A pull request is a proposal to change code, not a grant of access to deployment credentials. The workflow that tests it may execute package scripts, build plugins, and test helpers supplied by that proposal. Review its authority as if all of those instructions were chosen by an untrusted contributor.
The same principle applies to pull-request metadata and generated files. A title, branch name, test report, or uploaded artifact can carry untrusted content into another step. A secure workflow separates validation from privileged actions and defines exactly which facts may cross that boundary.
Map execution by authority
Start with three zones: untrusted verification, trusted interpretation, and privileged release. Verification can compile and test proposed changes using read-only access and disposable resources. Trusted interpretation may read a constrained report to present a result. Release operates only on approved source and verified artifacts under separate authorization.
Write down tokens, secrets, cloud identity, network reachability, and persistent filesystem access for each zone. A job with no repository write token can still be dangerous if it runs on a persistent runner with internal credentials or access to sensitive services. Token permissions are one boundary, not the complete environment.
- Untrusted verification
- Proposed code executes with minimal credentials, isolated runners, and synthetic fixtures.
- Constrained evidence
- Reports are treated as data with a strict schema, size limits, and verified run identity.
- Trusted release
- Reviewed source and identified artifacts receive narrowly scoped deployment authority.
Review trigger context before adding permissions
A normal pull-request verification path should use the least-privileged context suitable for testing. Fork behavior depends on repository and organization settings, so inspect the effective configuration instead of assuming every installation behaves identically. Keep production secrets and cloud token issuance out of the verification job.
pull_request_target executes in a privileged repository context designed for particular repository-management tasks. It should not check out and run the proposed untrusted code. If a task only needs to label or describe a pull request, use a trusted implementation that treats PR fields as data and requires only the necessary repository permission.
A follow-up triggered by workflow_run can also have privileges the original run lacked. That makes it useful for separation only when the follow-up does not execute the untrusted workspace or blindly trust its outputs. The fact that the preceding workflow succeeded is not a security validation of every byte it produced.
Keep metadata out of executable script source
Do not interpolate untrusted expressions directly into shell commands. Pass necessary text through an environment variable or a structured API argument, quote it correctly, and validate it for its intended use. A pull-request title should remain text even when it contains punctuation meaningful to a shell.
Path inputs need their own policy. An artifact-provided filename should not determine an arbitrary file to read or overwrite in a privileged workspace. Normalize and constrain paths, reject unexpected archive entries, and keep extraction away from trusted executable files. The safest report consumer reads a small known data file rather than restoring a complete workspace.
Review logs and summaries too. Avoid rendering untrusted content in a way that impersonates trusted approval evidence or exposes secrets. A report should identify its source run and commit clearly, so a reviewer can distinguish what the system verified from what the contributor merely supplied.
Validate artifact provenance and content separately
Before a privileged job downloads a report, verify the repository, event type, workflow identity, run identifier, and source revision expected by the process. Do not select “the latest artifact with this name” across unrelated runs. Names are convenient labels, not sufficient provenance.
Then validate the content against a narrow schema. For example, a test summary might contain numeric counts and a bounded list of test identifiers. It should not contain a command to execute, a role to assume, or an arbitrary deployment target. Successful provenance checks do not make executable payloads safe to run.
Keep release artifacts separate from diagnostic PR artifacts. A production deployment should consume an artifact built from the approved release revision under the required controls. If the organization promotes a previously built artifact, its provenance and authorization must establish that exact relationship rather than relying on a matching branch name.
Include runners and caches in the review
Use isolated, disposable execution for untrusted contributions. Persistent self-hosted runners require careful design because one job can leave files or processes that affect later jobs. A label on a runner does not prove that its filesystem, network, or credentials are isolated from privileged workloads.
Do not store secrets in caches or artifacts. Review cache access and key scope so a privileged build cannot mistake attacker-influenced cached content for trusted executable output. Dependency installation should remain tied to the reviewed lockfile and integrity checks, and a clean-cache build should still work.
Check third-party actions and repository scripts as execution dependencies. Pin reviewed action revisions where appropriate, and ensure changes to workflow files and release scripts receive the expected review. A minimal token cannot protect a secret deliberately passed to an unreviewed action.
Turn the review into explicit acceptance cases
Use harmless test cases to verify the boundaries: a fork PR cannot obtain deployment identity; unusual title characters remain literal text; an unexpected artifact schema is rejected; a report from another run is ignored; and a verification runner cannot access production resources. Test the actual repository configuration rather than only a simplified local YAML file.
The architecture review guide frames evidence-led remediation, and technical due diligence applies similar scrutiny to asynchronous work. Engineering consulting can turn workflow risk into specific boundaries and reviewable fixes without obstructing ordinary contributions.