Skip to main content
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:
  1. Run the zap-api-scan.py script
  2. Customize scan rules and add authentication headers
  3. Generate and serve an OpenAPI 3 spec from Spring Boot via SpringDoc
  4. Execute the ZAP API scan and review reports
Let’s dive in!

1. OWASP ZAP API Scan Usage

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.
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 your pom.xml, include:
This exposes:
  • OpenAPI JSON at: /v3/api-docs
  • Swagger UI at: /swagger-ui.html

3.2 Example pom.xml

3.3 Build and Run

Your Spring Boot app will start on port 8080, serving the OpenAPI spec.

4. Viewing the OpenAPI Definition

Open your browser or REST client to:
Example response:
You can also browse the interactive docs at:

5. Running the ZAP API Scan

With your API spec live, start the security scan:
This command produces both zap-report.html and zap-report.json in your current directory for review.

Watch Video