/

CVE-2026-40316

Severity:

HIGH RISK

(8.8)

Code Injection / Insecure CI Workflow in OWASP BLT GitHub

CVE-2026-40316

Analyzed

Vulnerability type

Category:

Code Injection / Insecure CI Workflow

CWE:

CWE-94, CWE-95

Impact:

Remote Code Execution in CI with Repository Token and Secrets Exposure

Severity:

HIGH RISK

(8.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

OWASP BLT versions prior to 2.1.1 contain a code injection vulnerability in a GitHub Actions workflow that regenerates Django migrations using attacker-controlled model files from untrusted pull requests.

When a maintainer labels an external pull request for migration regeneration, arbitrary Python code in the contributor's models.py can execute in the privileged CI environment, exposing repository secrets and the GITHUB_TOKEN to potential compromise.

Affected context

This vulnerability appears in the CI/CD context of OWASP BLT's GitHub repository, specifically within the .github/workflows/regenerate-migrations.yml workflow.

It is relevant when:

  • The repository is hosted on GitHub and GitHub Actions are enabled.
  • The pull_request_target trigger is used for the regenerate-migrations workflow.
  • The workflow copies files from an untrusted pull request (via git show or equivalent) into the trusted runner workspace.
  • The workflow runs python manage.py makemigrations against those files, causing Django to import attacker-controlled model modules.

The risk manifests primarily for public or externally-contributed repositories where maintainers apply the regenerate-migrations label to pull requests from untrusted contributors.

Exploit preconditions

  • Attack surface: GitHub Actions CI environment for the OWASP BLT repository.
  • Required access: Ability to open a pull request from a fork or external branch (no prior write access to the target repository is required).
  • Maintainer interaction: A maintainer must apply the regenerate-migrations (or equivalent) label so the vulnerable workflow runs against the attacker's pull request.
  • Trigger point: Execution of the .github/workflows/regenerate-migrations.yml workflow using pull_request_target, which checks out privileged code and copies PR content (including website/models.py) into the runner workspace.
  • Why exploitation is possible: The workflow implicitly trusts and executes attacker-supplied Python modules as part of Django's migration generation process. Because the workflow runs in the context of the base repository with a write-scoped GITHUB_TOKEN and access to repository secrets, any module-level code in the attacker's models.py is executed with these elevated privileges.

Why this happens

The core issue is the unsafe combination of:

  • GitHub Actions' pull_request_target trigger, which runs with the base repository's security context, and
  • Execution of untrusted code originating from a pull request within that privileged context.

This aligns with CWE-94: Improper Control of Generation of Code ('Code Injection'), as attacker-controlled Python code is loaded and executed during Django's model import process. By copying files from the untrusted pull request into the trusted workspace and running python manage.py makemigrations, the workflow effectively treats untrusted PR content as trusted application code.

The presence of CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection') is conceptually related: arbitrary Python directives within the attacker's module are respected at import time. However, the primary bug class is the design flaw of executing untrusted code in a high-privilege CI environment, rather than any specific misuse of eval() or similar functions.

Abstractly, the insecure pattern is: "CI pipeline executes or imports artifacts derived from untrusted pull request content while running under the base repository's identity and permissions, without isolation, policy checks, or trust boundaries."

Potential impact

  • Exfiltration of the repository's GITHUB_TOKEN, enabling:
  • Force-pushing malicious commits.
  • Modifying workflows to retain long-term CI compromise.
  • Creating or modifying releases and tags for supply chain attacks.
  • Access to, and exfiltration of, GitHub Actions secrets configured on the repository or organization.
  • Tampering with source code or configuration files in the repository using the write-scoped GITHUB_TOKEN.
  • Insertion of backdoors or malicious logic into the project, leading to downstream supply chain compromise for users of OWASP BLT.
  • Abuse of the CI runner environment (within the limits of GitHub's isolation) to perform further network reconnaissance or attacks on allowed endpoints.

General mitigation guidance

Effective mitigation focuses on re-establishing a strict trust boundary between untrusted pull request content and privileged CI execution:

  • Avoid pull_request_target for workflows that build or execute PR code:
  • Prefer pull_request or similar triggers that run in the context of the fork, with a minimized GITHUB_TOKEN and no access to repository secrets.
  • Do not execute code directly from untrusted pull requests in a privileged context:
  • Only operate on trusted base-branch code when running commands like python manage.py makemigrations.
  • If PR content must be inspected, treat it as data, not executable code (e.g., parse or lint, but do not import or run it).
  • Minimize permissions for workflow tokens and secrets:
  • Use permissions: in workflow definitions to restrict the GITHUB_TOKEN scopes to the minimum required.
  • Avoid exposing organization or environment-level secrets to workflows that can be triggered from untrusted sources.
  • Introduce review or gating mechanisms for dangerous automation:
  • Require explicit, documented human review before running workflows that might execute contributed code, and consider running them locally or in isolated environments.
  • Isolate build and test environments:
  • Where possible, separate workflows that execute untrusted code from those that require privileged repository access, using different triggers, tokens, or environments.

These patterns are generally applicable to any CI/CD system that processes contributions from untrusted users, not just GitHub Actions.

How teams detect issues like this

Detection can focus on both configuration-level and behavioral signals:

  • Static analysis of CI configuration:
  • Scan .github/workflows/*.yml for:
  • Use of pull_request_target or equivalent high-privilege triggers.
  • Steps that checkout or otherwise incorporate PR content into a workspace with write-scoped GITHUB_TOKEN.
  • Direct execution or import of code drawn from PR branches (e.g., python manage.py, npm test, build commands) under these triggers.
  • Flag workflows that both:
  • Have elevated permissions (permissions: write-all or broad defaults), and
  • Consume artifacts or files from untrusted branches.
  • Policy enforcement in CI/CD:
  • Enforce organizational policies that prohibit running untrusted code under pull_request_target or similar triggers.
  • Require security review for workflows that access repository secrets.
  • Code review checklists:
  • Include CI configuration review in pull request templates and checklists, specifically checking for:
  • Execution of untrusted code,
  • Unnecessary secrets exposure,
  • Overly broad GITHUB_TOKEN permissions.
  • Automated tools:
  • Use CI security scanners or GitHub Action linters that understand CI threat models (e.g., misuse of pull_request_target) to automatically detect similar patterns in workflows.

Sources

SourceLink
github.comgithub.com/OWASP-BLT/BLT/security/advisories/GHSA-wxm3-64fx-cmx9

Frequently asked

questions

Any external contributor who can open a pull request against an affected OWASP BLT repository and whose PR receives the regenerate-migrations label can potentially exploit this issue. The limiting factor is maintainer action: a maintainer must apply the label to trigger the vulnerable workflow.

No repository write access is needed. A standard GitHub account with the ability to submit a pull request from a fork is sufficient. The attack leverages the repository's own CI permissions granted to the workflow, not the attacker's account privileges.

The safest pattern is to prevent execution of untrusted PR code under high-privilege contexts. Concretely, avoid using pull_request_target (or equivalent) for workflows that build or execute PR content, minimize the permissions of any tokens used in workflows, and ensure that any privileged automation only processes trusted base-branch code.

Adopt a defense-in-depth CI strategy:

  • Treat all PR content as untrusted and isolate its execution from secrets and write-capable tokens.
  • Use restrictive permissions: settings and separate workflows for trusted vs. untrusted tasks.
  • Regularly review and statically analyze CI configurations for patterns like pull_request_target misuse.
  • Incorporate CI security checks into code review practices and automated pipeline governance.
Find out what's already
exploitable in your codebase.