This article provides a guide for automating API security scans using OWASP ZAP with a Spring Boot application.
Welcome to this hands-on guide for automating API security scans using OWASP ZAP and a Spring Boot application powered by OpenAPI. In this tutorial, you will learn how to:
Run the zap-api-scan.py script
Customize scan rules and add authentication headers
Generate and serve an OpenAPI 3 spec from Spring Boot via SpringDoc
The zap-api-scan.py script is bundled in the ZAP Docker images. It accepts an API definition—OpenAPI, SOAP, or GraphQL (file or URL)—or directly targets a GraphQL endpoint.
Copy
Ask AI
Usage: zap-api-scan.py -t <target> -f <format> [options] -t target API spec (OpenAPI/SOAP file or URL, or GraphQL endpoint) -f format openapi | soap | graphqlOptions: -c config_file INFO/IGNORE/FAIL custom rules file -u config_url URL to custom rules config -g gen_file generate default config template -r report_html output full HTML report -w report_md output full Markdown report -x report_xml output XML report -j report_json output JSON report -a include alpha passive scan rules -d debug mode -P port override ZAP listen port -D delay wait seconds for passive scan -i default rules not in config to INFO -I do not treat warnings as failure (post 2.9.0) -l level min level to show: PASS|IGNORE|INFO|WARN|FAIL -n context_file load context file before scanning -p progress_file progress file for addressed issues -s short output (no PASS or example URLs) -S safe mode (baseline only) -T timeout max time (minutes) for startup + passive scan -U user authenticated scan username (defined in context) -O hostname override hostname in remote spec -z zap_options pass custom ZAP CLI options --hook Python file for custom hooks
By default, ZAP listens on port 8090. Use -P to bind a different port if it conflicts with your environment.
ZAP needs a REST API definition to drive its scans. With SpringDoc OpenAPI, you can automatically generate and serve an OpenAPI 3 spec alongside a Swagger UI.