Where each test belongs
- Pull request: secret scanning, static analysis (SAST) and dependency checks. Fast, deterministic, source-only.
- After deploy to an ephemeral or staging environment: dynamic testing against the running application, focused on changed services.
- Nightly or weekly: a full dynamic run across the whole application, including adaptive exploitation.
- Before major releases: a scheduled deep run, with human review of high-severity findings.
Gating without breaking builds
Decide in advance which severity fails the job; high and above is a common starting point. Only gate on verified findings, otherwise a single false positive blocks a release and the team learns to bypass the check. Give dynamic jobs a hard time limit and a cost cap so a slow run cannot hold the pipeline hostage. Report everything below the gate, but do not fail on it.
Secrets, scope and test data
- Store model API keys and test credentials in the CI secret store, never in the workflow file.
- Pass scope explicitly, as the staging hostname, so a misconfigured variable cannot point the test at production.
- Use seeded test accounts and data that can be reset; dynamic tests may change state.
- Restrict who can trigger the job manually and edit its target variables.
Ephemeral environments make dynamic testing safer
If your platform can spin up a short-lived environment per branch or per release candidate, it is the ideal pentest target: production-like, isolated, seeded with known data and thrown away afterwards, so state changes from exploitation do not matter. Point the dynamic test at that environment's hostname, pass the same hostname as scope, and tear the environment down when the job ends. Where ephemeral environments are not available, use a shared staging environment and schedule runs outside working hours so testers and engineers are not tripping over each other.
Getting findings to developers
Emit results in SARIF so they appear in your platform's code scanning view next to static analysis findings, and keep the full report as a build artifact. Link each finding to the service owner. A pipeline that produces findings nobody sees has the same effect as no pipeline at all.
Pentest-Swarm in a pipeline
Pentest-Swarm is scriptable and emits SARIF, so it fits both halves of the design.
- Source-side:
pentestswarm playbook run ci-cd-security --target $STAGING_URL --scope $STAGING_HOSTruns gitleaks, trufflehog and semgrep and emits SARIF, with no traffic to production. - Dynamic:
pentestswarm scan $STAGING_HOST --scope $STAGING_HOST --safe-mode --budget 5 --followstreams plain log lines suited to CI. - A GitHub Action (beta) wraps the scan with a
fail-onseverity input and a SARIF output path. - Scope enforcement is fail-closed, so a wrong variable cannot widen the test beyond what you passed.
- Use
--mode asmfor a recon-only pass when you need surface mapping without active exploitation.
Where it falls short
The ci-cd-security playbook is source-side analysis (secrets, SAST, dependencies), not a dynamic pentest; you need a separate scan against a running environment for that. Adaptive runs take longer than a typical PR check and vary between runs, so they belong on a schedule or post-deploy step. If you need a sub-minute dynamic check on every pull request, a lightweight DAST baseline scan such as ZAP's is quicker.
Questions
Should I run a pentest on every pull request?
Usually not a full one. Run source-side checks on pull requests and dynamic testing after deploy or on a schedule.
What severity should fail the build?
Start with verified high and critical findings, and lower the threshold only once false positives are under control.
Can CI pentests run against production?
It is possible but risky. Prefer staging that mirrors production, and if you test production, use safe mode and an agreed window.