QA and Test Automation · Lab 28 of 35
OWASP ZAP Baseline Scan in Docker and CI: ShopRung Lab
Scan your own copy of ShopRung with the OWASP ZAP baseline scan in Docker: read the 6 warnings it found, triage them into a rules file that fails the build on the ones that must never come back, learn what a passive scan cannot find, and run it weekly in GitHub Actions.
⏱ 45 minBeginner💸 Free6 steps
OWASP ZAP (ghcr.io/zaproxy/zaproxy:stable)Docker ComposeGitHub ActionsShopRung
Overview video
What you will build
A security scan you can run with one command and trust in CI:
compose.zap.yaml: ShopRung in a container, and ZAP's baseline scan pointed at it on a private network, writing HTML, JSON and Markdown reports.- The real result on ShopRung: 62 rules passed, 6 warnings, among them a missing Content-Security-Policy, anti-clickjacking header and X-Content-Type-Options.
zap/rules.tsv: your triage. One finding FAILs the build, one is IGNOREd with a reason, the rest stay warnings.- A weekly GitHub Actions job, and a clear list of what a passive scan cannot find.
Before you start
- The episode behind it: Security testing basics.
- Docker with Compose, and the
shoprung-qafolder (at leastshoprung/) from Tests inside Docker. - Only scan systems you own or have written permission to test. ShopRung on your machine is yours.
Setup
S1Check Docker
Start Docker Desktop (or the Docker service), then check Compose answers.
docker compose version Docker Compose version v2...
S2Pull the ZAP image
The ZAP image is large (about 1.5 GB). Pull it once now so the scan itself starts quickly.
docker pull ghcr.io/zaproxy/zaproxy:stable stable: Pulling from zaproxy/zaproxy ... Status: Downloaded newer image for ghcr.io/zaproxy/zaproxy:stable
ShopRung and ZAP, side by side
A Compose file that scans a fresh ShopRung on a private network.
In shoprung-qa, create compose.zap.yaml and a folder zap with the file rules.tsv. The shoprung service is the same health-checked container as in the Docker lab. The zap service waits until ShopRung is healthy, then runs zap-baseline.py against http://shoprung:8080, the service name on the Compose network.
The zap folder is mounted as /zap/wrk, ZAP's working folder: it reads rules.tsv from there and writes its reports there. For now rules.tsv holds only comments, so every rule keeps its default.
A baseline scan is passive: ZAP crawls the site with its spider and inspects the responses (headers, cookies, error pages, leaked information) without attacking anything. That is why it is safe to run often.
# An OWASP ZAP baseline scan of ShopRung: passive checks only, safe to run against your own test copy.
# docker compose -f compose.zap.yaml run --rm zap
# docker compose -f compose.zap.yaml down -v
services:
shoprung:
build: ./shoprung
healthcheck:
test: ["CMD", "wget", "-qO-", "http://localhost:8080/api/health"]
interval: 2s
timeout: 3s
retries: 15
zap:
image: ghcr.io/zaproxy/zaproxy:stable
depends_on:
shoprung:
condition: service_healthy
volumes:
- ./zap:/zap/wrk:rw
command: zap-baseline.py -t http://shoprung:8080 -r zap-report.html -J zap-report.json -w zap-report.md -c rules.tsv - Scan only once ShopRung answers its health check.line 17
- Your zap folder: rules in, reports out.line 19
- The target, by service name. Never point a scan at a site you do not own.line 20
- Your triage decisions: which rules fail, warn or are ignored.line 20
# ZAP baseline rules for ShopRung: <rule id><TAB><IGNORE|INFO|WARN|FAIL><TAB><why>
# Start with every rule at its default (WARN). After triage, FAIL the ones that must never come back. Run the baseline scan
A real scan of ShopRung, and its exit code.
Run the zap service once. ZAP spiders ShopRung (it found 11 URLs), runs its passive rules and prints one line per rule: 62 PASS and 6 WARN-NEW. The last line is the summary.
The exit code tells CI what happened: 0 no warnings or failures, 1 at least one FAIL, 2 at least one WARN and no FAIL, 3 something else went wrong. ShopRung gives 2.
docker compose -f compose.zap.yaml run --rm zap
echo "exit code: $?" Container docker-shoprung-1 Started Using the Automation Framework Total of 11 URLs PASS: Vulnerable JS Library (Powered by Retire.js) [10003] PASS: Cookie No HttpOnly Flag [10010] ... WARN-NEW: Missing Anti-clickjacking Header [10020] x 4 http://shoprung:8080 (200 OK) http://shoprung:8080/sql (200 OK) ... WARN-NEW: X-Content-Type-Options Header Missing [10021] x 5 WARN-NEW: Content Security Policy (CSP) Header Not Set [10038] x 4 WARN-NEW: Non-Storable Content [10049] x 8 WARN-NEW: Permissions Policy Header Not Set [10063] x 5 WARN-NEW: Cross-Origin-Embedder-Policy Header Missing or Invalid [90004] x 11 FAIL-NEW: 0 FAIL-INPROG: 0 WARN-NEW: 6 WARN-INPROG: 0 INFO: 0 IGNORE: 0 PASS: 62 exit code: 2
Stuck on this step?
- ZAP cannot write its report ("Permission denied" on /zap/wrk).
- The container runs as its own user. Make the folder writable:
chmod a+w zap(Linux and CI need this; Docker Desktop usually does not). - "Total of 0 URLs" or a connection error.
- The target must be
http://shoprung:8080, not localhost: inside the zap container, localhost is ZAP itself.
Read the report
Understand each finding before deciding anything.
Open zap/zap-report.html in your browser. Each alert has a risk (High, Medium, Low, Informational), a confidence, the URLs where it was seen, an explanation and a suggested fix. ShopRung's:
- Content Security Policy (CSP) Header Not Set (Medium): without CSP, injected scripts run freely. The strongest defence against cross-site scripting after output escaping.
- Missing Anti-clickjacking Header (Medium): other sites can frame ShopRung and trick users into clicks. Fixed with CSP
frame-ancestorsorX-Frame-Options. - X-Content-Type-Options Header Missing (Low): browsers may guess content types. One header,
nosniff, fixes it. - Permissions Policy and Cross-Origin-Embedder/Opener/Resource-Policy (Low): extra browser hardening headers.
- Non-Storable Content (Informational): ShopRung sends
Cache-Control: no-store. A note about caching, not a security problem.
Notice where it looked: the home page, /sql (the practice SQL console) and /api/test/bugs. A real shop would never expose test endpoints in production; a scan is a good way to notice them.
Triage into rules
Fail the build on what must never come back, ignore noise with a reason.
Edit zap/rules.tsv. Each line is a rule id, a TAB, an action (IGNORE, INFO, WARN or FAIL) and a note. Here, 10021 becomes FAIL: X-Content-Type-Options: nosniff is a one-line fix, so once the developers add it, any change that removes it should fail the build. 10049 becomes IGNORE, with the reason written down. Everything else stays a warning until the team decides.
Run the scan again: one FAIL-NEW, four warnings, one ignored, and exit code 1. In CI, that is a red build with a clear reason.
# ZAP baseline rules for ShopRung: <rule id><TAB><IGNORE|INFO|WARN|FAIL><TAB><why>
# Rules not listed keep their default: WARN.
10021 FAIL (X-Content-Type-Options must be set: a one-line fix that must never come back)
10049 IGNORE (Non-Storable Content: caching information, not a security issue for this shop) - Use TAB characters between the columns, not spaces.line 3
- Every IGNORE carries a reason, so the next person knows it was a decision.line 4
docker compose -f compose.zap.yaml run --rm zap
echo "exit code: $?" Total of 11 URLs ... IGNORE: Non-Storable Content [10049] x 8 WARN-NEW: Missing Anti-clickjacking Header [10020] x 2 WARN-NEW: Content Security Policy (CSP) Header Not Set [10038] x 4 WARN-NEW: Permissions Policy Header Not Set [10063] x 5 WARN-NEW: Cross-Origin-Embedder-Policy Header Missing or Invalid [90004] x 11 FAIL-NEW: X-Content-Type-Options Header Missing [10021] x 5 FAIL-NEW: 1 FAIL-INPROG: 0 WARN-NEW: 4 WARN-INPROG: 0 INFO: 0 IGNORE: 1 PASS: 62 exit code: 1
What the baseline did not find
Know the limits of a passive scan.
ShopRung has a practice bug, order-leak, that lets Bob open Alice's order, and it has no lockout after wrong passwords. The baseline scan found neither, and it cannot: it never logs in, never compares two users, and never sends attacks. It also crawled only 11 URLs, because ShopRung builds its pages with JavaScript and ZAP's classic spider reads HTML links.
So a baseline scan is a cheap safety net for headers and obvious leaks. Access control needs tests with two users, like those in Security testing basics; deeper scans need ZAP's full scan (active attacks, only on your own environment), the API scan with an OpenAPI file, the Ajax spider (-j) for JavaScript apps, and authenticated scanning.
A weekly scan in CI
The same scan on a schedule, failing on the rules you chose.
Add the workflow to the repository from lab 23, together with compose.zap.yaml and zap/rules.tsv. It runs every Monday and on demand, makes the zap folder writable for ZAP's user, runs the scan, keeps the reports as an artifact, and removes the containers.
With the rules above, the job fails until ShopRung sends X-Content-Type-Options, which is the point: the finding stays visible until it is fixed. If you only want reports, not failures, add -I to the scan command: it ignores warnings for the exit code.
name: zap-baseline
on:
schedule:
- cron: "41 3 * * 1" # every Monday, 03:41 UTC
workflow_dispatch:
permissions:
contents: read
jobs:
zap:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Let the ZAP container write its reports
run: chmod a+w zap
- name: Baseline scan of a fresh ShopRung
run: docker compose -f compose.zap.yaml run --rm zap
- name: Keep the reports
if: always()
uses: actions/upload-artifact@v4
with:
name: zap-report
path: zap/zap-report.*
- name: Stop and remove everything
if: always()
run: docker compose -f compose.zap.yaml down -v - Weekly is common for scans; add workflow_dispatch to run it any time.line 5
- On Linux runners, ZAP's container user needs write access to the mounted folder.line 19
- HTML, JSON and Markdown reports, kept even when the scan fails.line 29
actionlint
git add compose.zap.yaml zap/rules.tsv .github/workflows/zap-baseline.yml
git commit -m "Weekly ZAP baseline scan" && git push Actions → zap-baseline → Run workflow → zap ✘ (FAIL-NEW: 1) Artifacts: zap-report
Check it works
With the comments-only rules.tsv, the scan ends with WARN-NEW: 6 and PASS: 62, exit code 2, and zap/zap-report.html lists Content Security Policy, Anti-clickjacking and X-Content-Type-Options among the alerts.
With your rules, it ends with FAIL-NEW: 1, WARN-NEW: 4, IGNORE: 1, exit code 1. Finish with docker compose -f compose.zap.yaml down -v.
docker compose -f compose.zap.yaml run --rm zap; echo "exit code: $?" FAIL-NEW: 1 FAIL-INPROG: 0 WARN-NEW: 4 WARN-INPROG: 0 INFO: 0 IGNORE: 1 PASS: 62 exit code: 1
Troubleshooting
Exit code 3.
ZAP itself had a problem: the target was unreachable, the rules file was malformed, or the reports could not be written. Read the lines above the summary.
A rule in rules.tsv has no effect.
Columns must be separated by TAB characters. Many editors turn TAB into spaces; check with cat -A zap/rules.tsv (TABs show as ^I).
Permission denied writing the report.
Run chmod a+w zap before the scan.
The scan reports nothing useful about the API.
The baseline spider follows HTML links. Use the Ajax spider (-j) or zap-api-scan.py with an OpenAPI file for APIs.
What changes in production
- Teams run the baseline scan on every deploy to a test environment or weekly, and full or API scans on their own environments before releases.
- A rules file in Git records triage: FAIL for regressions that must not return, IGNORE with a reason for accepted findings.
- Scanner output is evidence for a human, not a bug list: every finding is checked, then fixed, accepted or ignored with a reason.
- Access control, business logic and authentication are tested with automated multi-user tests and manual testing; scanners rarely find them.
Interview angle
“How do you use OWASP ZAP in a pipeline?”
The baseline scan in Docker against a test environment I own: it spiders and runs passive checks only, so it is safe to run often. On our shop it passed 62 rules and warned about 6, including missing CSP, anti-clickjacking and X-Content-Type-Options headers. I triaged them into a rules file in Git: FAIL for findings that must never come back, IGNORE with a written reason for noise, WARN for the rest. The exit code, 1 for a failure and 2 for warnings, drives the CI result, and reports are kept as artifacts. I also know its limits: it does not log in or compare users, so access control bugs need two-user tests, and deeper checks need full, API or authenticated scans.
Clean up
Practice
These run in your browser and check your answer.
Apply a rules file
Write outcome(alerts, rules): alerts is a list of rule ids ZAP raised, rules maps rule ids to "IGNORE", "WARN" or "FAIL" (unlisted ids are "WARN"). Return the exit code ZAP's baseline would give: 1 if any alert is FAIL, else 2 if any is WARN, else 0.
def outcome(alerts, rules):
actions = [rules[a] for a in alerts]
if "FAIL" in actions:
return 1
if "WARN" in actions:
return 2
return 0
Hint
Use rules.get(alert, "WARN") so rules that are not in the file keep their default.
The full project
Every file from this lab, as it is after the last step.