GHSA-x2g8-7ch4-h792: 
JavaScript Analyse et atténuation de la vulnérabilité

Stored XSS / MDX injection in @graphql-markdown: one unmatched backtick disables escapeMDX() for every preceding special character in a schema description

Report metadata

FieldValue
Package@graphql-markdown/utils
Repositoryhttps://github.com/graphql-markdown/graphql-markdown
ComponentescapeMDX in packages/utils/src/string.ts, reached through generateDocFromSchema
Vulnerability classInjection: stored XSS and MDX/JSX expression injection through incomplete output escaping
CWECWE-79
Severity (reporter assessment)High
Verified againstCommit f4da8ad30fce5c9e001d082f0580a15968b6fd70 (1.42.0-era main). No other commits or released versions were checked, so the affected version range is not verified.
API surfacePublic documented API: buildConfig(...) + generateDocFromSchema(config), and the gqlmd CLI (graphql-to-doc)
Affected in default configurationYes. No non-standard option is needed: the stock Markdown output already contains the raw HTML. Choosing the documented MDX output additionally exposes MDX expression and JSX interpretation. Whether HTML executes depends on the downstream renderer allowing raw HTML or compiling the page as MDX.
No CVE or GHSA has been assigned for this issue as far as we know.

Summary

escapeMDX() decides whether a special character ({ < _ * > }) sits inside inline code by checking that the entire remaining string contains an even number of backticks. If a schema description puts raw HTML or MDX before a single unmatched backtick, the lookahead fails for every special character before it. That content then goes into the generated Markdown/MDX verbatim instead of being encoded as &#x....; entities. A lone backtick does not open a code span, so the content it "protects" is not in code at all. In a consuming app, the tainted input is any GraphQL type description in the schema being documented. The project documents remote introspection/SDL, Git and GitHub schema sources (docs/get-started.md:90-103), so the schema author is often not the docs site operator. The same function handles nearly identical inputs safely, which shows the unsafe case is a bug and not intended behaviour (all three cases go through string.ts:178-182):

  • Description text without a backtick -> fully encoded (for example &#x003C;b&#x003E;)
  • The same text followed by one unmatched backtick -> emitted unchanged, raw HTML/MDX
  • Special characters inside a balanced inline code span -> left as-is by design. This is the documented intent at string.ts:155-175.

Impact

If an attacker controls a schema description, they can inject raw HTML into the generated documentation pages. That is stored XSS in readers' browsers whenever the renderer allows HTML. When the page is compiled as MDX (as Docusaurus does), the attacker can also inject JSX and arbitrary JavaScript expressions. During verification, such an expression ran when the page was rendered server-side, so the injected code runs in the docs site's MDX build/SSR environment as well as in readers' browsers. Here is what the bug changes. Normally <, >, { and } in descriptions become HTML entities and show up as inert text. With the bypass, the attacker moves from schema text into markup and expressions that the documentation renderer executes. Scoring note: we did not compute a CVSS vector. Exploitability depends on the consumer's data flow (where the schema comes from) and on how the generated pages are rendered. Not affected: consumers that only generate docs from fully trusted schemas. The XSS part also does not affect consumers whose renderer neither allows raw HTML nor compiles MDX.

Preconditions

  1. The consumer generates docs with generateDocFromSchema (normally after buildConfig) or the gqlmd CLI, from a schema whose description text is not fully trusted. The project documents remote URL/introspection, Git and GitHub schema sources (docs/get-started.md:90-103).
  2. Default configuration is enough. The stock Markdown output already receives the raw HTML; the specific default option and its source line were not verified.
  3. The attacker can write a type description that contains HTML/MDX followed by an unmatched backtick, for example <img src=x onerror=alert(1)> `` ``.
  4. The generated pages are rendered by a Markdown renderer with raw HTML enabled, or compiled as MDX (for example Docusaurus' MDX format). This needs no non-standard usage, monkey-patching or unusual configuration. packages/core/README.md:20-29 documents direct generation without any warning that schema descriptions must be trusted. The behaviour is not documented as the caller's responsibility.

Data flow

  1. Source: GraphQL type descriptions are loaded from the configured schemaLocation, which may be a remote, Git or GitHub source (packages/core/src/generator.ts:247-262).
  2. Propagation: the description goes into printer page composition in Printer.printType (packages/printer-legacy/src/printer.ts:597-632, call at line 604). type.description is then passed to escapeMDX via formatDescription(type) (packages/printer-legacy/src/common.ts:34-45).
  3. Sink: the parity-based regex leaves special characters before an unmatched trailing backtick untouched: `${String(str)}`.replaceAll(/(?<!`)([{<_*>}])(?=(?:[^`]*`[^`]*`)*[^`]*$)/g, toHTMLUnicode) (packages/utils/src/string.ts:178-182). No later stage escapes it: Printer.printType stores the formatted description section and the renderer writes it out unchanged.
  4. Reachability: core generation calls the printer from the public generateDocFromSchema entry point (packages/core/src/generator.ts:537-541).

Vulnerable code

packages/utils/src/string.ts, lines 178-182 at f4da8ad30fce5c9e001d082f0580a15968b6fd70:

export const escapeMDX = (str: unknown): string => {
  return `${String(str)}`.replaceAll(
    /(?<!`)([{<_*>}])(?=(?:[^`]*`[^`]*`)*[^`]*$)/g, // SINK: lookahead counts backtick parity over the whole remaining string
    toHTMLUnicode,
  );
};

Reproduction

Verified dynamically at commit f4da8ad30fce5c9e001d082f0580a15968b6fd70. The Node.js version and exact CLI flags were not recorded. Unit check from source. The input below comes back from escapeMDX unchanged. The same text without the trailing backtick is fully encoded.

escapeMDX('<img src=x onError={alert(1)} /> {globalThis.pwned = 1} trailing `');
// returned unchanged: no characters encoded

End to end. We ran the built gqlmd CLI (graphql-to-doc) on a schema.graphql containing an object type with the description below, plus a control type with the same kind of content but no trailing backtick. The type name and other schema contents shown here are illustrative.

"""
Benign text <img src="x" onError={() => 0} /> {globalThis.__PWNED__ = "expr-executed-at-render"} trailing `
"""
type Evil {
  ping: String
}

Observed:

  • The description was written verbatim into docs/api/types/objects/evil.md. The control type was emitted as entities (&#x003C;b&#x003E;...).
  • We compiled and rendered the generated page with @mdx-js/mdx v3 and react-dom/server (Docusaurus' MDX format). The output contained a real <img> element, and the JavaScript expression ran: globalThis.__PWNED__ was set. The control page left it undefined. The equivalent programmatic entry point is below. It reaches the same sink, but this exact snippet was not run separately:
import { writeFileSync } from "node:fs";
import { buildConfig, generateDocFromSchema } from "@graphql-markdown/core";
writeFileSync("/tmp/schema.graphql", '"""<img src=x onerror=alert(document.domain)> `"""' + String.fromCharCode(10) + "type Query { ping: String }" + String.fromCharCode(10));
const config = await buildConfig({ schema: "/tmp/schema.graphql", rootPath: "/tmp/docs", baseURL: "api" });
await generateDocFromSchema(config);
  • Expected: the generated page contains &#x003C;img ...&#x003E; (inert text), and MDX braces are encoded.
  • Actual: the generated page contains literal <img ...> and {...} expressions. Rendered as MDX, the image element is created and the expression runs.

Suggested remediation

Swap the parity-based lookahead for a Markdown-aware routine that only preserves special characters inside a confirmed, balanced code span. An unmatched backtick must never turn escaping off. Below is an untested sketch in the project's existing style. It follows the CommonMark rule that a code span closes only on a backtick run of the same length:

const MDX_SPECIAL_CHARS = /[{<_*>}]/g;
const escapeOutsideCode = (text: string): string =>
  text.replaceAll(MDX_SPECIAL_CHARS, toHTMLUnicode);
export const escapeMDX = (str: unknown): string => {
  const input = String(str);
  let result = "";
  let index = 0;
  while (index < input.length) {
    const opener = /`+/g;
    opener.lastIndex = index;
    const open = opener.exec(input);
    if (!open) break;
    const fence = open[0];
    const closer = new RegExp("(?<!`)" + fence + "(?!`)", "g");
    closer.lastIndex = open.index + fence.length;
    const close = closer.exec(input);
    if (!close) {
      // unmatched backtick run: literal text, keep escaping what precedes and follows it
      result += escapeOutsideCode(input.slice(index, open.index + fence.length));
      index = open.index + fence.length;
      continue;
    }
    result += escapeOutsideCode(input.slice(index, open.index));
    result += input.slice(open.index, close.index + fence.length); // balanced code span: preserved
    index = close.index + fence.length;
  }
  return result + escapeOutsideCode(input.slice(index));
};

Notes:

  • The original pattern's (?<!`` ``)` lookbehind also skips any special character that directly follows a backtick, even outside a code span. The sketch drops that behaviour. Check whether any existing test depends on it.
  • Other production callers of escapeMDX go through the same sink and benefit from the same fix: printer-legacy/src/common.ts:39,45,87, printer-legacy/src/badge.ts:102 and printer-legacy/src/decorator.ts:273. We traced only the description path end to end, so whether the others can be exploited is not verified.
  • Inputs with no backticks, or only balanced code spans, already behave correctly. The fix should not change their output. Suggested regression tests alongside the existing tests for packages/utils/src/string.ts (test file name not verified):
  • escapeMDX('<img src=x onerror=alert(1)> `` ``')encodes<and>as</>`.
  • escapeMDX('{globalThis.pwned = 1} trailing `` ``')encodes{and}`.
  • A leading unmatched backtick, and mixed backtick runs (for example a double-backtick opener closed by a single backtick), still encode text outside real code spans.
  • A balanced inline code span such as `<b>` is still preserved unescaped.

Maintainer notes

Patches

Fixed in @graphql-markdown/utils 1.14.3, which @graphql-markdown/core 1.27.0 and @graphql-markdown/docusaurus 1.39.3 pull in. Upgrade, or refresh your lockfile so that @graphql-markdown/utils resolves to 1.14.3 or later. escapeMDX() no longer decides by counting backticks. It now scans the text and leaves MDX special characters unescaped only inside code that Markdown will definitely render as code:

  • an inline code span closed by a backtick run of the same length on the same line
  • a fenced code block that opens at the start of a line and has a matching closing fence Everything else is escaped, including any text around an unmatched backtick. The fix also blocks variants that the remediation suggested in this report would still have let through:
  • an opening backtick escaped with a backslash
  • an inline code span that continues onto a line Markdown starts as a new block, such as a heading
  • a run of three backticks in the middle of a line, which is not a code fence

Behaviour change

The new check is deliberately strict. Some legitimate code is now escaped too:

  • a fenced code block at the very start of a description, or an indented one
  • inline code that wraps onto a second line or contains | In those cases, {, <, >, _ and * inside the code show up as HTML entities (for example &#x007B;). This only affects how the page looks, not its security. To avoid it, start fenced code blocks at column 0 after a line of text, and keep inline code on one line.

Workarounds

If you cannot upgrade yet:

  • generate documentation only from schemas whose descriptions you trust, or
  • remove or escape backticriptions before generating the documentation.

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