Exponential catastrophic backtracking (ReDoS) in marked
Description
Marked is a markdown parser and compiler. Prior to version 4.0.10, the regular expression inline.reflinkSearch may cause catastrophic backtracking against some strings and lead to a denial of service (DoS). Anyone who runs untrusted markdown through a vulnerable version of marked and does not use a worker with a time limit may be affected. This issue is patched in version 4.0.10. As a workaround, avoid running untrusted markdown through marked or run marked on a worker thread and set a reasonable time limit to prevent draining resources.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
markednpm | < 4.0.10 | 4.0.10 |
Affected products
1- Range: < 4.0.10
Patches
28f806573a3f6fix(security): fix redos vulnerabilities
c4a3ccd344b6Merge pull request from GHSA-rrrm-qjm4-v8hf
4 files changed · +17 −4
src/rules.js+9 −4 modified@@ -25,7 +25,7 @@ export const block = { + '|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) open tag + '|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) closing tag + ')', - def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/, + def: /^ {0,3}\[(label)\]: *(?:\n *)?<?([^\s>]+)>?(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/, table: noopTest, lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/, // regex template, placeholders will be replaced according to different paragraph @@ -34,7 +34,7 @@ export const block = { text: /^[^\n]+/ }; -block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/; +block._label = /(?!\s*\])(?:\\.|[^\[\]\\])+/; block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/; block.def = edit(block.def) .replace('label', block._label) @@ -162,8 +162,8 @@ export const inline = { + '|^<![a-zA-Z]+\\s[\\s\\S]*?>' // declaration, e.g. <!DOCTYPE html> + '|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>', // CDATA section link: /^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/, - reflink: /^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/, - nolink: /^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/, + reflink: /^!?\[(label)\]\[(ref)\]/, + nolink: /^!?\[(ref)\](?:\[\])?/, reflinkSearch: 'reflink|nolink(?!\\()', emStrong: { lDelim: /^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/, @@ -230,6 +230,11 @@ inline.link = edit(inline.link) inline.reflink = edit(inline.reflink) .replace('label', inline._label) + .replace('ref', block._label) + .getRegex(); + +inline.nolink = edit(inline.nolink) + .replace('ref', block._label) .getRegex(); inline.reflinkSearch = edit(inline.reflinkSearch, 'g')
test/specs/redos/cubic_def.cjs+4 −0 added@@ -0,0 +1,4 @@ +module.exports = { + markdown: `[x]:${' '.repeat(1500)}x ${' '.repeat(1500)} x`, + html: `<p>[x]:${' '.repeat(1500)}x ${' '.repeat(1500)} x</p>`, +};
test/specs/redos/reflink_redos.html+1 −0 added@@ -0,0 +1 @@ +<p>[[]([]([]([]([]([]([]([]([]([]([]([]([]([]([]([]([]([]([]([]([]([]([]([]([]([]([]([]([]([]([</p>
test/specs/redos/reflink_redos.md+3 −0 added@@ -0,0 +1,3 @@ +[x]: x + +[\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\](\[\]([
Vulnerability mechanics
Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
7- github.com/advisories/GHSA-5v2h-r2cx-5xgjghsaADVISORY
- lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/AIXDMC3CSHYW3YWVSQOXAWLUYQHAO5UX/mitrevendor-advisory
- nvd.nist.gov/vuln/detail/CVE-2022-21681ghsaADVISORY
- github.com/markedjs/marked/commit/8f806573a3f6c6b7a39b8cdb66ab5ebb8d55a5f5ghsaWEB
- github.com/markedjs/marked/commit/c4a3ccd344b6929afa8a1d50ac54a721e57012c0ghsaWEB
- github.com/markedjs/marked/security/advisories/GHSA-5v2h-r2cx-5xgjghsaWEB
- lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/AIXDMC3CSHYW3YWVSQOXAWLUYQHAO5UXghsaWEB
News mentions
0No linked articles in our index yet.