Springboot endpoint 403 OPTIONS when doing a POST request
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
If a browser sends a POST request to a Spring Boot API and you see a 403 on the preceding OPTIONS request, the problem is usually not the POST endpoint itself. It is almost always a CORS preflight request being blocked by Spring Security or by incomplete CORS configuration before the real POST is even allowed to leave the browser.
Why the Browser Sends OPTIONS First
Browsers send a preflight OPTIONS request when a cross-origin request uses methods, headers, or content types that require permission checks. The browser asks the server whether the later POST is allowed from that origin.
A typical preflight request asks questions like:
- is this origin allowed
- is
POSTallowed - are custom headers such as
AuthorizationorContent-Typeallowed
If the server responds without the expected CORS headers, or if security blocks OPTIONS, the browser never sends the actual POST.
The Usual Spring Boot Cause
In many Spring Boot apps, CORS is configured in the controller or MVC layer but not in Spring Security. When Security runs first, it can reject the preflight request with 403 before the CORS configuration ever gets a chance to respond.
The modern fix is to enable CORS in the security filter chain and provide an explicit CorsConfigurationSource.
This does two important things. It tells Spring Security to process CORS, and it gives the framework enough information to answer the preflight request correctly.
@CrossOrigin Helps, But It Is Not Always Enough
For simple applications, @CrossOrigin on a controller can work:
However, if Spring Security is active and not configured to allow or process preflight requests, @CrossOrigin alone may still leave you with a 403. That is why the security-layer configuration is usually the real fix.
How to Debug It Quickly
A useful debugging pattern is to inspect the failed OPTIONS request in browser developer tools. Check the request headers and then check whether the response includes:
- '
Access-Control-Allow-Origin' - '
Access-Control-Allow-Methods' - '
Access-Control-Allow-Headers'
If those headers are missing, the server is not answering CORS correctly. If the request works in Postman but fails in the browser, that is another strong sign that CORS preflight is the issue. Postman is not bound by browser CORS rules.
Common Pitfalls
The biggest pitfall is focusing on the POST controller while ignoring the preflight request. If OPTIONS fails, the controller method is never reached.
Another common mistake is allowing the origin but forgetting the headers. A frontend that sends Authorization or JSON content typically needs those headers listed explicitly.
Developers also run into trouble by mixing wildcard origins with credentials. Browsers do not allow credentialed cross-origin requests when the server responds with a wildcard origin.
Finally, do not assume a 403 from the browser means your business authorization failed. In many cases, it is simply the CORS handshake being rejected earlier in the filter chain.
Summary
- A 403 on
OPTIONSbefore a POST is usually a blocked CORS preflight request. - Configure CORS in Spring Security, not only at the controller layer.
- Permit
OPTIONSrequests and return the requiredAccess-Control-Allow-*headers. - Use browser dev tools to inspect the preflight response directly.
- If Postman works but the browser does not, CORS is the first thing to verify.
Related reading
- Springboot RestController is never used
- springboot swagger3 Failed to load remote configuration.
- Springfox swagger not working in spring boot 2.2.0
- SSD anchors in Tensorflow detection API
- SQL injection that gets around mysql_real_escape_string
- SSH EC2 asking for password
- SSL certificate rejected trying to access GitHub over HTTPS behind firewall
- Static hosting on Amazon S3 - DNS Configuration

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.