Security and hardening · Intermediate · 17 min
Scan your own web app for common issues with the ZAP baseline scan
By Padding · Updated 18 Nov 2026
Ubuntu 26.04 · Docker Engine · ZAP 2.17.0 (ghcr.io/zaproxy/zaproxy:2.17.0)
You will run the ZAP 2.17 baseline scan against a small app on your own machine, read its report, fix two findings, record what you accept in a rules file and run the same scan in GitHub Actions against each preview deployment.
On this page
A dynamic scanner looks at your site the way a browser does: it requests pages and reads what comes back. ZAP is the best-known open-source one. Since 2024 its core team works at Checkmarx, and ZAP itself stays free and open source. Its baseline scan is the gentle mode. It crawls your site for up to a minute, then runs only passive rules over the responses it saw: missing security headers, cookies without the right flags, version numbers in headers, error pages that leak detail. It sends nothing designed to break or exploit anything.
That gentleness matters. ZAP also has an active scan, which sends attack payloads such as SQL injection and script injection strings to every parameter it finds. Run an active scan only against systems you own or have written permission to test, and never against a live site with real users' data. This tutorial stays with the passive baseline scan and with an app you own, running on your own machine.
You will build a three-page Python app on 127.0.0.1:8000, scan it with the ZAP 2.17.0 Docker image, read the findings, fix two of them, write a rules file that makes the fixed issues fail the build and records one accepted item with a reason, then run the same scan in GitHub Actions against each preview deployment.
Step 1 · Run a small app to scan
The demo app uses only Python's standard library, so there is nothing to install. It serves three linked HTML pages and sets a session cookie on each, the way many apps do before anyone reviews them. Create a throwaway folder and write the app:
mkdir -p ~/zap-demo
cd ~/zap-demo
cat > app.py <<'EOF'
"""A three-page notes site to practise the ZAP baseline scan on. Standard library only."""
import os
import secrets
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
PORT = int(os.environ.get("PORT", "8000"))
PAGES = {
"/": '<h1>Field notes</h1><p>Short notes for the team.</p>'
'<p><a href="/about">About</a> | <a href="/contact">Contact</a></p>',
"/about": '<h1>About</h1><p>A demo site for the ZAP baseline scan.</p><p><a href="/">Home</a></p>',
"/contact": '<h1>Contact</h1><p>Ask in the team channel.</p><p><a href="/">Home</a></p>',
}
class Handler(BaseHTTPRequestHandler):
def respond(self, with_body):
body = PAGES.get(self.path)
if body is None:
self.send_error(404)
return
page = ("<!doctype html><html lang='en'><head><meta charset='utf-8'>"
"<title>Field notes</title></head><body>" + body + "</body></html>").encode()
self.send_response(200)
self.send_header("Content-Type", "text/html; charset=utf-8")
self.send_header("Content-Length", str(len(page)))
self.send_header("Set-Cookie", "session=" + secrets.token_urlsafe(16) + "; Path=/")
self.end_headers()
if with_body:
self.wfile.write(page)
def do_GET(self):
self.respond(True)
def do_HEAD(self):
self.respond(False)
if __name__ == "__main__":
print(f"Serving on http://127.0.0.1:{PORT}", flush=True)
ThreadingHTTPServer(("127.0.0.1", PORT), Handler).serve_forever()
EOFThe server listens on 127.0.0.1 only, so nothing else on your network can reach it. In a second terminal, start it and leave it running:
cd ~/zap-demo
python3 app.pyIt prints Serving on http://127.0.0.1:8000 and then one log line per request.
Check it worked
Back in the first terminal, ask for the headers of the home page:
curl -sI http://127.0.0.1:8000/You see HTTP/1.0 200 OK, a Server header that names Python and its version, and Set-Cookie: session=...; Path=/ with nothing after Path=/. Keep that output in mind: the scan is about to tell you what is wrong with it.
Step 2 · Run the baseline scan
ZAP's team publishes the scan scripts inside the ZAP Docker image, so you need no Java or ZAP install on your machine. Pull the image with an exact version tag. That fixes ZAP itself and the scan scripts, but the baseline scan still updates its passive rule add-ons each time it starts, so alert counts and new rules can change between runs:
docker pull ghcr.io/zaproxy/zaproxy:2.17.0The image is large. On prepaid or metered mobile data, check its size on the GitHub Container Registry page first, pull it once over Wi-Fi, or skip the local run and use the GitHub Actions step at the end, where the download happens on GitHub's network instead of yours.
The image runs as a user with ID 1000 and writes its reports into whatever folder you mount at /zap/wrk. Run id -u. If it prints 1000, as it does for the first user on most Ubuntu machines, carry on. If not, run chmod a+w ~/zap-demo so the scan can write its files there.
Now scan the app. --network host lets the scan reach 127.0.0.1:8000 on your machine, and -v "$PWD":/zap/wrk/:rw mounts the demo folder for the reports:
cd ~/zap-demo
docker run --rm --network host -v "$PWD":/zap/wrk/:rw ghcr.io/zaproxy/zaproxy:2.17.0 \
zap-baseline.py -t http://127.0.0.1:8000 -g zap-gen.conf -r report.html -J report.json -I \
| tee scan-1.txtWhat each option does:
-tis the target. Point it only at sites you own or have permission to scan.-g zap-gen.confwrites a starter rules file that lists every passive rule with its ID, set toWARN.-r report.htmland-J report.jsonwrite the full report as a web page and as JSON.-Istops warnings from turning into a failing exit code. Without it the script exits2when it finds any warning. It exits1for aFAILand3when the scan itself broke, for example because the target did not answer.
On Docker Desktop for macOS or Windows, drop --network host and use -t http://host.docker.internal:8000. That name points at your computer from inside Docker Desktop.
The run takes a minute or two: ZAP starts, updates its rule add-ons, crawls the three pages and waits for the passive rules to finish.
Check it worked
grep 'WARN-INPROG' scan-1.txt
ls ~/zap-demoThe first command prints the summary line, something like FAIL-NEW: 0 FAIL-INPROG: 0 WARN-NEW: 9 WARN-INPROG: 0 INFO: 0 IGNORE: 0 PASS: 50. The exact counts depend on the rule versions. The folder now holds report.html, report.json, zap-gen.conf and scan-1.txt.
Step 3 · Read the findings
Each warning in the terminal output is one line in the form WARN-NEW: <alert name> [<rule ID>] x <number of URLs>, followed by example URLs. List them:
grep -E '^(WARN|FAIL)-NEW' scan-1.txtExpect lines such as these, among others:
Cookie No HttpOnly Flag [10010]: scripts on the page can read the session cookie, so one cross-site scripting bug can leak sessions.Cookie without SameSite Attribute [10054]: the browser may send the cookie on requests started by other sites, which helps cross-site request forgery.X-Content-Type-Options Header Missing [10021]: the browser may guess a response's type from its content instead of trustingContent-Type.Missing Anti-clickjacking Header [10020]andContent Security Policy (CSP) Header Not Set [10038]: other sites can frame your pages, and there is no policy limiting where scripts load from.Server Leaks Version Information via "Server" HTTP Response Header Field [10036]: theServerheader names the software and its version.
The JSON report is easier to sort and share. Install jq to query the JSON report:
sudo apt install -y jqPrint one line per alert with its risk and the number of URLs it hit:
jq -r '.site[].alerts[] | "\(.pluginid)\t\(.riskdesc)\t\(.alert)\t\(.instances | length) URLs"' report.jsonriskdesc reads like Low (Medium): the risk first, then ZAP's confidence in the finding. Look at where one alert was seen:
jq -r '.site[].alerts[] | select(.pluginid == "10010") | .instances[] | "\(.uri) cookie: \(.param)"' report.jsonEach line is a page that set the session cookie without HttpOnly. Open report.html in a browser for the same data with a description, a suggested fix and reference links for every alert.
A passive scan reports what it can see in responses, so some findings may not apply to you, and it cannot see anything behind a sign-in page unless you configure authentication. Treat the list as a set of questions to answer, not a grade. Triage security scanner findings covers how to rank and record decisions on a longer list.
Check it worked
You can name the rule ID for the cookie findings (10010 and 10054) and for the missing nosniff header (10021), and report.html opens in your browser with the same alerts.
Step 4 · Fix the cookie flags and the nosniff header
Fix two findings in the app: give the session cookie the HttpOnly and SameSite=Lax attributes, and send X-Content-Type-Options: nosniff on every response. The header goes in an end_headers override, so it is added to error pages from send_error as well as normal pages. The app also gains Secure on the cookie when COOKIE_SECURE=1 is set, for when it runs behind HTTPS.
Stop the app in the second terminal with Ctrl+C, then replace app.py with the fixed version:
cd ~/zap-demo
cat > app.py <<'EOF'
"""A three-page notes site to practise the ZAP baseline scan on. Standard library only."""
import os
import secrets
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
PORT = int(os.environ.get("PORT", "8000"))
# HttpOnly: page scripts cannot read the cookie. SameSite=Lax: other sites' forms do not send it.
COOKIE_FLAGS = "; Path=/; HttpOnly; SameSite=Lax"
if os.environ.get("COOKIE_SECURE") == "1":
COOKIE_FLAGS += "; Secure" # only sent over HTTPS
PAGES = {
"/": '<h1>Field notes</h1><p>Short notes for the team.</p>'
'<p><a href="/about">About</a> | <a href="/contact">Contact</a></p>',
"/about": '<h1>About</h1><p>A demo site for the ZAP baseline scan.</p><p><a href="/">Home</a></p>',
"/contact": '<h1>Contact</h1><p>Ask in the team channel.</p><p><a href="/">Home</a></p>',
}
class Handler(BaseHTTPRequestHandler):
def end_headers(self):
# Runs for every response, including the error pages that send_error writes.
self.send_header("X-Content-Type-Options", "nosniff")
super().end_headers()
def respond(self, with_body):
body = PAGES.get(self.path)
if body is None:
self.send_error(404)
return
page = ("<!doctype html><html lang='en'><head><meta charset='utf-8'>"
"<title>Field notes</title></head><body>" + body + "</body></html>").encode()
self.send_response(200)
self.send_header("Content-Type", "text/html; charset=utf-8")
self.send_header("Content-Length", str(len(page)))
self.send_header("Set-Cookie", "session=" + secrets.token_urlsafe(16) + COOKIE_FLAGS)
self.end_headers()
if with_body:
self.wfile.write(page)
def do_GET(self):
self.respond(True)
def do_HEAD(self):
self.respond(False)
if __name__ == "__main__":
print(f"Serving on http://127.0.0.1:{PORT}", flush=True)
ThreadingHTTPServer(("127.0.0.1", PORT), Handler).serve_forever()
EOFStart it again in the second terminal:
python3 app.pyIn a framework you would make the same change in its session settings and its middleware rather than by hand. Secure sessions and cookies in an Express app shows the Express version.
Scan again, writing to a new output file:
docker run --rm --network host -v "$PWD":/zap/wrk/:rw ghcr.io/zaproxy/zaproxy:2.17.0 \
zap-baseline.py -t http://127.0.0.1:8000 -r report.html -J report.json -I \
| tee scan-2.txtCheck it worked
curl -sI http://127.0.0.1:8000/ | grep -iE '^(set-cookie|x-content-type-options)'
grep -E '\[(10010|10054|10021)\]' scan-2.txt || echo "10010, 10054 and 10021 are gone"The cookie line ends in ; HttpOnly; SameSite=Lax, the nosniff header is there, and the second command prints 10010, 10054 and 10021 are gone. The CSP and anti-clickjacking warnings remain; a strict policy with frame-ancestors deals with both, as in Set a strict Content Security Policy with nonces.
Step 5 · Write a rules file
By default every finding is a warning, so a scan that runs on every change either fails all the time or is ignored. A rules file fixes that. Each line holds a rule ID, an action and the rule's name in brackets, separated by tab characters, with an optional fourth field: a message printed next to the alert. The main actions are FAIL, WARN, INFO and IGNORE; OUTOFSCOPE also exists for URLs you want left out. Lines starting with # are comments.
Use the rules file for two jobs:
- Make the issues you fixed
FAIL, so they cannot quietly come back. - Mark items you have decided to accept as
IGNORE, with the reason, an owner and a review date in a comment above them, so the decision is visible in code review.
Here the accepted item is the Server header from Python's development server, on the assumption that in production the app sits behind Nginx with server_tokens off, as in Add security headers in Nginx. Replace it with your own decision. zap-gen.conf from the first scan lists every rule ID and name if you want to pick others.
printf writes real tabs with \t, which survives copy and paste better than tab characters typed into an editor:
cd ~/zap-demo
mkdir -p .zap
{
printf '# ZAP baseline rules for zap-demo. Fields are separated by tabs.\n'
printf '# Fixed: fail the scan if these come back.\n'
printf '10010\tFAIL\t(Cookie No HttpOnly Flag)\tSession cookies must be HttpOnly\n'
printf '10054\tFAIL\t(Cookie without SameSite Attribute)\tSet SameSite=Lax or Strict\n'
printf '10021\tFAIL\t(X-Content-Type-Options Header Missing)\tSend nosniff on every response\n'
printf '# Accepted: Python dev server header; Nginx sets server_tokens off in production.\n'
printf '# Owner: web team. Review by 2027-05-31.\n'
printf '10036\tIGNORE\t(Server Leaks Version Information)\n'
} > .zap/rules.tsvRules you leave out stay as WARN. Scan with the rules file. -c is a path inside the mounted folder:
docker run --rm --network host -v "$PWD":/zap/wrk/:rw ghcr.io/zaproxy/zaproxy:2.17.0 \
zap-baseline.py -t http://127.0.0.1:8000 -c .zap/rules.tsv -r report.html -J report.json -I \
| tee scan-3.txt
echo "exit code: ${PIPESTATUS[0]}"-I still stops plain warnings from failing the run, but a FAIL rule always makes it exit 1. If someone later removes HttpOnly, the scan prints a line like FAIL-NEW: Cookie No HttpOnly Flag [10010] x 3 Session cookies must be HttpOnly and the CI job goes red.
Check it worked
awk -F'\t' '!/^#/ { print NF " fields: " $1 " " $2 }' .zap/rules.tsv
grep 'WARN-INPROG' scan-3.txtEvery rule line shows 3 or 4 fields; a line showing 1 fields has spaces where tabs belong and the scan stops with an Unexpected number of tokens error. The summary line starts FAIL-NEW: 0 and shows IGNORE: 1, and the exit code is 0.
Step 6 · Scan every preview deployment in GitHub Actions
Scanning a local app proves the idea. The useful version runs on every change, against the build you are about to ship. Many hosts create a preview deployment for each pull request and report it to GitHub as a deployment status with the preview's URL. A workflow on the deployment_status event can scan that URL as soon as it is live. If your host does not report deployments, Create a preview environment for every pull request builds one in Actions and exposes its URL.
Copy .zap/rules.tsv into the root of your project, then add the workflow. The demo writes both into ~/zap-demo:
cd ~/zap-demo
mkdir -p .github/workflows
cat > .github/workflows/zap-baseline.yml <<'EOF'
name: ZAP baseline scan
on:
deployment_status:
permissions:
contents: read
jobs:
zap-baseline:
# Only scan previews that finished deploying and have a URL.
if: github.event.deployment_status.state == 'success' && github.event.deployment_status.environment_url != ''
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.deployment.sha }}
persist-credentials: false
- name: Baseline scan of the preview
uses: zaproxy/action-baseline@de8ad967d3548d44ef623df22cf95c3b0baf8b25 # v0.15.0
with:
target: ${{ github.event.deployment_status.environment_url }}
docker_name: ghcr.io/zaproxy/zaproxy:2.17.0
rules_file_name: .zap/rules.tsv
cmd_options: -I
fail_action: true
allow_issue_writing: false
artifact_name: zap-baseline-report
EOFThe choices in this file:
fail_action: truemakes the job fail when the scan exits1or2. With-Iincmd_options, plain warnings exit0, so only yourFAILrules break the build. An exit code of3, a broken scan, always fails the job.allow_issue_writing: falsestops the action from opening a GitHub issue with the report, which it does by default and which needs write access to issues. The reports are kept as a workflow artifact namedzap-baseline-reportinstead.- Both actions are pinned to the commits behind their tags (
v7.0.1andv0.15.0), so a moved tag cannot swap in different code. Harden GitHub Actions workflows explains why. The image is pinned to2.17.0, which fixes ZAP and its scan scripts, but the scan still updates its rule add-ons at start, so a new or changed rule can appear in a later run. - The target comes from your host's deployment record, so the workflow only ever scans your own previews.
If your previews sit behind a login or a host's password protection, the scan only sees the sign-in page. Keep it passive even there. Turning on ZAP's active scan in CI is a separate decision that needs a dedicated test environment and the system owner's permission.
Check it worked
Commit .zap/rules.tsv and .github/workflows/zap-baseline.yml to your project and open a pull request. When the preview finishes deploying, the Actions tab shows a ZAP baseline scan run. It passes, and the run's summary page has a zap-baseline-report artifact with the HTML, JSON and Markdown reports. To prove the guard, push a commit that drops HttpOnly from the session cookie: the next run fails with a FAIL-NEW line for rule 10010.
Step 7 · Clean up
Stop the app in the second terminal with Ctrl+C.
If you copied the rules file and workflow into a real project, the demo folder is no longer needed. Delete it:
cd ~
rm -rf ~/zap-demoRemove the ZAP image if you do not plan to scan locally again:
docker image rm ghcr.io/zaproxy/zaproxy:2.17.0Check it worked
ls ~/zap-demo reports No such file or directory, and docker image ls ghcr.io/zaproxy/zaproxy lists nothing.
Next steps
- Fix the CSP and anti-clickjacking warnings that remain: Set a strict Content Security Policy with nonces.
- Strip the
Serverversion and add the other headers at the proxy: Add security headers in Nginx. - Rank and record decisions on a longer list of findings: Triage security scanner findings.
- Harden the session cookie in a framework: Secure sessions and cookies in an Express app.
Part of these paths
Related tutorials
- How to Add Security Headers to Your Site in NginxYou will add the HTTP security headers every site should send, keep them in one reusable file, avoid the add_header inheritance trap, and roll out Content-Security-Policy and HSTS in the safe order.
- Set a strict Content Security Policy with noncesYou will serve a Node.js page under a nonce-based strict Content Security Policy, roll it out in report-only mode with your own report collector, fix the inline handler it flags, add Trusted Types and cover a static nginx site with hashes.
- Triage security scanner findings without drowning in themYou will take a dependency scan with 14 findings, rank them with CVSS, EPSS and CISA's Known Exploited Vulnerabilities list, check which packages ship and which code is reachable, fix what matters, and record each accepted risk with an owner and an expiry date in osv-scanner.toml and a VEX statement.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials