Skip to main content
Integrate OWASP ZAP security testing into your Jenkins CI/CD workflow by leveraging the OpenAPI spec exposed at /v3/api-docs in your Spring Boot application. This guide walks you through updating your Jenkinsfile, creating a ZAP scan script, publishing HTML reports, and fixing security headers.

Prerequisites

1. Update the Jenkinsfile

Add an OWASP ZAP – DAST stage after your integration tests, and configure the post section to publish the HTML report.

2. Create the zap.sh Script

This script retrieves your service’s NodePort, invokes the ZAP API scan against the OpenAPI spec, and organizes the report for Jenkins.
Save this as zap.sh, make it executable (chmod +x zap.sh), and commit it alongside your Jenkinsfile.
If OWASP ZAP exits with a non-zero code, the pipeline will fail. Review the HTML report to triage any findings.

3. Configure Jenkins to Publish HTML

Use the Pipeline Syntax Snippet Generator in Jenkins to configure the publishHTML step:
  • HTML directory: owasp-zap-report
  • Index page(s): zap_report.html
  • Report title: OWASP ZAP HTML Report
The image shows a Jenkins Pipeline Syntax configuration page for publishing HTML reports, with fields for specifying the HTML directory, index page, and report title. There are multiple browser tabs open at the top, and a person is visible in a small circular video feed.
The image shows a Jenkins Pipeline Syntax configuration page for generating an OWASP ZAP HTML report, with options to keep past reports and link to the last build. There are multiple browser tabs open and a small video call window in the corner.

4. Trigger a Build and Review

After pushing your commits, Jenkins will run a new build including the OWASP ZAP – DAST stage:
The image shows a Jenkins pipeline for a "devsecops-numeric-application" with various stages like build, tests, scans, and deployment, all marked as successful. There's also a "50X SPEED" label and a script execution detail for OWASP ZAP.
In the console output, you will see ZAP importing your API endpoints and executing its security rules:

5. View the Published HTML Report

Open the OWASP ZAP HTML Report link on your Jenkins build page to explore vulnerabilities:
The image shows an OWASP ZAP HTML report detailing security alerts, including unexpected content types and missing headers, with associated risk levels and instances.
Select any alert for detailed information:
The image shows an OWASP ZAP HTML report detailing a client error response code of 400, indicating potential issues with handling unexpected input. It includes URLs, methods, and evidence of the error.
In this demo, text/plain responses are expected and can be treated as false positives, but the missing X-Content-Type-Options: nosniff header is a genuine low-risk issue.

6. Verify and Fix the Missing Header

Open your application endpoint in a browser and inspect the response headers under Developer Tools → Network. You should see that X-Content-Type-Options is absent:
The image shows a browser window with multiple tabs open, displaying a webpage titled "Kubernetes DevSecOps" and the browser's developer tools open to the "Network" tab, showing HTTP headers for a request.
Next, enhance your Spring Boot security configuration to include the X-Content-Type-Options: nosniff header and eliminate the warning.

Watch Video