Introducing The Sweep: OX’s New Live Security Research Series
Register Now
Breaking: The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Read the Report
Are you exposed? Connect your apps in minutes.
Scan your apps free

@fastify/swagger-ui

Latest version: v6.1.5

Overview

Last scanned
20 Nov 2026
Published
20 Nov 2026
npm package Publisher: eomm, matteo.collina
192 Stars
48 Forks
5 Versions
9.0M Downloads
JavaScript Repo language

Scan summary

@fastify/swagger-ui was last scanned on 20 Nov 2026 at version 6.1.5. Risk score 0 of 100. No malicious behavior was detected.

  • Releases: 5 versions; the latest 2 were published within 7 days (14–20 Nov 2026).
  • Findings: No rules fired in version 6.1.5.
  • Downloads: 9,018,773 downloads.

Versions

5 versions published
Versions and the rules that fired in each
VersionPublishedStatus
6.1.5 LATEST 20 Nov 2026 No rules fired
6.1.4 14 Nov 2026 No rules fired
6.1.3 3 Nov 2026 No rules fired
6.1.2 9 Oct 2026 Not shown
6.1.1 28 Jul 2026 Not shown

No rules fired in 6.1.5

Findings

Findings for v6.1.5. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.

The score describes 6.1.5; other versions have their own rules, not their own score.

Known vulnerabilities

1 CVE · last 15 Jan 2024

0 CRITICAL 0 HIGH 1 MEDIUM 0 LOW

Versions

  • ≥ 2.1.0
  • ≥ 2.0.0, < 2.1.0 1 MEDIUM
  • < 2.0.0

Vulnerabilities

  • CVE-2024-22207 Medium 15 Jan 2024 Default swagger-ui configuration exposes all files in the module Fixed in 2.1.0

README

The publisher’s own README, as collected from the registry.

@fastify/swagger-ui

NPM version CI neostandard javascript style

A Fastify plugin for serving Swagger UI.

Install

npm i @fastify/swagger-ui
Compatibility
Plugin version Fastify version Swagger Plugin Version
^5.x ^5.x ^9.x
^2.x ^4.x ^8.x
^1.x ^4.x ^8.x

Please note that if a Fastify version is out of support, then so are the corresponding versions of this plugin in the table above. See Fastify's LTS policy for more details.

Usage

Add it with @fastify/swagger to your project with register, pass it some options, call the swagger API, and you are done!

import fastify from 'fastify'

const app = fastify()

await app.register(import('@fastify/swagger'))

await app.register(import('@fastify/swagger-ui'), {
  routePrefix: '/documentation',
  uiConfig: {
    docExpansion: 'full',
    deepLinking: false
  },
  uiHooks: {
    onRequest: function (request, reply, next) { next() },
    preHandler: function (request, reply, next) { next() }
  },
  staticCSP: true,
  transformStaticCSP: (header) => header,
  transformSpecification: (swaggerObject, request, reply) => { return swaggerObject },
  transformSpecificationClone: true
})

app.put('/some-route/:id', {
  schema: {
    description: 'post some data',
    tags: ['user', 'code'],
    summary: 'qwerty',
    params: {
      type: 'object',
      properties: {
        id: {
          type: 'string',
          description: 'user id'
        }
      }
    },
    body: {
      type: 'object',
      properties: {
        hello: { type: 'string' },
        obj: {
          type: 'object',
          properties: {
            some: { type: 'string' }
          }
        }
      }
    },
    response: {
      201: {
        description: 'Successful response',
        type: 'object',
        properties: {
          hello: { type: 'string' }
        }
      },
      default: {
        description: 'Default response',
        type: 'object',
        properties: {
          foo: { type: 'string' }
        }
      }
    },
    security: [
      {
        "apiKey": []
      }
    ]
  }
}, (req, reply) => {})

await app.ready()

Security note: apiKey in the security array is the name of the security scheme declared in components.securitySchemes (OpenAPI 3) or securityDefinitions (Swagger 2.0), not an API key value. The empty array represents scopes and remains empty for API key authentication.

API

Register options
Options
Option Default Description
baseDir undefined Directory from which the Swagger UI static assets (served under <routePrefix>/static/) are loaded, instead of the static folder shipped with this plugin. Any other file in that directory is also served relative to routePrefix, e.g. spec files referenced via $ref. When not set, only the bundled Swagger UI assets are served. Provided value should be an absolute path without trailing slash. See Bundling.
initOAuth {} Configuration options for Swagger UI initOAuth.
routePrefix '/documentation' Overwrite the default Swagger UI route prefix.
indexPrefix '' External path prefix added to the asset links in the index page, for when the Fastify server is behind path based routing (e.g. NGINX). See Running behind a reverse proxy.
staticCSP false Enable CSP header for static resources.
transformStaticCSP undefined Synchronous function to transform CSP header for static resources if the header has been previously set.
transformSpecification undefined Synchronous function to transform the swagger document.
transformSpecificationClone true Provide a deepcloned swaggerObject to transformSpecification
uiConfig {} Configuration options for Swagger UI.
uiHooks {} Additional hooks for the documentation's routes, including the static assets served under <routePrefix>/static/. You can provide the onRequest and preHandler hooks with the same route's options interface.
theme {} Add custom JavaScript and CSS to the Swagger UI web page
logLevel info Allow to define route log level.

The plugin will expose the documentation with the following APIs:

URL Description
'/documentation/json' The JSON object representing the API
'/documentation/yaml' The YAML object representing the API
'/documentation/' The swagger UI
'/documentation/*' External files that you may use in $ref
uiConfig

To configure Swagger UI, you need to modify the uiConfig option. It's important to ensure that functions are self-contained. Keep in mind that you cannot modify the backend code within the uiConfig functions, as these functions are processed only by the browser. You can reference the Swagger UI element using ui, which is assigned to window.ui.

Example
const fastify = require('fastify')()

await fastify.register(require('@fastify/swagger'))

await fastify.register(require('@fastify/swagger-ui'), {
  uiConfig: {
    onComplete: function () {
      alert('ui has type of ' + typeof ui) // 'ui has type of object'
      alert('fastify has type of ' + typeof fastify) // 'fastify has type of undefined'
      alert('window has type of ' + typeof window) // 'window has type of object'
      alert('global has type of ' + typeof global) // 'global has type of undefined'
    }
  }
})
Multiple specifications

Swagger UI can show a "Select a definition" dropdown to switch between several specifications. Pass the urls option through uiConfig:

await fastify.register(require('@fastify/swagger-ui'), {
  uiConfig: {
    urls: [
      { url: '/documentation/json', name: 'Main API' },
      { url: '/documentation/openapi.yaml', name: 'Other API' }
    ]
  }
})

Each entry is fetched by the browser, so every URL must be reachable from the client (e.g. the spec exposed by this plugin, a file served from baseDir, another Fastify route or an external host). Prefer absolute paths: relative ones (e.g. ./json) are resolved against the page URL, so they only work when the documentation is opened with a trailing slash (/documentation/).

The dropdown is rendered by the topbar of the default StandaloneLayout, so it is not shown if uiConfig.layout is set to BaseLayout. Use urls.primaryName to choose which definition is selected on load:

uiConfig: {
  urls: [
    { url: '/documentation/json', name: 'Main API' },
    { url: '/documentation/openapi.yaml', name: 'Other API' }
  ],
  'urls.primaryName': 'Other API'
}

The URLs are used as-is: if the server is exposed under an external path prefix (see Running behind a reverse proxy), include that prefix in each url (e.g. /service/documentation/json).

transformSpecification

There can be use cases, where you want to modify the swagger definition on request. E.g. you want to modify the server definition based on the hostname of the request object. In such a case you can utilize the transformSpecification-option.

Example
const fastify = require('fastify')()

await fastify.register(require('@fastify/swagger'))

await fastify.register(require('@fastify/swagger-ui'), {
  transformSpecification: (swaggerObject, req, reply) => {
    swaggerObject.host = req.hostname
    return swaggerObject
  }
})

By default fastify.swagger() will be deepcloned and passed to the transformSpecification-function, as fastify.swagger() returns a mutatable Object. You can disable the deepcloning by setting transformSpecificationClone to false. This is useful, if you want to handle the deepcloning in the transformSpecification function.

Example with caching
const fastify = require('fastify')()
const LRU = require('tiny-lru').lru
const rfdc = require('rfdc')()

await fastify.register(require('@fastify/swagger'))

const swaggerLru = new LRU(1000)
await fastify.register(require('@fastify/swagger-ui'), {
  transformSpecificationClone: false,
  transformSpecification: (swaggerObject, req, reply) => {
    if (swaggerLru.has(req.hostname)) {
      return swaggerLru.get(req.hostname)
    }
    const clonedSwaggerObject = rfdc(swaggerObject)
    clonedSwaggerObject.host = req.hostname
    swaggerLru.set(req.hostname, clonedSwaggerObject)
    return clonedSwaggerObject
  }
})
theme

You can add custom JavaScript and CSS to the Swagger UI web page by using the theme option.

Example
const fastify = require('fastify')()

await fastify.register(require('@fastify/swagger'))

await fastify.register(require('@fastify/swagger-ui'), {
  theme: {
    title: 'My custom title',
    js: [
      { filename: 'special.js', content: 'alert("client javascript")' }
    ],
    css: [
      { filename: 'theme.css', content: '* { border: 1px red solid; }' }
    ],
    favicon: [
      {
        filename: 'favicon.png',
        rel: 'icon',
        sizes: '16x16',
        type: 'image/png',
        content: Buffer.from('iVBOR...', 'base64')
      }
    ]
  }
})

You can add custom JavaScript and CSS to the Swagger UI web page by using the theme option.

logo

It's possible to override the logo displayed in the top bar by specifying:

await fastify.register(require('@fastify/swagger-ui'), {
  logo: {
    type: 'image/png',
    content: Buffer.from('iVBOR...', 'base64'),
    href: '/documentation',
    target: '_blank'
  },
  theme: {
    favicon: [
      {
        filename: 'favicon.png',
        rel: 'icon',
        sizes: '16x16',
        type: 'image/png',
        content: Buffer.from('iVBOR...', 'base64')
      }
    ]
  }
})
Protect your documentation routes

You can protect your documentation by configuring an authentication hook. Here is an example using the @fastify/basic-auth plugin:

Example

OX Radar and Response Center

Find threats in your stack.

OX Radar can check high-priority threats, like critical package CVEs, against your context.

Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.

Where it’s listed

The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).

  • npm @fastify/swagger-ui

References

The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.

Powered by Read the latest findings

Scan your whole stack

Group 1261154050 1
Group 1261154050
 

From OX Research Newsroom

Cry2Wolf: How to Tell a Real Bug from a Nothingburger
AI & VibeSec

Cry2Wolf: Not Every Branded Bug Deserves a Fire Drill

Ethersphere Hijacked With Crypto Stealing Malware (1)
npm

Ethersphere Hijacked With Crypto Stealing Malware Via Github & npm

The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Vulnerability Insights

The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?

Frame 2085668439 (1)
Group 1261154229