Skip to main content
Menu
Advisories

@fastify/swagger-ui vulnerable to documentation authentication bypass via the unprotected /static route

GHSA-J7QM-JHPC-MJ26Published Updated GitHub

Description

Impact

@fastify/swagger-ui lets applications protect the documentation with uiHooks (the onRequest and preHandler authentication hooks described in the README). Those hooks are applied to every route the plugin adds except the @fastify/static instance mounted at <routePrefix>/static/. When baseDir is set, which the README recommends for bundling the UI, that instance serves every file in baseDir, so a file the operator protected at <routePrefix>/<file> is also reachable without credentials at <routePrefix>/static/<file>. An unauthenticated client who knows or guesses a file name can read specification files that were meant to stay behind the documentation login. Access is read-only, and the /json, /yaml and UI page routes stay protected. Versions 2.1.0 through 6.1.4 are affected.

Patches

Upgrade to @fastify/swagger-ui 6.1.5 or later, which applies the uiHooks to the /static route as well. The bundled Swagger UI assets are now served behind the same hooks. Basic and cookie or session authentication keep working because the browser sends same-origin credentials for those requests; a header-only bearer scheme or a proxy that injects authentication may need the assets on a separate public path or an authentication-aware same-origin proxy.

Workarounds

Enforce authentication in a Fastify hook registered before @fastify/swagger-ui so it also runs for the /static route, or do not set baseDir (without it, only the public bundled assets are served under /static/).

References

  • GHSA-62jr-84gf-wmg4 (CVE-2024-22207), an earlier file exposure in @fastify/swagger-ui's static serving.

Affected versions

References

GitHub · fastify/fastify-swagger-ui