This guide walks you through remediating the missing X-Content-Type-Options header in HTTP responses for a Spring Boot application.
In our previous tutorial, we ran an OWASP ZAP scan against a Spring Boot application and published an HTML report via Jenkins. This guide walks you through remediating the missing X-Content-Type-Options header in HTTP responses.First, let’s inspect the vulnerability reported by ZAP:
A quick search on Stack Overflow suggests adding Spring Security Starter to include this header automatically. We’ll:
Add the spring-boot-starter-security dependency.
Create a WebSecurityConfig class to disable CSRF (since we’re only using security for headers).
During the Maven dependency scan, the build fails due to high-severity issues in Spring Security:
Copy
Ask AI
mvn dependency-check:check...[ERROR] One or more dependencies were identified with vulnerabilities that have a CVSS score greater than or equal to '8.0':[ERROR] spring-security-core-5.3.5.RELEASE.jar (CVE-2021-21112)[ERROR] spring-security-web-5.3.5.RELEASE.jar (CVE-2021-21112)
Refresh your application endpoint in the browser. You should now see:
Before: No X-Content-Type-Options header
After:X-Content-Type-Options: nosniff
This confirms the header is correctly applied. The only remaining ZAP warning relates to unexpected Content-Type, which can be addressed by customizing ZAP’s scan rules.