How to fix: Outdated Swagger UI bundle loaded
The page loads a Swagger UI bundle older than 4.1.3, read from the version embedded in the asset path or package specifier.
Why it matters
Swagger UI before 4.1.3 is affected by a DOM XSS in its own rendering of a specification (CVE-2021-46708). Because Swagger UI is commonly configured to load a spec from a URL supplied in the query string, an attacker can serve a crafted specification and get script execution on the origin hosting the documentation, which is often the same origin as the API session cookie.
The version is read from the asset path or the package specifier, so it reports what the page references rather than what a CDN might silently substitute. Documentation pages are easy to forget in dependency upgrades because they are usually a static bundle pinned once and never touched again. If the page also accepts a ?url= or ?configUrl= parameter, the exposure is direct rather than theoretical.
How to fix it
- 1Upgrade swagger-ui-dist to a current release and redeploy the documentation page.
- 2Do not let the spec URL come from the query string; hardcode it, or validate it against an allowlist.
- 3Serve the documentation from a separate origin from the authenticated application so an XSS there cannot reach session cookies.
- 4Pin the bundle with a Subresource Integrity hash if it is loaded from a CDN.
Code examples
Hardcode the spec URL
SwaggerUIBundle({
url: '/openapi.json', // never new URLSearchParams(...).get('url')
dom_id: '#swagger-ui',
deepLinking: false,
});Pin the bundle with SRI
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui-bundle.js"
integrity="sha384-REPLACE_WITH_REAL_HASH"
crossorigin="anonymous"></script>References
Detected automatically by VulnRadar. The check id is api-swagger-ui-outdated-version, stable across every scan so you can filter or diff on it.
More api checks
- LowTRACE method referenced in API response body
- InfoREST endpoint allows DELETE
- LowGraphQL introspection field suggestions
- MediumGraphQL endpoint has no rate-limit headers
- LowOpenAPI server URL leaks internal host
- LowCORS preflight result not cached
- HighBearer token in URL query string
- MediumJSONP callback parameter accepted
Questions
- How severe is Outdated Swagger UI bundle loaded?
- VulnRadar rates this medium severity in the api category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id api-swagger-ui-outdated-version, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does Outdated Swagger UI bundle loaded map to?
- It maps to CWE-79. In the OWASP Top 10 it falls under A06:2021.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.