
PEACH
Un cadre d’isolation des locataires
printCustomDirective writes customDirective descriptor output raw into the Directives section| Field | Value |
|---|---|
| Package | @graphql-markdown/docusaurus (npm, pkg:npm/%40graphql-markdown/docusaurus); vulnerable code is in packages/printer-legacy (@graphql-markdown/printer-legacy) |
| Repository | https://github.com/graphql-markdown/graphql-markdown |
| Component | printCustomDirective in packages/printer-legacy/src/decorator.ts |
| Vulnerability class | MDX/JSX injection (cross-site scripting into generated documentation pages) |
| CWE | CWE-79 |
| Severity (reporter assessment) | High |
| Verified against | Commit f4da8ad30fce5c9e001d082f0580a15968b6fd70 (@graphql-markdown/docusaurus 1.39.2, @graphql-markdown/printer-legacy 1.19.4 at that commit). Other releases were not verified. |
| API surface | Public documented API: the default export of @graphql-markdown/docusaurus (Docusaurus plugin) and its graphql-to-doc command, configured through extensions.graphql-markdown.customDirective |
| Affected in default configuration | No. The customDirective option (documented, deprecated in favour of decorators, still supported) must be configured with a descriptor that puts schema values into its output. |
The legacy printer's customDirective adapter renders each descriptor's output twice. The description slot (customDirective:description) escapes it with escapeMDX(), but the built-in Directives section, written by printCustomDirective, concatenates the same descriptor string directly into the page MDX (decorator.ts:173). Any MDX/JSX in the descriptor output is therefore compiled and rendered as code instead of being shown as text.
The documented directiveDescriptor helper reads per-node directive argument values with getTypeDirectiveValues() and interpolates them into the descriptor text (for example ${requires}). Remote and third-party schemas are a documented schema source, so a directive argument controlled by whoever authors or can edit the schema ends up in the generated page.
customDirective:description slot -> escaped with escapeMDX(text), decorator.ts:273printCustomDirective -> raw interpolation, decorator.ts:173An attacker who can influence the GraphQL schema being documented can inject arbitrary MDX/JSX into the generated Docusaurus pages. During verification, compiling and rendering the generated page the way a Docusaurus build does:
globalThis.__GQLMD_PWNED__ was set to 'code-executed'), and<img> element with an attacker-supplied onError JSX handler attached. That handler would run in readers' browsers after hydration. The browser-side execution was inferred from the rendered output and was not observed directly.</p> broke MDX compilation, so the same input can also make the documentation build fail (denial of service).
What this adds over safe behaviour: the site owner meant to publish a plain-text directive description. Without this bug, a schema author can only change the text shown on the page, as the escaped description slot shows. With it, the schema author gets code execution at build time and script in the published site.
Not scored: no CVSS vector has been assigned. Whether a site can be exploited depends on its configuration and on who controls its schema. Not affected:customDirective@graphql-markdown/docusaurus with the customDirective option configured with a descriptor (directive-specific or wildcard). This option is off by default. It is deprecated in favour of decorators but still supported.directiveDescriptor helper does this (packages/helpers/src/directives/descriptor.ts:83-94).docs/advanced/custom-directive.md:70-91 documents a descriptor that interpolates ${requires} from the schema, and docs/advanced/custom-directive.md:123-147 documents a wildcard directiveDescriptor. Neither section warns that descriptor output is treated as raw MDX or must be escaped by the caller.getTypeDirectiveValues and interpolated by directiveDescriptor (packages/helpers/src/directives/descriptor.ts:83-94).customDirective handlers into printer decorators with buildCustomDirectiveDecorators (packages/core/src/generator.ts:444-452). getCustomDirectiveResolver calls the configured descriptor callback (packages/printer-legacy/src/decorator.ts:129-145, :163-167).printCustomDirective concatenates the returned descriptor into the MDX unescaped: return \${SectionLevels.LEVEL.repeat(4)} ${typeNameLink}${MARKDOWN_EOL} ${description}${MARKDOWN_EOL} `; ([packages/printer-legacy/src/decorator.ts:173](https://github.com/graphql-markdown/graphql-markdown/blob/f4da8ad30fce5c9e001d082f0580a15968b6fd70/packages/printer-legacy/src/decorator.ts#L173)). The description slot for the same descriptor escapes it with escapeMDX ([packages/printer-legacy/src/decorator.ts:255-276`](https://github.com/graphql-markdown/graphql-markdown/blob/f4da8ad30fce5c9e001d082f0580a15968b6fd70/packages/printer-legacy/src/decorator.ts#L255-L276)).customDirectives decorator calls printCustomDirective (packages/printer-legacy/src/decorator.ts:241-252). That decorator is used in production by core runGeneration (packages/core/src/generator.ts:444-452), which the Docusaurus plugin's graphql-to-doc command reaches.packages/printer-legacy/src/decorator.ts, lines 154-174 at f4da8ad30fce5c9e001d082f0580a15968b6fd70. The excerpt is verbatim, with intermediate lines omitted at the ... marker. See the full range at the pinned commit.
const description = getCustomDirectiveResolver(
"descriptor",
type,
constDirectiveOption,
);
...
return `${SectionLevels.LEVEL.repeat(4)} ${typeNameLink}${MARKDOWN_EOL} ${description}${MARKDOWN_EOL} `; // SINK (line 173): descriptor output interpolated rawThe safe sibling is the customDirective:description slot in the same file (lines 255-276), which applies escapeMDX(text) at line 273 before rendering.
Verified at commit f4da8ad30fce5c9e001d082f0580a15968b6fd70 (@graphql-markdown/docusaurus 1.39.2, @graphql-markdown/printer-legacy 1.19.4). The end-to-end test called the real CLI runGraphQLMarkdown, which runs core buildConfig/generateDocFromSchema with the Docusaurus MDX formatter (packages/docusaurus/src/mdx). The configuration and schema below are equivalent. The exact test file was not included in the verification evidence.
// .graphqlrc.js: descriptor built with the documented directiveDescriptor helper
const { directiveDescriptor } = require("@graphql-markdown/helpers");
module.exports = {
schema: "./schema.graphql",
extensions: {
"graphql-markdown": {
customDirective: {
version: {
descriptor: (directive, node) =>
directiveDescriptor(directive, node, "Requires version ${min}"),
},
},
},
},
};
# schema.graphql (attacker-controlled)
directive @version(min: String!) on OBJECT
type Widget @version(min: """1.0
<img src="x" onError={() => alert(document.cookie)} />
{globalThis.__GQLMD_PWNED__ = 'code-executed'}""") {
id: ID
}To reproduce, generate the docs (for example npx docusaurus graphql-to-doc), then inspect the generated widget.mdx. To confirm execution, compile and render that file with @mdx-js/mdx v3 evaluate plus React server-side rendering, which is what a Docusaurus build does.
Observed in the generated widget.mdx:
customDirective:description) holds the escaped descriptor (<img ..., {...). Type descriptions are escaped too.### Directives section written by printCustomDirective holds the same descriptor raw: <img src="x" onError={() => alert(document.cookie)} /> and {globalThis.__GQLMD_PWNED__ = ...}.globalThis.__GQLMD_PWNED__ = 'code-executed' in the Node process and emitted an <img> element with the onError handler attached.</p> made MDX compilation fail.Escape descriptor output in printCustomDirective before interpolating it, matching the escapeMDX() already applied by the customDirective:description slot.
// packages/printer-legacy/src/decorator.ts, printCustomDirective
return `${SectionLevels.LEVEL.repeat(4)} ${typeNameLink}${MARKDOWN_EOL} ${escapeMDX(description)}${MARKDOWN_EOL} `;If raw MDX from descriptors is meant to be an advanced capability, expose it through a separate, explicitly unsafe option instead of treating descriptor output as raw by default. Notes:
docs/advanced/custom-directive.md:123-147) are expected to reach the same printCustomDirective sink and should be covered by the same fix. This was not verified separately.docs/advanced/custom-directive.md that descriptor output is treated as text.
Suggested regression test alongside the existing printer-legacy decorator tests (exact file not verified): for a descriptor that returns <Injected /> (or {globalThis.x = 1}), assert that the output of printCustomDirective does not contain the raw string and does contain escapeMDX("<Injected />"), matching the description-slot output.Scope confirmed on main. customDirective is deprecated. @graphql-markdown/core converts it into three decorators built by buildCustomDirectiveDecorators in packages/printer-legacy/src/decorator.ts:
customDirectives: the built-in "Directives" section. printCustomDirective writes the descriptor output raw. This is the vulnerable sink. It has been there since customDirective was introduced (@graphql-markdown/printer-legacy 1.3.0, @graphql-markdown/docusaurus 1.18.0), and wildcard ("*") descriptors reach it too.customDirective:description: already escapes the same descriptor output with escapeMDX.customDirective:tags: badge text is already escaped with escapeMDX, and the documented directiveTag helper prints only the directive name, which must be a valid GraphQL name.
Decorators declared directly under the decorators option are not affected by this advisory. Their render callback is user code that returns MDX by design, so the user's own code decides whether schema values are escaped.
Fix. printCustomDirective will escape descriptor output with escapeMDX, so descriptor output is always treated as text, as the description slot already does. Patched versions: @graphql-markdown/printer-legacy 1.20.0, @graphql-markdown/docusaurus 1.39.3.
Workaround until you upgrade: escape schema values in your descriptor before returning them (for example with escapeMDX from @graphql-markdown/utils), or move from customDirective to decorators.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."