- Run the
zap-api-scan.pyscript - Customize scan rules and add authentication headers
- Generate and serve an OpenAPI 3 spec from Spring Boot via SpringDoc
- Execute the ZAP API scan and review reports
1. OWASP ZAP API Scan Usage
Thezap-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.
By default, ZAP listens on port 8090. Use
-P to bind a different port if it conflicts with your environment.2. Custom Scan Rules & Authentication Headers
2.1 Default Rule Levels
You can adjust rules to fire at INFO, WARN, or FAIL by supplying a custom config file (-c) or URL (-u). Here’s a sample of default rule IDs:
Use
-c myrules.conf or -u https://example.com/myrules.conf to apply your tailored policy.
2.2 Adding Authentication Headers
For authenticated scans, ZAP’s replacer options let you insert or replace HTTP headers. Here’s an example that adds two headers via Docker:Never commit your authentication tokens or sensitive headers into version control. Use environment variables or secret management.
3. Generating an OpenAPI Spec from Spring Boot
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.3.1 Add the SpringDoc Dependency
In yourpom.xml, include:
- OpenAPI JSON at:
/v3/api-docs - Swagger UI at:
/swagger-ui.html
3.2 Example pom.xml
3.3 Build and Run
4. Viewing the OpenAPI Definition
Open your browser or REST client to:5. Running the ZAP API Scan
With your API spec live, start the security scan:zap-report.html and zap-report.json in your current directory for review.