Pipeline security: the last line of defence against AI code
, 4 min read
Code review used to be the main security gate. A second engineer read the diff and caught the injection or the missing check. That still works, but it scales with people. AI assistants make code faster to write: in a controlled GitHub experiment, developers with Copilot finished a set task 55.8% faster than those without it. Diffs get bigger and more frequent, and review gets thinner. Research on assistant users also found that people trust generated code more than it deserves.
A pipeline doesn't get tired and doesn't skim. It applies the same rules to every change. That makes it the one security control that keeps up with the volume.
Four layers
1. On the developer's machine
Fast checks that stop the worst mistakes before they reach the repository: secret scanning and a small set of high-confidence rules. With the pre-commit framework:
# .pre-commit-config.yaml
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.30.1
hooks:
- id: gitleaksPre-commit hooks can be skipped, so treat this layer as a courtesy. The next layer is the gate.
2. On every pull request
This is where the build fails. Run these as parallel jobs:
- SAST: Semgrep, CodeQL or similar, with an OWASP-focused ruleset
- Secret scanning across the full history of the branch
- Dependency review: new packages, known-vulnerable versions, licence issues
- Container image scanning, if the change touches a Dockerfile
- Infrastructure-as-code scanning, if it touches Terraform or Kubernetes manifests
name: security
on: pull_request
permissions:
contents: read
jobs:
sast:
runs-on: ubuntu-latest
container: semgrep/semgrep
steps:
- uses: actions/checkout@<commit SHA> # v6
- run: semgrep scan --config p/owasp-top-ten --error
secrets:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@<commit SHA> # v6
with:
fetch-depth: 0
- uses: gitleaks/gitleaks-action@<commit SHA> # v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
dependencies:
runs-on: ubuntu-latest
steps:
- uses: actions/dependency-review-action@<commit SHA> # v5
with:
fail-on-severity: highBranch protection should make these checks required. A security job that can be ignored is a report, not a gate.
3. Against staging
Some flaws only appear when the application runs: missing authorisation checks, insecure headers, CORS mistakes, session handling. A DAST scan, such as ZAP's baseline or full scan, runs against the staging deployment after merge and blocks promotion to production on high findings. Add a small set of authorisation tests of your own: log in as one user and try to read another user's data. Scanners are weak at that class of bug.
4. In production
The pipeline's output is only as secure as what's known today. An SBOM (CycloneDX or SPDX) stored for every release lets you answer "are we running the version from today's advisory?" in minutes. Pair it with continuous dependency monitoring, so a CVE published after release still raises an alert.
Secure the pipeline itself
A security pipeline that can be hijacked is worse than none. It runs with your repository's credentials in reach. In March 2026, attackers force-pushed 76 of the 77 version tags of the aquasecurity/trivy-action GitHub Action to credential-stealing code. Every pipeline that pulled the scanner by tag during those hours ran the attacker's code. The controls that prevent this are the same ones you'd apply anywhere:
- Pin every third-party action to a full commit SHA, with a bot to keep pins current.
- Declare
permissions:in every workflow, read-only by default. - Use OIDC for cloud access instead of long-lived keys stored as secrets.
- Don't run scanners with more access than they need. A SAST job needs to read code, not deploy it.
Keeping it quiet enough to trust
A gate that fires on everything gets bypassed. Keep the signal clean:
- Block on high-confidence, high-severity findings only. Report the rest as pull-request comments.
- Allow reviewed, inline exceptions with a reason, so false positives don't turn into disabled rules.
- Track two numbers: how often the gate blocks, and how often a block turns out to be wrong. If the second one climbs, tune the rules before people stop reading the output.
Custom rules for patterns you keep seeing
Public rulesets cover the general cases. When assistants keep producing the same mistake in your codebase, write a rule for it. For example, a signing call with a hard-coded string secret:
rules:
- id: jwt-hardcoded-secret
languages: [javascript, typescript]
pattern: jwt.sign($PAYLOAD, "...", ...)
message: JWT signed with a hard-coded secret. Load it from the environment or a secret manager.
severity: ERROREach new rule turns one reviewer's catch into a check that runs on every future change.
Sources
- Peng et al. — The Impact of AI on Developer Productivity: Evidence from GitHub Copilot
- Perry et al. — Do Users Write More Insecure Code with AI Assistants? (ACM CCS 2023)
- GitHub docs — Secure use reference for GitHub Actions
- Aqua Security — Trivy ecosystem supply chain temporarily compromised (CVE-2026-33634)
- Semgrep docs — Sample CI configurations
- GitHub — dependency-review-action
- Gitleaks
- ZAP — Baseline scan
- CycloneDX specification