How AI agents can attack software supply chains and how to defend against them.
AI agents can attack software supply chains at every stage: they can poison training data, inject malicious code during generation, compromise build pipelines, and exfiltrate artifacts. This guide covers the attack vectors and practical defenses.
Supply Chain Attack Vectors for AI Agents
| Stage | Attack Vector | Impact |
|---|---|---|
| Training Data | Data poisoning, backdoor injection | Model learns malicious patterns |
| Model Supply | Compromised model weights, trojaned models | Backdoors in all generated code |
| Code Generation | Malicious code suggestions, vulnerable patterns | Insecure code deployed to production |
| Build Pipeline | CI/CD compromise, artifact tampering | Malicious artifacts distributed |
| Dependency | Typosquatting, dependency confusion | Malicious packages installed |
| Deployment | Container image tampering, config injection | Compromised runtime environment |
Defense 1: Model Provenance & Verification
Signed Model Artifacts
# cosign for model signing
cosign generate-key-pair
cosign sign --key cosign.key my-model:latest
# Verify before use
cosign verify --key cosign.pub my-model:latest
# Output: Verified signature for my-model:latest
SBOM for Models
# Generate model SBOM
syft my-model:latest -o spdx-json > model-sbom.spdx.json
# Check for known vulnerabilities
grype my-model:latest
Defense 2: Code Generation Guardrails
Semgrep Rules for AI-Generated Code
# .semgrep-rules/ai-generated.yaml
rules:
- id: ai-hardcoded-secret
pattern-either:
- pattern: $X = "sk-..."
- pattern: $X = "ghp_..."
- pattern: $X = "aws_access_key_id=..."
message: "Hardcoded secret detected in AI-generated code"
severity: ERROR
languages: [python, javascript, typescript, go, java]
- id: ai-sql-injection
pattern-either:
- pattern: "cursor.execute(f"...$X...")"
- pattern: "db.query(`...${X}...`)"
message: "Potential SQL injection in AI-generated code"
severity: ERROR
languages: [python, javascript, typescript]
- id: ai-path-traversal
pattern: "open($PATH, ...) where $PATH from user input"
message: "Path traversal risk in AI-generated file operations"
severity: WARNING
languages: [python, javascript, go]
Automated PR Checks for AI Commits
# .github/workflows/ai-supply-chain.yml
name: AI Supply Chain Security
on:
pull_request:
types: [opened, synchronize]
jobs:
supply-chain:
runs-on: ubuntu-latest
if: github.actor == 'copilot[bot]' || github.actor == 'dependabot[bot]' || contains(github.head_ref, 'ai-')
steps:
- uses: actions/checkout@v4
- name: Semgrep AI Rules
uses: returntocorp/semgrep-action@v1
with:
config: .semgrep-rules/ai-generated.yaml
- name: Dependency Scan
run: |
npm audit --audit-level=high || true
pip-audit --desc || true
cargo audit || true
govulncheck ./... || true
- name: Check for Typosquatting
uses: ossf/twosig-action@v1
- name: Verify Model Provenance
if: hashFiles('models/**') != ''
run: |
for model in models/*; do
cosign verify --key cosign.pub $model || exit 1
done
- name: Require Human Approval
run: |
echo "AI-generated changes require human review"
exit 1
Defense 3: Build Pipeline Integrity
SLSA Level 3 Build
# .github/workflows/slsa-build.yml
name: SLSA Build
on:
push:
tags: ['v*']
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
attestations: write
steps:
- uses: actions/checkout@v4
- name: Build with SLSA
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
with:
base64-subjects: ${{ hashFiles('**') }}
- name: Publish Provenance
uses: actions/attest-build-provenance@v2
with:
subject-path: dist/*
Reproducible Builds
# Dockerfile - reproducible
FROM python:3.11-slim@sha256:abc123... AS builder
# Pin all dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
FROM python:3.11-slim@sha256:abc123...
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY . /app
WORKDIR /app
USER 1000:1000
ENTRYPOINT ["python", "main.py"]
Defense 4: Dependency Security
Lockfiles & Hash Verification
# Python - pip-tools with hashes
pip-compile --generate-hashes requirements.in
# npm - package-lock.json v2+ with integrity
npm install --package-lock-only
# Go - go.sum verification
go mod verify
# Cargo - cargo.lock
cargo generate-lockfile
Private Registry with Proxy
# .npmrc
registry=https://private-registry.company.com
@company:registry=https://private-registry.company.com
//private-registry.company.com/:_authToken=${NPM_TOKEN}
# pip.conf
[global]
index-url = https://private-pypi.company.com/simple
trusted-host = private-pypi.company.com
Defense 5: Runtime Attestation
In-Toto Attestation
# Install in-toto
pip install in-toto
# Record build steps
in-toto-record start --step-name build --key build.key
# ... build commands ...
in-toto-record stop --step-name build --key build.key --materials requirements.txt --products dist/
# Verify at deploy
in-toto-verify --layout layout.json --layout-keys layout.pub
Sigstore Policy Controller (Kubernetes)
# policy.yaml
apiVersion: policy.sigstore.dev/v1beta1
kind: ClusterImagePolicy
metadata:
name: ai-agent-policy
spec:
images:
- glob: "**/ai-agent-*"
authorities:
- name: cosign-keyless
source:
keyless:
subject: "github.com/myorg/ai-agent"
issuer: "https://token.actions.githubusercontent.com"
verificationMode: enforce
Defense 6: Monitoring & Detection
Falco Rules for Supply Chain
# /etc/falco/rules.d/supply-chain.yaml
- rule: Unexpected Package Install
desc: Detect unauthorized package installation in CI/CD
condition: container and proc.name in (npm, pip, cargo, go) and not proc.pname in (github-actions, gitlab-runner, jenkins)
output: "Unexpected package install (user=%user.name cmd=%proc.cmdline container=%container.name)"
priority: WARNING
- rule: Artifact Tampering
desc: Detect modification of build artifacts
condition: open_write and fd.name in (/dist/, /build/, /artifacts/) and not proc.name in (expected-build-tools)
output: "Artifact tampering (file=%fd.name proc=%proc.name)"
priority: CRITICAL
- rule: Model Weight Modification
desc: Detect modification of model files
condition: open_write and fd.name endswith (.bin, .safetensors, .pt, .onnx) and not proc.name in (training-scripts)
output: "Model weight modification (file=%fd.name)"
priority: CRITICAL
Complete Supply Chain Security Checklist
| Control | Implementation | Maturity |
|---|---|---|
| Model signing | cosign + keyless signing | 🔴 Required |
| Model SBOM | syft + grype scanning | 🔴 Required |
| Code generation guardrails | Semgrep AI rules in CI | 🔴 Required |
| SLSA Level 3 builds | slsa-github-generator | 🟡 Recommended |
| Reproducible builds | Pinned base images, locked deps | 🟡 Recommended |
| Dependency proxy | Private registry with verification | 🟡 Recommended |
| In-toto attestation | Build provenance recording | 🟢 Advanced |
| Sigstore policy enforcement | Kubernetes admission controller | 🟢 Advanced |
| Runtime Falco monitoring | Supply chain specific rules | 🟡 Recommended |
Related Tools on DevStackIO
- Hash Generator — Generate checksums for artifacts
- JSON Schema Generator — Define artifact schemas
- CSP Generator — Lock down CI/CD web interfaces
References
- SLSA Framework — https://slsa.dev/
- Sigstore — https://www.sigstore.dev/
- in-toto — https://in-toto.io/
- Falco — https://falco.org/
- OWASP Software Supply Chain — https://owasp.org/www-project-software-supply-chain/
- NIST SSDF — https://csrc.nist.gov/projects/secure-software-development-framework