API Documentation Publicly Exposed

Interactive documentation or the machine-readable definition of an API that is not meant to be public, such as Swagger UI or an OpenAPI file, can be retrieved by anyone.

SeverityInformational
CVSS 3.10 CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:N Open in the calculator
CVSS 4.00 CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:N/SC:N/SI:N/SA:N Open in the calculator
CWECWE-538: Insertion of Sensitive Information into Externally-Accessible File or Directory
OWASP Top 10A01:2025 Broken Access Control
MITRE ATT&CKT1594 Search Victim-Owned Websites
CategoryInformation Disclosure

Description

API frameworks can generate documentation from the code: an OpenAPI (Swagger) definition in JSON or YAML, an interactive Swagger UI or ReDoc page, a WSDL file for SOAP services, or a GraphQL playground. These are useful during development, but the application publishes them to anyone on its production hosts, although the API is not intended for public use. Documentation for an API that is offered to the public is not a weakness in itself.

The definition lists every endpoint, method, parameter and data model the code exposes, often including internal and administrative operations and fields the client never uses, so it gives an attacker a complete and accurate map of the API: it removes much of the effort of discovering endpoints and parameters and points directly to the most sensitive operations, such as administrative and bulk functions. It does not give access to data or functions by itself, since requests made from it still need whatever authentication the API enforces. On its own it is a matter of reducing exposure rather than a direct risk, and its significance rises where it reveals endpoints that prove to be vulnerable, or where its examples contain real credentials or data.

The weakness is identified by requesting the default paths of common frameworks, such as /swagger-ui.html, /v2/api-docs and /v3/api-docs for Spring, /swagger/index.html and /swagger/v1/swagger.json for ASP.NET Core, /docs, /redoc and /openapi.json for FastAPI, and ?wsdl on SOAP endpoints, and by searching client code and responses for links to them. Scanners report it as an exposed API specification or Swagger UI. Some older Swagger UI releases have also had cross-site scripting flaws, which are reported separately where the version found is affected.

Remediation

Publish API documentation only where it is intended to be public:

  • Disable the documentation endpoints in production, for example by registering Swagger only in the development environment in ASP.NET Core, setting springdoc.api-docs.enabled=false and springdoc.swagger-ui.enabled=false for springdoc in Spring Boot, or passing docs_url=None, redoc_url=None and openapi_url=None to FastAPI().
  • Where developers, partners or customers need the documentation, host it on a separate internal or authenticated portal, or require authentication on the documentation routes.
  • Remove real credentials, tokens and personal data from the examples in the definition.
  • Do not rely on hidden documentation for security: every endpoint must enforce authentication and authorisation whether or not it is documented.
// ASP.NET Core: expose Swagger only in development if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); }

Confirm the fix by requesting the documentation paths again from an unauthenticated, external position and checking that they are no longer served.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More APIs Findings

Every APIs finding