Skip to content

[fix] stop serving the openapi document to anonymous callers - #4276

Open
Duansg wants to merge 7 commits into
apache:masterfrom
Duansg:fix-openapi-docs-authz
Open

[fix] stop serving the openapi document to anonymous callers#4276
Duansg wants to merge 7 commits into
apache:masterfrom
Duansg:fix-openapi-docs-authz

Conversation

@Duansg

@Duansg Duansg commented Jul 29, 2026

Copy link
Copy Markdown
Member

What's changed?

The OpenAPI/Swagger document endpoints are no longer open to anonymous callers; scoped to admin.

Checklist

  • I have read the Contributing Guide
  • I have written the necessary doc or comment.
  • I have added the necessary unit tests and all cases have passed.

Add or update API

  • I have added the necessary e2e tests and all cases have passed.

@Duansg

Duansg commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

/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
@Duansg
Duansg requested a review from zqr10159 August 9, 2026 14:20

@zqr10159 zqr10159 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants