Commit 142e453
fix: Allow OPTIONS requests on /openapi.json for CORS preflight (#1518)
* fix: Allow OPTIONS requests on /openapi.json for CORS preflight
This change exempts OPTIONS requests from authentication on documentation
endpoints (/docs, /redoc, /openapi.json) to support CORS preflight requests.
Issue: Browser-based OpenAPI integrations (like Open WebUI) were failing
because CORS preflight OPTIONS requests cannot include Authorization headers
per RFC 7231 Section 4.3.7, but the DocsAuthMiddleware was enforcing
authentication on all requests including OPTIONS.
Solution: Check request.method == 'OPTIONS' before applying authentication,
allowing CORS preflight to succeed while still requiring authentication
for GET requests to actually fetch the OpenAPI spec.
This maintains security (GET still requires auth) while enabling proper
CORS support for browser-based integrations.
Fixes browser-based OpenAPI tool integration (Open WebUI, Swagger UI, etc.)
when AUTH_REQUIRED=false or when using proper authentication flows.
* style: Remove extra blank line in DocsAuthMiddleware
Fix minor style issue with double blank line after OPTIONS check.
Signed-off-by: Mihai Criveti <[email protected]>
---------
Signed-off-by: Mihai Criveti <[email protected]>
Co-authored-by: Jason Sievert <[email protected]>1 parent 93bf8cf commit 142e453
1 file changed
+8
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
910 | 910 | | |
911 | 911 | | |
912 | 912 | | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
913 | 917 | | |
914 | 918 | | |
915 | 919 | | |
| |||
951 | 955 | | |
952 | 956 | | |
953 | 957 | | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
954 | 962 | | |
955 | 963 | | |
956 | 964 | | |
| |||
0 commit comments