Skip to main content
Vulnerability Database/CVE-2024-22207

CVE-2024-22207: Fastify Swagger UI Information Disclosure

CVE-2024-22207 is an information disclosure vulnerability in fastify-swagger-ui that exposes sensitive files through unprotected HTTP routes. This article covers technical details, affected versions, and mitigation strategies.

Published:

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2024-22207 Overview

CVE-2024-22207 is an information disclosure vulnerability in @fastify/swagger-ui, a Fastify plugin that serves Swagger UI for API documentation. Versions prior to 2.1.0 expose all files in the module's directory through HTTP routes when the baseDir option is not configured. An unauthenticated remote attacker can retrieve arbitrary files served from the module's root path. The vulnerability is categorized under [CWE-1188] (Initialization of a Resource with an Insecure Default). Maintainers released a fix in version 2.1.0.

Critical Impact

Remote, unauthenticated attackers can read files served from the plugin's directory, resulting in confidentiality loss across any Fastify application using the default configuration.

Affected Products

  • @fastify/swagger-ui versions prior to 2.1.0
  • Fastify applications integrating Swagger UI without the baseDir option set
  • NetApp products bundling the affected component (see NetApp advisory NTAP-20240216-0002)

Discovery Timeline

  • 2024-01-15 - CVE-2024-22207 published to the National Vulnerability Database (NVD)
  • 2026-06-17 - Last updated in NVD database

Technical Details for CVE-2024-22207

Vulnerability Analysis

The flaw resides in the plugin's route registration logic within lib/routes.js. When baseDir is not provided, the plugin registers fastify-static with a root path pointing to the module's own directory via path.join(__dirname, '..'). A catch-all GET /* route then serves any file requested under the Swagger UI endpoint using reply.sendFile(file). This exposes internal plugin files, dependency assets, and any other content under that directory to unauthenticated HTTP clients. Because Swagger UI endpoints are typically mounted at predictable paths, attackers can discover and request files without prior reconnaissance.

Root Cause

The root cause is an insecure default configuration [CWE-1188]. The plugin assumed a safe fallback directory when baseDir was omitted, but the fallback pointed at the module's parent directory and combined with an unrestricted wildcard route handler. No path validation or allowlist constrained which files could be returned.

Attack Vector

Exploitation requires only network access to the application exposing the Swagger UI route. An attacker issues GET requests to the Swagger UI mount point with a target filename appended. The static file handler resolves and returns the requested file from the plugin's directory. No authentication, user interaction, or privileges are required.

javascript
// Patch excerpt from lib/routes.js - commit 13d799a2c5f14d3dd5b15892e03bbcbae63ee6f7
   decorateReply: false
 })

-  fastify.register(fastifyStatic, {
-    root: opts.baseDir || path.join(__dirname, '..'),
-    serve: false
-  })
+  if (opts.baseDir) {
+    fastify.register(fastifyStatic, {
+      root: opts.baseDir,
+      serve: false
+    })

-  // Handler for external documentation files passed via $ref
-  fastify.route({
-    url: '/*',
-    method: 'GET',
-    schema: { hide: true },
-    ...hooks,
-    handler: function (req, reply) {
-      const file = req.params['*']
-      reply.sendFile(file)
-    }
-  })
+    // Handler for external documentation files passed via $ref
+    fastify.route({
+      url: '/*',
+      method: 'GET',
+      schema: { hide: true },
+      ...hooks,

Source: fastify-swagger-ui commit 13d799a. The patch gates both the static file registration and the wildcard route behind an explicit baseDir check, removing the insecure default behavior.

Detection Methods for CVE-2024-22207

Indicators of Compromise

  • HTTP GET requests to Swagger UI routes targeting filenames such as package.json, lib/routes.js, or files under node_modules/
  • Anomalous 200 OK responses from Swagger UI endpoints returning non-HTML content types
  • Repeated requests enumerating files beneath the Swagger UI mount path

Detection Strategies

  • Review installed @fastify/swagger-ui versions in dependency manifests (package.json, package-lock.json) and flag any version below 2.1.0
  • Inspect application configuration to confirm whether the baseDir option is set when registering the plugin
  • Deploy web application firewall rules that match path traversal patterns and non-documentation file extensions against Swagger UI routes

Monitoring Recommendations

  • Log and alert on HTTP responses from Swagger UI endpoints that serve content types other than text/html, application/javascript, or text/css
  • Monitor outbound responses for sensitive filenames such as .env, package.json, or source files leaving documentation routes
  • Track request volume to /documentation/* or custom Swagger routes for enumeration patterns

How to Mitigate CVE-2024-22207

Immediate Actions Required

  • Upgrade @fastify/swagger-ui to version 2.1.0 or later in all Fastify applications
  • Audit production deployments for exposed Swagger UI endpoints and restrict access where documentation is not required externally
  • Rotate any secrets that may have been readable from the plugin's directory if exposure is suspected

Patch Information

The fix is available in @fastify/swagger-ui version 2.1.0. Reference the GitHub Security Advisory GHSA-62jr-84gf-wmg4 and the upstream commit 13d799a for implementation details. NetApp customers should consult the NetApp Security Advisory NTAP-20240216-0002 for product-specific guidance.

Workarounds

  • Set the baseDir option explicitly when registering @fastify/swagger-ui to constrain the static file root to a directory containing only intended documentation assets
  • Restrict access to Swagger UI routes using authentication middleware or network-level controls until the upgrade is deployed
  • Disable Swagger UI entirely in production environments where API documentation is not required
bash
# Upgrade the vulnerable package to the fixed version
npm install @fastify/swagger-ui@^2.1.0

# Example safe registration with baseDir explicitly set
# fastify.register(require('@fastify/swagger-ui'), {
#   routePrefix: '/documentation',
#   baseDir: path.join(__dirname, 'docs')
# })

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.