Skip to content
30 November 2026 An independent technology publication
Guide

GitHub Actions security: 10 essential fixes after the Trivy and Megalodon attacks

GitHub Actions security after the Trivy and Megalodon attacks: 10 essential fixes, from SHA pinning and read-only tokens to OIDC, CODEOWNERS and egress control.

GitHub Actions security: 10 essential fixes after the Trivy and Megalodon attacks, DevQuarry featured image

GitHub Actions security became a front-page problem in 2026. In March, attackers hijacked 75 of the 76 version tags of the popular Trivy scanning action and stole secrets from pipelines that trusted it. In May, a campaign called Megalodon pushed malicious workflow files into 5,561 repositories in about six hours. Neither attack needed a bug in GitHub itself. Both used ordinary features that most teams leave wide open.

The good news is that the fixes are well known and mostly free. This guide explains how the 2026 attacks worked and gives ten fixes in order of effort, from a five-minute settings change to a full move to short-lived credentials.

GitHub Actions security: 10 essential fixes after the Trivy and Megalodon attacks, DevQuarry featured image

The short version

  • Set the default GITHUB_TOKEN to read-only and grant permissions per job.
  • Pin third-party actions to full commit SHAs, and let Dependabot keep the pins current.
  • Remove risky pull_request_target workflows before GitHub blocks them on 2 December 2026.
  • Protect .github/workflows/ with CODEOWNERS and branch rules.
  • Replace long-lived cloud keys with OIDC, and gate deploy secrets behind environments.
  • Rotate personal access tokens, and watch what your runners connect to.

What happened to GitHub Actions security in 2026?

Two large attacks made GitHub Actions security a board-level topic and showed that CI pipelines are now a main target for supply chain attackers, because pipelines hold the keys to cloud accounts, package registries and production.

GitHub Actions security incidents: tj-actions changed-files in March 2025, Trivy action compromise in March 2026, Megalodon campaign in May 2026, pull_request_target blocked by default in December 2026
Date Incident How it worked
March 2025 tj-actions/changed-files A popular action’s tags were pointed at code that printed secrets into build logs
19 to 20 March 2026 Trivy action compromise Stolen token used to force-push 75 of 76 trivy-action tags to a credential stealer
18 May 2026 Megalodon Stolen developer tokens used to commit malicious workflows to 5,561 repositories
2 December 2026 GitHub default change pull_request_target blocked by default in public repositories

How did the Trivy compromise work?

According to Snyk’s write-up, the attack started on 28 February with a vulnerable pull_request_target workflow in the Trivy organisation, which let attackers steal an organisation-scoped personal access token. Credentials survived a rotation. On 19 March, the attackers force-pushed 75 of the 76 trivy-action version tags to malicious commits and published a poisoned Trivy binary.

The malicious code ran before the real scan, so pipelines looked normal. It read secrets from the runner’s memory on GitHub-hosted runners, searched more than 50 file paths for keys on self-hosted runners, and sent everything to a lookalike domain. Only users who had pinned the action to a full commit SHA were safe.

How did Megalodon work?

The Cloud Security Alliance research note describes Megalodon as direct poisoned pipeline execution. On 18 May 2026, between 11:36 and 17:48 UTC, attackers used stolen personal access tokens and deploy keys to push 5,718 commits to 5,561 repositories. The commits came from fake identities such as build-bot and used boring messages like “ci: add build optimization step.”

Two payloads were used. One added a new workflow that ran on every push and pull request. The other quietly changed existing workflows to run only on manual dispatch, so the attacker could trigger them later. Both collected cloud credentials from metadata services, SSH keys, Kubernetes configs, Terraform state credentials and GitHub’s OIDC tokens.

The lesson from both: GitHub Actions security depends on who can change your workflows, which code your workflows trust, and what a compromised job can reach.

How do attackers get into a GitHub Actions pipeline?

There are four common paths into a pipeline, and each GitHub Actions security fix in this guide closes at least one of them.

GitHub Actions security attack paths: moved action tags, stolen tokens that edit workflows, pwn requests through pull_request_target, and script injection from untrusted input, all leading to stolen secrets
Attack path Example Main fixes
A third-party action changes under you Trivy tags moved to malicious commits SHA pinning, Dependabot
Someone edits your workflow files Megalodon commits with stolen tokens CODEOWNERS, token rotation, branch rules
A fork pull request runs with secrets Pwn requests via pull_request_target Trigger changes, environments
Untrusted text runs as a shell command PR titles inside run: scripts Environment variables, linting

Fix 1: Make the GITHUB_TOKEN read-only by default

Every workflow run gets a GITHUB_TOKEN. If your organisation or repository still uses the old permissive default, that token can write to your code, releases and packages. Change the default to read-only, then grant extra permissions only to the jobs that need them.

GitHub Actions security setting: Workflow permissions in repository settings set to Read repository contents and packages permissions, with pull request approval by Actions unchecked

In Settings, open Actions, then General, and under Workflow permissions choose Read repository contents and packages permissions. Leave Allow GitHub Actions to create and approve pull requests unchecked unless a workflow really needs it.

Then declare permissions in each workflow:

permissions:
  contents: read

jobs:
  release:
    permissions:
      contents: write
    runs-on: ubuntu-latest

A stolen read-only token is close to worthless. That one GitHub Actions security setting limits the damage from most attacks.

Fix 2: Pin third-party actions to full commit SHAs

Version tags like @v3 can be moved to different code at any time by anyone with write access to the action’s repository. A full 40-character commit SHA cannot. This is the single most effective fix for GitHub Actions security against tag-hijacking attacks like Trivy.

- uses: example-org/scan-action@3f1c9e7a5b2d4c6e8f0a1b3c5d7e9f1a2b4c6d8e # v2.4.1

Keep the version as a comment so humans can read it. The action name and SHA here are examples; use the real SHA of the release you trust. To find the SHA for a tag, ask the repository directly:

GitHub Actions security in a terminal: git ls-remote lists the tags of an action with their commit SHAs, and the workflow line is pinned to the SHA with a version comment
git ls-remote --tags https://github.com/example-org/scan-action v2.4.1

Enforce SHA pinning with a policy

Organisation and repository owners can require pinning in the Actions policy settings, so a workflow that uses an action by tag fails instead of running. Turn it on in a test repository first, because every unpinned action will stop working.

GitHub Actions security policy: allowed actions settings with Require actions to be pinned to a full-length commit SHA enabled

GitHub’s 2026 security roadmap also describes dependency locking, a dependencies: section in workflow files that locks direct and transitive actions to SHAs. Until it is generally available in your organisation, manual pinning plus Dependabot is the practical approach.

Fix 3: Let Dependabot keep pinned actions up to date

Pinning without updates leaves you on old, possibly vulnerable versions, which is its own GitHub Actions security problem. Dependabot understands SHA-pinned actions and opens pull requests that update both the SHA and the version comment.

# .github/dependabot.yml
version: 2
updates:
  - package-ecosystem: "github-actions"
    directory: "/"
    schedule:
      interval: "weekly"

Review those pull requests like any other dependency change. Check the action’s release notes, especially for actions that handle secrets.

Fix 4: Remove risky pull_request_target workflows

The Trivy attack started with a pull_request_target workflow that ran code from a fork with access to secrets. GitHub will block that trigger by default in public repositories from 2 December 2026. Move build and test workflows to pull_request, split privileged steps into a workflow_run workflow, and keep pull_request_target only for tasks like labelling that never run contributor code. Our step-by-step pull_request_target migration guide covers every case.

Fix 5: Protect your workflow files with CODEOWNERS and rules

Megalodon worked because stolen tokens could push workflow changes straight to repositories. Make workflow changes go through review:

  • Add a CODEOWNERS entry such as /.github/workflows/ @your-org/platform-team.
  • Turn on a branch ruleset for the default branch that requires pull requests and code owner review.
  • Block direct pushes and force pushes to the default branch.
  • Alert on new or changed files under .github/workflows/ in repositories that rarely change them.

With these rules, an attacker holding a developer’s token still needs a code owner to approve a malicious workflow, which is much harder to do quietly.

Fix 6: Replace long-lived secrets with OIDC

Long-lived cloud keys stored as repository secrets are the prize in almost every pipeline attack, which makes them the biggest GitHub Actions security risk after workflow access. OpenID Connect (OIDC) lets a workflow ask your cloud provider for short-lived credentials at run time instead.

GitHub Actions security with OIDC: the workflow requests a signed token from GitHub, the cloud provider checks the repository, branch and environment claims, then returns short-lived credentials that expire after the job

For AWS, the workflow looks like this:

permissions:
  id-token: write
  contents: read

steps:
  - uses: aws-actions/configure-aws-credentials@v5
    with:
      role-to-assume: arn:aws:iam::123456789012:role/deploy-main
      aws-region: ap-south-1

On the cloud side, restrict the role’s trust policy to your repository and to the branch or environment that should deploy. Megalodon’s payload collected OIDC tokens too, so short-lived credentials are not magic. They expire quickly and they can be limited to one job’s purpose, which makes them far less useful to an attacker.

Fix 7: Gate deploy secrets behind environments

GitHub environments let you attach secrets to a named target, such as production, and require a reviewer to approve each job that uses it. Only jobs that declare environment: production can read those secrets, and only after approval.

Setting Recommended value
Required reviewers At least one person outside the author of the change
Deployment branches Only the default branch or release tags
Wait timer Optional, useful for staged rollouts
Environment secrets Production credentials only; never in repository secrets

This adds a human check between untrusted code and your most valuable secrets.

Fix 8: Stop script injection from untrusted input

Pull request titles, branch names and issue bodies are attacker-controlled. If a workflow pastes them straight into a shell command with ${{ }}, an attacker can run their own commands.

Unsafe:

- run: echo "Title: ${{ github.event.pull_request.title }}"

Safe:

- env:
    PR_TITLE: ${{ github.event.pull_request.title }}
  run: echo "Title: $PR_TITLE"

Passing untrusted values through environment variables keeps them as data. Static analysis tools such as actionlint and zizmor flag this pattern and many others, and both run quickly in CI.

Fix 9: Watch what your runners connect to

Every 2026 attack ended with stolen data leaving a runner over the network. Monitoring outbound connections catches that last step even when everything before it went unnoticed.

  • On GitHub-hosted runners, third-party runtime monitors can log and block unexpected outbound traffic. StepSecurity spotted both the Trivy and Megalodon campaigns this way.
  • GitHub’s roadmap includes a native Layer 7 egress firewall for hosted runners, planned for public preview later.
  • On self-hosted runners, use ephemeral runners that are destroyed after each job, and never attach self-hosted runners to public repositories.

Fix 10: Rotate tokens and use narrower credentials

Megalodon’s initial access came from personal access tokens and deploy keys, probably stolen by malware on developer machines. Reduce how much a stolen token can do:

Credential Better choice
Classic personal access tokens Fine-grained tokens limited to specific repositories, with expiry dates
Shared bot accounts A GitHub App with only the permissions it needs
Deploy keys with write access Read-only deploy keys, or a GitHub App
Organisation-wide tokens in workflows Repository-scoped tokens or OIDC

Set expiry on every token, rotate them on a schedule, and rotate immediately after any laptop compromise. The Trivy attackers succeeded partly because a credential survived a rotation, so check that old tokens are really revoked.

How do I check my GitHub Actions security quickly?

Run a short GitHub Actions security audit before deciding where to start. These checks take less than an hour for most repositories.

GitHub Actions security priorities: quick wins like read-only token and pull_request_target review, then SHA pinning and CODEOWNERS, then OIDC, environments and egress monitoring
Check How
Token default Settings, Actions, General, Workflow permissions
Unpinned actions grep -RIn "uses: .*@v" .github/workflows
Risky triggers Search for pull_request_target and workflow_run
Script injection Run zizmor or actionlint over .github/workflows
Secrets inventory Settings, Secrets and variables, Actions; delete anything unused
Workflow file owners Check that CODEOWNERS covers .github/workflows/

OpenSSF Scorecard also scores repositories on many of these practices and runs as an action itself.

GitHub Actions security for self-hosted runners

Self-hosted runners change the GitHub Actions security picture. They run on your own machines or cloud accounts, so a compromised job can reach whatever that machine can reach: internal networks, cloud metadata services and other workloads on the same host. The Trivy payload searched more than 50 paths for credentials on self-hosted runners, and Megalodon queried cloud metadata services for instance credentials.

Risk Safer setup
Runner reused across jobs Ephemeral runners that are created for one job and destroyed after
Runner attached to a public repository Never do this; anyone can open a pull request that runs on your machine
Broad instance role on a cloud runner A minimal role, with deploy credentials coming from OIDC per job
Open outbound internet access Allow-list the hosts builds really need, such as package registries
Long-lived runner registration tokens Register runners automatically with short-lived tokens

Tools such as Actions Runner Controller on Kubernetes make ephemeral runners practical at scale. They also make it easier to apply network policies per runner pool.

A GitHub Actions security baseline for teams

Individual fixes are easier to keep when they are written down as a baseline that every new repository starts with. Here is a practical baseline for a small or mid-sized organisation:

Area Baseline rule Where to set it
Token Default GITHUB_TOKEN read-only Organisation Actions settings
Actions Third-party actions pinned to SHAs; allow-list approved publishers Organisation Actions policy
Updates Dependabot for github-actions weekly .github/dependabot.yml template
Triggers No pull_request_target without security review Event policy and code review
Workflow changes CODEOWNERS review for .github/workflows/ Repository template and rulesets
Cloud access OIDC only; no long-lived cloud keys in secrets Cloud IAM and secret scanning
Production Environment with required reviewers Repository environments
Checks zizmor or actionlint runs on every pull request Shared reusable workflow

Put the configuration files in a repository template, so new projects start secure instead of being fixed later. Review the baseline every quarter, because GitHub is adding new controls throughout 2026 and 2027.

Common GitHub Actions security mistakes

Most real incidents trace back to a short list of habits. These are the ones that come up most often in incident write-ups and audits:

Mistake Why it is risky
Using @main or @master for third-party actions Any new commit runs in your pipeline immediately
Printing secrets while debugging Masking can fail for transformed values, and logs persist
Storing a personal access token as a repository secret The token usually has far more access than the workflow needs
One AWS role for every workflow A test job can deploy to production
Ignoring Dependabot pull requests for actions Pins drift to old versions with known problems
Leaving unused secrets in place Old credentials are still valid if stolen

Fixing these does not require new tools, only review time.

What should I do if an action I use is compromised?

Act as if every secret the affected workflows could read has been stolen, because in the Trivy and Megalodon cases that is what happened. A clear response order keeps the damage small:

  1. Stop the bleeding. Disable the affected workflows or pin the action to a known-good SHA published by the maintainers.
  2. Find the exposure window. List every workflow run that used the compromised version, with dates, from the Actions run history.
  3. Rotate secrets. Rotate every secret and token those runs could access, including cloud keys, registry tokens and personal access tokens. Revoke the old values; do not just add new ones.
  4. Check for persistence. Look for new workflow files, new deploy keys, new repositories in your account (the Trivy attackers created ones named tpcp-docs) and unexpected releases.
  5. Check downstream. If you published packages or images during the window, check whether they include anything unexpected, as happened with the Tiledesk npm package in Megalodon.
  6. Write it down. Record what you rotated and when, so the next review starts from facts.

Practise this once on a quiet day, ideally with the people who own your cloud accounts in the room. A GitHub Actions security incident is stressful, and a written checklist makes the difference between a two-hour fix and a two-week cleanup.

What is GitHub changing next?

GitHub published a 2026 Actions security roadmap in March. Its main items:

Feature What it does
Dependency locking Locks direct and transitive actions to commit SHAs in the workflow file
Workflow execution policies Rulesets for which events and actors can run workflows, with an evaluate mode
Scoped secrets Binds secrets to specific repositories, branches, environments or reusable workflows
Secrets permission Separates secret management from write access with a dedicated role
Native egress firewall Monitors and enforces outbound traffic on GitHub-hosted runners

The roadmap gave timelines in months rather than dates. The pull_request_target default block is the first of these controls to reach every public repository, and more defaults are likely to follow.

Frequently asked questions

What is the most important GitHub Actions security fix?

For most teams, setting the GITHUB_TOKEN to read-only and pinning third-party actions to full commit SHAs. Together they block the most common attacks of 2025 and 2026.

Is pinning to a major version tag like @v4 safe?

No. Tags can be moved. In the Trivy attack, 75 of 76 tags were moved to malicious code. Only a full 40-character commit SHA is immutable.

Are GitHub’s own actions safe to use by tag?

Actions under the actions/ organisation are maintained by GitHub and are lower risk, but pinning them to SHAs costs nothing with Dependabot handling updates. Many teams pin everything for consistency.

Does OIDC remove the need for secrets?

It removes long-lived cloud keys from your repository. You still need to restrict the cloud role to the right repository and branch, because a compromised job can still use the short-lived credentials while it runs.

How did Megalodon get access to so many repositories?

Through stolen personal access tokens and deploy keys, most likely taken from developer machines by malware. It did not exploit a GitHub vulnerability.

Should I use self-hosted runners for better security?

Not automatically. Self-hosted runners give you control over the network but add their own risks. Use ephemeral runners and never attach them to public repositories, where anyone can trigger jobs.

What tools check GitHub Actions workflows for security problems?

zizmor and actionlint analyse workflow files for issues such as script injection and risky triggers. OpenSSF Scorecard rates repositories on wider practices, and Dependabot keeps pinned actions updated.

Does GitHub Actions security differ for private repositories?

The same attacks apply, but some defaults differ. The December 2026 pull_request_target block covers public repositories only, so private repositories need the same review done manually.

Can GitHub Actions security tools block a compromised action automatically?

Partly. Runtime monitors can block unexpected outbound connections, which stops many credential stealers from sending data. SHA pinning prevents a moved tag from running in the first place. No single tool covers every path, so combine prevention with monitoring.

How often should I rotate GitHub tokens?

Set expiry dates on all fine-grained tokens, typically 30 to 90 days, and rotate immediately after any suspected compromise of a developer machine. Prefer GitHub Apps and OIDC, which avoid long-lived tokens altogether.

Start with the five-minute fixes

GitHub Actions security does not need a big budget. The two fixes that would have stopped most of 2026’s damage, a read-only token and SHA pinning, take minutes per repository. Do those this week, handle pull_request_target before 2 December, and then plan the bigger moves: OIDC, environments and CODEOWNERS. If your pipelines also broke recently for less dramatic reasons, our guide to the ubuntu-latest move to Ubuntu 26.04 explains what changed on GitHub’s runners.

About the author Aradhya Chaudhary

Data Scientist | Freelancer | Speaker & Writer skilled in programming, development and building AI/ML backed systems.

More from Aradhya
Keep reading

More in Cloud & DevOps

All of Cloud & DevOps →