[fix] stop serving the openapi document to anonymous callers - #4276
Conversation
|
/swagger-ui/index.html is still served anonymously by the existing /**/*.html===get exclusion, but the page fetches /v3/api-docs/swagger-config and /v3/api-docs without an Authorization header — swagger-ui's Authorize button only applies to try-it-out calls, not to the spec fetch. The UI will therefore show "Failed to load API definition" for everyone, including admins. The document itself remains reachable for an admin with a token: curl -H "Authorization: Bearer $JWT" http://localhost:1157/v3/api-docs If the community would rather not ship a UI page that cannot load, the follow-up is to set springdoc.api-docs.enabled / springdoc.swagger-ui.enabled to false by default and let deployments opt in; that is a product decision kept out of this PR. |
# Conflicts: # hertzbeat-startup/src/main/resources/sureness.yml # script/docker-compose/hertzbeat-mysql-iotdb/conf/sureness.yml # script/docker-compose/hertzbeat-mysql-tdengine/conf/sureness.yml # script/docker-compose/hertzbeat-mysql-victoria-metrics/conf/sureness.yml # script/docker-compose/hertzbeat-postgresql-greptimedb/conf/sureness.yml # script/docker-compose/hertzbeat-postgresql-victoria-metrics/conf/sureness.yml # script/sureness.yml
zqr10159
left a comment
There was a problem hiding this comment.
Restricting the generated OpenAPI document to administrators is the right security boundary, but the current change leaves /swagger-ui/index.html publicly reachable while the UI cannot attach an administrator token to its initial /v3/api-docs/swagger-config and /v3/api-docs requests. The result is a shipped page that shows “Failed to load API definition” for anonymous users and administrators alike. Please either disable the Swagger UI by default (with an explicit opt-in deployment path), or provide an authenticated loading flow that lets an administrator use it. Keep the document endpoints admin-only in either case.
Scoping the generated document to the admin role left the swagger ui page reachable anonymously through the /**/*.html exclusion, while the page fetches /v3/api-docs/swagger-config and /v3/api-docs without an Authorization header - its Authorize button only applies to try-it-out calls. Everyone, administrators included, would have seen "Failed to load API definition". Sureness checks the exclusion tree before any credential check, so the ui page cannot be pulled back under an rbac rule without narrowing the /**/*.html exclusion itself, which is a separate and much wider change. Both springdoc endpoints are therefore off in the shipped configuration and a deployment opts in explicitly; the admin-only rules stay as the second line of defence for the deployments that do. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…-openapi-docs-authz
…-openapi-docs-authz
…-openapi-docs-authz
zqr10159
left a comment
There was a problem hiding this comment.
The previous Swagger UI regression is resolved. OpenAPI and Swagger UI are now disabled by default across the packaged and deployment configurations; when explicitly enabled, the UI attaches the existing HertzBeat JWT only to same-origin requests, while the document endpoints remain admin-only. The configuration-copy contracts, transformer tests, focused security tests, and current-head CI are all green.

What's changed?
The OpenAPI/Swagger document endpoints are no longer open to anonymous callers; scoped to admin.
Checklist
Add or update API