Pull requests from outside the trust boundary

Code from a fork or an untrusted branch is not your code yet. A workflow that runs it with production secrets or a deploy role has already shipped that trust.

Lesson 29 of 29 · 15 min read · practice only with authorization

Diagram

From an untrusted change to a job that holds secrets

Follow the path. One example at a time.

Step 1 of 4

Change

A pull request arrives from a fork or from a person who cannot commit to the protected branch.

Illustration: a pull request is untrusted input
# A change from a fork is someone else's code.
# The test job can read the repository.
# It cannot deploy.
What changes the outcome
Trigger

Pull requests run the workflow in the fork’s copy or with your secrets injected.

Identity

The job can deploy or read production.

Runner

A self-hosted runner is shared with trusted builds.

The example on the open step is one illustration, or the fix you can paste into an application you own.

What this page is made of

4 pieces. Each one says what fails, who is affected, what you would notice, and what you change.

  1. Untrusted code is the input

    What fails
    A pull request is someone else’s program until you merge it. Running it is executing that program.
    Who is affected
    Everyone whose secrets were in the job’s environment, and everyone the deploy role can change.
    What you would notice
    A workflow that dumps the environment, or a deploy job triggered by pull_request with secrets available.
    What you change
    Keep secrets off that trigger. Review workflows as carefully as application code.
  2. The runner is a network position

    What fails
    A self-hosted runner inside your network, reused by untrusted jobs, is a server those jobs can use.
    Who is affected
    The network and the caches that runner can see.
    What you would notice
    One runner pool for forks and for release builds, with a shared filesystem.
    What you change
    Isolate untrusted jobs on runners that are destroyed afterward. Keep release runners for protected branches.
  3. Tokens the platform injects

    What fails
    The default token on a job can be more privileged than you think. Write the permission down. Do not inherit a write token you did not ask for.
    Who is affected
    The repository and any package or environment that token can change.
    What you would notice
    A workflow with no permissions block, on a repository whose default is broad.
    What you change
    Set the smallest permissions on every workflow. Review the platform’s current defaults when they change.
  4. Environments and approvals

    What fails
    A deploy environment that anyone’s pull request can enter is not an environment. Approvals and branch filters are the gate.
    Who is affected
    The production tenants, if the gate is missing.
    What you would notice
    A deploy button that runs from any branch with the production environment’s secrets.
    What you change
    Bind the environment to protected branches and required reviewers. Forks do not qualify.

A pull request is not a merge

Continuous integration exists to run proposed code. Proposed code from a fork, or from a branch an outsider can open, is untrusted code. The moment that job receives a production secret, a package-publish token, or a cloud role, you have decided the outsider may use them. The review you planned to do after the tests pass is too late. The tests already ran as you.

Split the identities. Tests on untrusted changes get a read-only checkout and no secrets. They can build and run unit tests. They cannot deploy, and they cannot read the environment that deploys. The deploy workflow runs on the protected branch, after the reviews you require, with a different principal. Write that down in the workflow file so the next edit does not “temporarily” rejoin them.

Runners have a location

Hosted runners that disappear after the job are a different risk from a self-hosted runner on your network that keeps a disk. Untrusted jobs on the second kind can see caches, internal addresses, and files a previous job left behind. Use them for trusted branches, or throw the machine away after the job. Do not share one pool because it was expensive to set up.

The default token the platform injects is part of this story. Set permissions explicitly on every workflow. A missing block means you inherited a default, and defaults have changed before. Read the current documentation for the platform you use when you tighten this. The property to check is: untrusted code cannot write to the repository, the packages, or the cloud.

What you would notice

Look for pull_request triggers, especially from forks, in the same file as secret references or deploy steps. Look for self-hosted labels on those jobs. Look for an environment named production with no branch restriction. Each is a finding. The people affected are whoever the secret or the runner can reach: customers in the account the role can read, and the integrity of the artifact you ship.

Do not demonstrate the finding by opening a pull request against a repository you do not administer. In a repository you own, a test workflow with a dummy secret and a fork is a lab. The dummy secret should not be a real one.

What you change

Edit the workflows. Isolate the runners. Restrict environments. Remove secrets from fork jobs today, even before the runner project is pretty. Add a review rule that a workflow change is a security review, because it is a change to who code runs as.

Pair this with workload identity and with the lockfile lessons. A trusted branch that installs a floating dependency is a different door to the same deploy. Close the pull-request door first if it is open. It is the one that does not require a compromised maintainer.

Check yourself

Recognition and the fix. Nothing here is a procedure.

1 / 3

Fork pull requests run a workflow that has access to the production deploy key. What failed?

Sibling techniques

Pages at the same depth, plus a lab and a glossary card for this one.

  1. MapCloud accounts and container environmentsCloud failure is usually identity and exposure.
  1. 01Workload identity instead of static keysA long-lived access key on a laptop or in a repository is a session that does not expire.

Practice

  1. LabTenant deskTwo companies, one API. See what changes when the server checks ownership.

Glossary

  1. CardSupply-chain compromiseA trusted dependency, build plugin, or vendor update carries a change you did not write.