Skip to content

fix(openapi): add securitySchemes and global security requirement to OpenAPI spec - #34998

Open
mbiuki wants to merge 3 commits into
mainfrom
fix/openapi-security-schemes-34996
Open

mbiuki wants to merge 3 commits into
mainfrom
fix/openapi-security-schemes-34996

Conversation

@mbiuki

@mbiuki mbiuki commented Mar 16, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #34996

The OpenAPI spec at /api/openapi.json declared security: [] globally with no securitySchemes defined, documenting all 689 endpoints as unauthenticated even though the server enforces auth on the vast majority of them.

  • Add @SecuritySchemes to DotRestApplication — three schemes matching the actual auth waterfall in WebResource.java: ApiToken (JWT Bearer), BasicAuth (HTTP Basic), DotAuth (DOTAUTH header)
  • Set global security default in @OpenAPIDefinition — all endpoints now require auth in the spec unless explicitly overridden
  • Mark 16 genuinely public endpoints with security = {} override: health/liveness/readiness checks (required for k8s probes), login, forgot password, and all SAML SSO flow endpoints

Files Changed

File Change
DotRestApplication.java Add @SecuritySchemes + global security to @OpenAPIDefinition
HealthResource.java security = {} on all 8 health endpoints
AuthenticationResource.java security = {} on login + logInUser
ForgotPasswordResource.java security = {} on forgot password
DotSamlResource.java security = {} on all 5 SAML SSO endpoints

Test Plan

  • curl https://<instance>/api/openapi.json | jq '.components.securitySchemes' — should return ApiToken, BasicAuth, DotAuth schemes
  • curl https://<instance>/api/openapi.json | jq '.security' — should return [{"ApiToken":[]},{"BasicAuth":[]}]
  • Verify health endpoints still have "security": [] in the generated spec
  • Verify SAML, login, and forgot-password endpoints have "security": []
  • Run spec through 42Crunch or OWASP ZAP — admin/infra endpoints should no longer be flagged as unauthenticated
  • Confirm dotCMS starts and /api/openapi.json is served without errors

🤖 Generated with Claude Code

…OpenAPI spec

Fixes #34996

The OpenAPI spec at /api/openapi.json declared security: [] globally with no
securitySchemes defined, making all 689 endpoints appear unauthenticated to
scanners and API consumers even though the server enforces auth on the vast
majority of them.

Changes:
- DotRestApplication: add @SecuritySchemes (ApiToken/Bearer JWT, BasicAuth,
  DotAuth header) and set global security default in @OpenAPIDefinition
- HealthResource: mark all 8 health/liveness/readiness endpoints as public
  (security = {}) — required for k8s probes and monitoring
- AuthenticationResource: mark login and logInUser as public
- ForgotPasswordResource: mark forgot password as public
- DotSamlResource: mark all 5 SAML SSO flow endpoints as public
  (login, callback, metadata, logout POST/GET)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@claude

claude Bot commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @fabrizzio-dotCMS's task in 1m 27s —— View job


Code Review

  • Gather context (diff of 5 changed files)
  • Analyze security scheme annotations
  • Check generated openapi.yaml regeneration
  • Post review

New Issues

  • 🟠 High: dotCMS/src/main/webapp/WEB-INF/openapi/openapi.yaml (not in PR) — The generated OpenAPI spec was not regenerated or committed. Per CLAUDE.md, openapi.yaml is auto-generated by swagger-maven-plugin at compile and CI verifies the committed file matches the build output. The current committed openapi.yaml has no components.securitySchemes, no top-level security: block, and no per-operation security: [] overrides — none of this PR's intended output. Two consequences: (1) the "did the generated spec change?" CI gate will fail, and (2) nothing in this PR actually ships the fix described in the summary — the whole point is a change to the generated spec, and that artifact is unchanged. Regenerate and commit alongside the Java changes:
    ./mvnw compile -pl :dotcms-core --am -DskipTests
    git add dotCMS/src/main/webapp/WEB-INF/openapi/openapi.yaml
    Fix this →

Notes (non-blocking)

  • 🟡 Medium: DotSamlResource.java:33, AuthenticationResource.java:42, ForgotPasswordResource.java:42, HealthResource.java:22 — the added import io.swagger.v3.oas.annotations.security.SecurityRequirement; is unused in all four files. They only use security = {} (an empty array literal), which never references the SecurityRequirement type by name. Only DotRestApplication.java actually uses @SecurityRequirement(...). Remove the four unused imports.

  • 🟡 Medium: DotRestApplication.java:49 — the DotAuth scheme is defined but never referenced by any @SecurityRequirement, either in the global security (which lists only ApiToken and BasicAuth) or on any operation. Since WebResource.java's auth waterfall accepts the DOTAUTH header, consider adding @SecurityRequirement(name = "DotAuth") to the global security so the spec reflects it as an accepted mechanism — otherwise it's a defined-but-dangling scheme.

  • 🟡 Medium: AuthenticationResource.java:229 — security = {} is applied to logInUser ("information about any users currently in a session"). Confirm this endpoint genuinely functions without credentials; if it returns authenticated session data, documenting it as fully public is misleading. The other 15 overrides (health probes, login, forgot-password, SAML SSO) are appropriate.

The annotation approach itself is correct: @SecuritySchemes + a global @SecurityRequirement default with per-operation security = {} overrides is the right OpenAPI pattern, and the empty-array override correctly marks an operation public.

--- · fix/openapi-security-schemes-34996

@mbiuki mbiuki added CVSS : N/A Not a vulnerability: no CVSS v3.1 base score CVSS 4.0 : N/A CVSS 4.0: not a vulnerability and removed Priority : 3 Average CVSS : N/A Not a vulnerability: no CVSS v3.1 base score labels Sep 30, 2026
@mbiuki

mbiuki commented Oct 6, 2026

Copy link
Copy Markdown
Member Author

Security assessment

CVSS 4.0 N/A: PR that corrects OpenAPI securitySchemes; documentation accuracy only, no runtime auth change.
Priority P4 · due 2027-03-16 (one year, 365 days from 2026-03-16) · project #7 (dotCMS - Product Planning): P4 - Low
Weakness CWE-1059 Insufficient Technical Documentation

Why this priority: PR that corrects OpenAPI securitySchemes; documentation accuracy only, no runtime auth change.

Labels: already correct, no change.

Automated triage by the dotCMS Security team (Claude), 2026-10-06. To override, change the project's Priority field or the CVSS label. The next refresh keeps a manual change.

@fabrizzio-dotCMS fabrizzio-dotCMS 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.

The goal is right, but the PR doesn't produce the spec it describes yet.

1. @Operation(security = {}) is a no-op in swagger-core 2.2.34. SecurityParser.getSecurityRequirements returns Optional.empty() for a zero-length array, so nothing is set on the operation and it inherits the new global ApiToken/BasicAuth requirement. Login, forgot-password and SAML would be documented as authenticated. Method-level @SecurityRequirement goes through the same parser, so there's no annotation-only way to override the global value with an empty list. Suggest a ReaderListener#afterScan that does operation.setSecurity(new ArrayList<>()) on operations flagged public (e.g. an x-public extension).

2. Nine of the 16 "public" endpoints are not public.

  • All 8 HealthResource endpoints call isAccessAllowed, which requires the CMS Admin role unless health.detailed.authentication.required=false (default true). K8s probes use /dotmgt/livez and /dotmgt/readyz (web.xml), not /api/v1/health.
  • DotSamlResource#metadata requires an admin backend user (its own description says so).

The 7 that are really public: authentication, logInUser, forgot password, SAML login (GET + callback POST), SAML logout (GET + POST).

3. DotAuth is declared but not in the global requirement, so the spec says no endpoint accepts DOTAUTH while WebResource accepts it everywhere. Add it or drop the scheme.

4. openapi.yaml not regenerated. CI compares it against the build output. Please regenerate (./mvnw compile -pl :dotcms-core --am -DskipTests), commit it, and check that only those 7 operations end up with security: [].

Nit: unused SecurityRequirement import in HealthResource, AuthenticationResource, ForgotPasswordResource and DotSamlResource.

This branch has not been deployed

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

Labels

AI: Safe To Rollback Area : Backend PR changes Java/Maven backend code CVSS 4.0 : N/A CVSS 4.0: not a vulnerability dotCMS : Security OKR : Security & Privacy Owned by Mehdi Schema Changes Team : Security Issues related to security and privacy

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

security: OpenAPI spec (/api/openapi.json) declares all 689 endpoints as unauthenticated due to missing securitySchemes

4 participants