How do you scan an API with ZAP using an OpenAPI definition?
IntermediateHands-onOWASP ZAP
Answer
Short answer
Use zap-api-scan.py with the API's OpenAPI/Swagger (or GraphQL/SOAP) definition. ZAP imports every endpoint and parameter from the spec and actively scans each one — much better coverage than crawling, since APIs have no links to follow.
Command
docker run --rm -v $(pwd)/zap:/zap/wrk:rw -t ghcr.io/zaproxy/zaproxy:stable \
zap-api-scan.py -t https://staging-api.shop.example.com/v3/api-docs -f openapi \
-r api-report.html -J api-report.json \
-z "-config replacer.full_list(0).description=auth \
-config replacer.full_list(0).enabled=true \
-config replacer.full_list(0).matchtype=REQ_HEADER \
-config replacer.full_list(0).matchstr=Authorization \
-config replacer.full_list(0).replacement=Bearer\ ${API_TOKEN}"
The -z replacer config adds an Authorization header to every request so authenticated endpoints get tested.
Formats
-f openapi, -f soap, -f graphql.
Tips
- Use a test token for a test user — never a production credential.
- Seed test data so endpoints return real responses.
- Exclude destructive endpoints if needed (
DELETE /admin/...).
What to say in the interview
"zap-api-scan imports the OpenAPI spec and actively scans every endpoint; I inject an auth header with the replacer config using a test user's token, run it against a seeded test environment and exclude destructive endpoints."
More on OWASP ZAP
What is OWASP ZAP and how do you run a DAST scan?BeginnerWhat is the difference between SAST and DAST?BeginnerWhat is OWASP ZAP?BeginnerWhat is the difference between a ZAP baseline scan and a full scan?BeginnerHow do you run a ZAP baseline scan with Docker?BeginnerHow do you read a ZAP report?Beginner