Security Testing in Your CI/CD Pipeline: Where Automated Pentesting Fits
Continuous security testing in a CI/CD pipeline means running different security checks at different stages: fast static checks (secrets, dependencies, IaC) on every commit or pull request, lightweight dynamic scans against staging after deploy, and deeper automated pentesting against the deployed, internet-facing environment on a schedule and after releases. The mistake most teams make is trying to fit all of it into the build. Pentest-style testing needs a running system and takes longer than anyone wants to wait on a PR, so it belongs after deploy, not as a merge gate.
This post maps each type of test to a pipeline stage, gives working GitHub Actions examples, and explains where automated penetration testing fits alongside the tools you probably already run.
Continuous security testing in CI/CD: the pipeline map
Here's the layout we recommend. Each stage has a time budget, because a security check that adds 20 minutes to every PR will get disabled within a month.
| Stage | What to test | Example tools | Time budget | Block the pipeline? |
|---|---|---|---|---|
| Pre-commit / PR | Hardcoded secrets in the diff | Gitleaks, pre-commit hooks | Seconds | Yes, on any secret |
| PR / build | Dependencies (SCA), code patterns (SAST), IaC policies | Dependency scanners, Semgrep, Checkov-style IaC scanners | 1–5 min | On critical/high, with an exceptions file |
| Deploy to staging | Passive DAST: headers, cookies, info leaks | ZAP baseline scan | A few minutes | Only on rules you've explicitly set to FAIL |
| Post-deploy (staging) | Active DAST against non-production | ZAP full scan, authenticated scanners | 10–60+ min | No, file tickets |
| Post-deploy (production, external) | Attack surface changes, exposed services, secrets in bundles, cloud exposure, chained issues | Automated/agentic pentesting, ASM | Runs on its own schedule | No, alert and ticket |
| Periodic | Human-verified, authenticated pentest | Engineer-led test | Days | No, it gates releases via your process, not CI |
The rule behind the table: the closer a check is to the developer, the faster and more precise it has to be. The further right you go, the more it can afford to explore.
Stage 1: Secrets, before they ever land
Secrets in git history are effectively permanent. Rotating the key is the only real fix, so catch them early. Gitleaks' GitHub Action runs on PRs and pushes:
name: gitleaks
on:
pull_request:
push:
workflow_dispatch:
schedule:
- cron: "0 4 * * *" # daily at 04:00 UTC
jobs:
scan:
name: gitleaks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: gitleaks/gitleaks-action@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }} # orgs only
fetch-depth: 0 pulls full history so the scan sees more than the latest commit. Per the action's README, GITLEAKS_LICENSE is required for organization repos, not personal accounts.
Pipeline secret scanning only sees the repo. It won't catch a key injected at build time through an environment variable and then shipped in a minified JavaScript bundle. That's a post-deploy problem, covered below and in scanning JavaScript bundles for leaked API keys.
Stage 2: Dependencies, code and infrastructure-as-code
This is the most mature part of DevSecOps and most teams have something in place. Two practical notes:
- Gate on severity and reachability, not on count. A pipeline that fails on every medium-severity transitive dependency trains people to add
|| true. - Scan IaC before
terraform apply, not after. A public S3 bucket caught in a PR costs a one-line fix. Caught in production, it's an incident review. See infrastructure as code security scanning for the checks that matter most.
Stage 3: Passive DAST after deploy to staging
Once the app is running, dynamic checks become possible. ZAP's baseline scan is built for this stage. According to the ZAP docs, it spiders the target for one minute by default, then waits for passive scanning to finish. It doesn't perform attacks, finishes in a few minutes at most, and is "intended to be ideal to run in a CI/CD environment, even against production sites."
Run it with Docker:
docker run -v $(pwd):/zap/wrk/:rw -t ghcr.io/zaproxy/zaproxy:stable zap-baseline.py \
-t https://staging.example.com -g gen.conf -r testreport.html
-g gen.conf writes a default config with every rule set to WARN. Edit it to promote the rules you care about to FAIL (or IGNORE the noise), then pass it back with -c. By default the baseline reports everything as a warning, so out of the box it won't block anything.
In GitHub Actions, the official ZAP baseline action does the same thing and keeps a GitHub issue updated with alerts:
- name: ZAP baseline scan
uses: zaproxy/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
docker_name: 'ghcr.io/zaproxy/zaproxy:stable'
target: 'https://staging.example.com'
rules_file_name: '.zap/rules.tsv'
cmd_options: '-a'
ZAP also has a full-scan action that runs active attacks. Its README carries a warning that it "will perform attacks on the target website". Point it only at environments you own and are prepared to have modified, never at production by default.
Stage 4: Where automated pentesting fits
Everything above tests the artifact you built. Penetration testing tests the system you exposed, and those are not the same thing. Plenty of real exposure never passes through your pipeline:
- A subdomain created in the DNS console for a vendor integration
- A dangling CNAME left behind after a service was deleted (subdomain takeover)
- A storage bucket made public by hand during an incident
- A staging environment someone exposed to share with a customer
- An outdated reverse proxy or admin panel no repo deploys
- A newly published CVE affecting a version you were already running
Your CI/CD pipeline has no idea any of these exist. That's why automated pentesting belongs outside the build, running against the deployed, external surface:
- On a schedule (daily or weekly discovery, weekly testing), so it catches drift no pipeline triggered.
- After a release, as a post-deploy step or a manual trigger, so major changes get tested within hours.
- With results going to the same place as your CI findings, so there's one backlog, not two.
A practical pattern is to keep the post-deploy job non-blocking. Deploy finishes, the external test runs, and new high or critical findings open tickets and page the owning team. Blocking a deploy on a test that takes 30 minutes and covers infrastructure the deploy didn't touch causes more problems than it solves.
Stage 5: Human-verified testing
Neither CI scanners nor automated pentesting reliably catch authorization flaws between roles, IDOR across tenants, or business-logic abuse. Those need someone who understands how the product is supposed to behave. Schedule an authenticated, engineer-led test at least annually and before releases that change authentication, payments or multi-tenancy. How often you should run a penetration test goes into the triggers, and automated vs manual penetration testing breaks down which issues fall on which side.
Common mistakes
- Blocking on everything. Pick a small set of FAIL conditions you will actually enforce. Everything else is a ticket.
- Scanning only staging. Staging rarely matches production DNS, CDN, WAF and cloud config. Test production's external surface too, using read-only, non-destructive checks.
- No owner for findings. A security issue in a GitHub issue with no assignee is the same as no finding.
- Treating "the pipeline is green" as "we're secure." A green pipeline means the checks you configured passed. It says nothing about the assets the pipeline doesn't know about.
How SecurityInfinity fits into this setup
SecurityInfinity covers the post-deploy, external layer. Autonomous AI agents run recon, web, network and secrets checks against domains you've verified with a DNS TXT record or matching work email. Scans are read-only, so they're safe against production. The agent pivots on what it finds, for example from a leaked hostname in a JS bundle to testing that host. Every finding includes evidence and exact remediation, ordered by severity. Relevant scanners include js-secrets-scanner, subdomain-takeover, cloud-misconfigs and deep-security-scan. On the code side there are ai-sast-secret-scan and infra-as-code-audit.
The Pro plan ($9/month, see /pricing) adds continuous monitoring and re-scans plus Jira export, so findings land in the same backlog as your CI results. For the human layer, the Startup Pentest delivers an engineer-verified report and attestation letter in 3 business days.
To see what your pipeline isn't catching, run a scan against your production domain.
Frequently asked questions
What is continuous security testing in CI/CD?
It's the practice of running security checks automatically at each stage of delivery: secret and dependency scanning on commits, IaC checks on PRs, DAST after deploy, and automated pentesting against the deployed environment on a schedule. The goal is to catch issues at the cheapest point to fix them without slowing every build.
Should penetration testing run inside the CI/CD pipeline?
Usually not as a blocking step. Pentest-style testing needs a running system, takes longer than a PR check should, and covers assets the pipeline doesn't deploy. Run it after deploy and on a schedule, and send findings to the same backlog as your CI results.
Is DAST the same as automated penetration testing?
No. DAST tools like the ZAP baseline scan test a given URL for known issue patterns. Automated penetration testing also discovers assets you didn't list, chains findings together and verifies them with evidence, closer to how an attacker works.
Can I run security scans against production from CI?
Passive and read-only checks, yes. ZAP's documentation describes its baseline scan as suitable even against production sites. Active attack scans should target environments you own and can afford to have modified, usually staging.
Does CI/CD security testing replace an annual pentest?
No. Pipeline checks and automated testing reduce how much a human tester has to find, but auditors and enterprise customers still expect a formal pentest report, and authorization and business-logic flaws still need human testing.