Egress allowlists for GitHub Actions: a practical guide
By the CapyShield team · · 5 min read
In short
An egress allowlist lets a CI job reach only the registries and APIs it needs, so a compromised dependency can't send stolen secrets anywhere else. Record a build's real connections with capyshield watch --emit-policy, review the result, and enforce it with capyshield guard, which exits 2 on a blocked connection. Pair it with SHA-pinned actions and least-privilege tokens, which cover what a network allowlist can't.
A GitHub Actions job can usually connect to any host on the internet. That is convenient for installing tools and terrible for containing a compromised dependency, because the same job holds your repository token, your registry token and often cloud credentials. An egress allowlist flips the default: the job may reach the registries and APIs it needs, and every other connection fails. This post shows how to build one from what your workflow actually does, enforce it per step, and where its limits are.
Why lock down outbound traffic in CI?
Because CI is where secrets and untrusted code meet. A single npm ci runs install scripts from every package in the tree, with the job's environment. If one of those packages is malicious, it needs two things: a secret to steal, and a way to send it somewhere. You can reduce the first with careful secret scoping, but you can rarely remove it. The second you can close almost completely, because a build talks to a short, predictable list of hosts.
It also gives you a record. When a job unexpectedly contacts a new host, that is worth knowing even if nothing was stolen: a dependency started downloading a binary, a tool added telemetry, or something worse.
Recent incidents show why the network step is worth guarding. The npm worms that hit CI in 2025 and 2026 all ran at install time, collected tokens from the environment and from files such as ~/.npmrc, and then had to send them somewhere: an attacker's HTTPS endpoint, a file-upload network, or a public GitHub repository. Each of those is a connection a typical npm ci never needs to make.
Which hosts does a CI job actually need?
Fewer than you would think. A Node build needs the npm registry; a Python build needs PyPI and its file host; a Rust build needs crates.io and its index. CapyShield packages these as presets you can name instead of listing hosts by hand:
npm registry.npmjs.org, registry.yarnpkg.com, repo.yarnpkg.com
python pypi.org, files.pythonhosted.org
rust crates.io, index.crates.io, static.crates.io, static.rust-lang.org
go proxy.golang.org, sum.golang.orgBe careful with the github, gitlab, bitbucket and chrome-for-testing presets. Those hosts serve content anyone can upload, which means they can also receive exfiltrated data: several npm worms published stolen credentials to attacker-created GitHub repositories. Enable them only if your build needs them. CapyShield still scans request bodies and URLs sent to them for secrets.
How do you build an allowlist without breaking the build?
Don't write it by hand. Run the build once in watch mode, which records every connection and blocks nothing, and have it write the policy:
capyshield watch --emit-policy capyshield.yaml -- npm ciThe generated file is an enforce-mode policy listing every host the command reached, with a note on which preset covers each one. Review it before you commit it: anything you don't recognise is exactly what this exercise is for. Run it with a cold cache, since a warm cache hides the downloads that only happen on a fresh runner.
A reviewed policy for a Node project might be this small:
version: 1
mode: enforce
fail_mode: fail_closed
egress:
tls_inspection: sni
allow_presets: ["npm"]
deny_hosts: ["*.ngrok-free.app", "webhook.site"]
max_outbound_bytes: 131072Unknown keys are rejected, so a typo exits with code 1 instead of silently weakening the policy. Switch tls_inspection to mitm if you also want request bodies to allow-listed hosts scanned for secrets; sni enforces hosts and byte counts without decrypting anything.
How do you enforce an egress allowlist in a GitHub Actions workflow?
Wrap the steps that run untrusted code with capyshield guard. It exits with code 2 when it blocks a connection, so the job fails.
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- uses: capyshield-hq/capyshield/action@dd8fad936b663d4f51837fa0c60824781667f528 # v0.2.0
- run: capyshield guard --config capyshield.yaml --report egress.json -- npm ci
- run: capyshield guard --config capyshield.yaml -- npm run buildEach run: step is a separate process, so wrap each one that executes dependency code: install, build and test. The --report file is a JSON log of every connection with its host, port, bytes sent, action and rule, worth uploading as an artifact. The example workflow also runs the VEX and workflow-audit steps.
Give each step only the secrets it uses. If the install needs a private registry token, set it on that step alone with env:. guard fingerprints sensitive environment values in memory, so if an install script puts NPM_TOKEN in a request body or URL, or sends it to any host other than an allow-listed one in an authentication header, the request is blocked as a secret_leak. With CapyShield Cloud on Team, --sync also applies one team egress policy across projects and reports blocked hosts: host names and counts only, never payloads.
What doesn't an egress allowlist protect against?
Being clear about this is what keeps the control honest:
- Steps you don't wrap.
uses:steps run as actions, outside the proxy. Pinning them to a full commit SHA, as GitHub's secure-use guide recommends, is what protects you there. - Raw sockets. The proxy is cooperative: npm, pip, uv, curl, git and most SDKs honor proxy variables, but code that opens its own sockets can bypass it. For a hard boundary, run the step in a container or network namespace whose only route out is the proxy.
- Secrets printed to logs. The tj-actions/changed-files compromise (CVE-2025-30066) dumped secrets into build logs instead of sending them anywhere. CISA's advice was to find affected workflows and rotate every exposed secret. No network control stops that; least-privilege tokens limit what there is to print.
- Workflow design flaws. The TanStack compromise chained a
pull_request_targetworkflow, a poisoned Actions cache and an OIDC token taken from runner memory. An allowlist on the install step doesn't fix any of those.
For the last group, capyshield actions --fail-on high audits .github/workflows offline for unpinned actions, checkout credentials left on disk, missing or write-all permissions, pull request code checked out under pull_request_target, and untrusted github.event input run as shell. Egress control and workflow hygiene cover different halves of the same attack.
Frequently asked questions
- Can GitHub Actions runners connect to any host?
- A job can usually connect to any host on the internet unless you restrict it. An egress allowlist changes the default so only listed hosts are reachable.
- How do I generate an egress allowlist for my build?
- Run the build once with capyshield watch --emit-policy capyshield.yaml -- <command>. It records every host the command reached and writes an enforce-mode policy, which you review before committing.
- Should I allow github.com in my CI egress policy?
- Only if the build needs it. GitHub hosts serve content anyone can upload, and npm worms have used public GitHub repositories to publish stolen secrets. If you allow them, inspect request bodies for secrets.
- Does an egress allowlist protect uses: steps in GitHub Actions?
- Not when you enforce it by wrapping run: steps, because uses: steps run outside the wrapped command. Pin actions to a full commit SHA to protect those.