VYPR
High severityNVD Advisory· Published Jan 14, 2022· Updated Apr 22, 2025

Exponential catastrophic backtracking (ReDoS) in marked

CVE-2022-21681

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.

PackageAffected versionsPatched versions
markednpm
< 4.0.104.0.10

Affected products

1

Patches

2
8f806573a3f6

fix(security): fix redos vulnerabilities

https://github.com/markedjs/markedTony BrixJan 13, 2022via ghsa
c4a3ccd344b6

Merge pull request from GHSA-rrrm-qjm4-v8hf

https://github.com/markedjs/markedTony BrixJan 13, 2022via ghsa
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

News mentions

0

No linked articles in our index yet.