Summary
The Swagger UI at /api/docs is publicly accessible without any authentication in production. This exposes the full API surface, parameter names, and schema details to unauthenticated users.
Risk
Proposed options
- Environment gate (recommended): Only register the Swagger plugin when
NODE_ENV !== 'production' or when a ENABLE_SWAGGER=true env var is set.
- Basic auth on /api/docs: Add a preHandler that checks a static credential from env before serving the docs.
- Remove in production builds: Conditionally include the
@fastify/swagger-ui plugin.
// Option 1 — simplest
if (process.env.NODE_ENV !== 'production') {
await app.register(swaggerUi, { ... });
}
Priority: LOW (P3)
Summary
The Swagger UI at
/api/docsis publicly accessible without any authentication in production. This exposes the full API surface, parameter names, and schema details to unauthenticated users.Risk
Proposed options
NODE_ENV !== 'production'or when aENABLE_SWAGGER=trueenv var is set.@fastify/swagger-uiplugin.Priority: LOW (P3)