Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

marked(">".repeat(5000)) crashes with recursion error #1462

Closed
andersk opened this issue Apr 8, 2019 · 3 comments · Fixed by #1464
Closed

marked(">".repeat(5000)) crashes with recursion error #1462

andersk opened this issue Apr 8, 2019 · 3 comments · Fixed by #1464
Labels
has PR The issue has a Pull Request associated L0 - security A security vulnerability within the Marked library is discovered

Comments

@andersk
Copy link
Contributor

andersk commented Apr 8, 2019

Describe the bug

marked(">".repeat(5000)) crashes with a recursion error. The exact bound is JS engine dependent, of course: I get the error with Node at 3842, Chrome at 3931, and Firefox at 49392.

To Reproduce

Steps to reproduce the behavior:

$ node
> const marked = require('./lib/marked');
> marked(">".repeat(5000));
RangeError: Maximum call stack size exceeded
Please report this to https://github.com/markedjs/marked.
    at RegExp.exec (<anonymous>)
    at Lexer.token (/home/anders/markdown/marked/lib/marked.js:295:37)
    at Lexer.token (/home/anders/markdown/marked/lib/marked.js:307:12)
    at Lexer.token (/home/anders/markdown/marked/lib/marked.js:307:12)
    at Lexer.token (/home/anders/markdown/marked/lib/marked.js:307:12)
    at Lexer.token (/home/anders/markdown/marked/lib/marked.js:307:12)
    at Lexer.token (/home/anders/markdown/marked/lib/marked.js:307:12)
    at Lexer.token (/home/anders/markdown/marked/lib/marked.js:307:12)
    at Lexer.token (/home/anders/markdown/marked/lib/marked.js:307:12)
    at Lexer.token (/home/anders/markdown/marked/lib/marked.js:307:12)

Expected behavior

Marked should avoid algorithms that rely on unbounded recursion.

@UziTech
Copy link
Member

UziTech commented Apr 9, 2019

commonmark.js doesn't seem to have a limit.
markdown-it limits it at 100 nested blockquotes.

Not sure the best way to do this.

@UziTech UziTech mentioned this issue Apr 9, 2019
6 tasks
@UziTech
Copy link
Member

UziTech commented Apr 9, 2019

commonmark.js seems to treat nested block quotes as a special case so it can have as many as given without recursion. I have a PoC for marked at #1464

I'm wondering if there are other ways to trigger unbounded recursion in nested blockquotes.

Nested lists probably have the same issue.

@UziTech UziTech added the L0 - security A security vulnerability within the Marked library is discovered label Apr 9, 2019
@UziTech
Copy link
Member

UziTech commented Apr 9, 2019

I also think we have to decide if this is something we should fix or if throwing an error is good enough considering the following:

  1. Highly unlikely you would have 1000+ nested blockquotes with normal use.
  2. We can't reliably prevent a malicious actor from causing marked to throw an error.

@UziTech UziTech added the has PR The issue has a Pull Request associated label Apr 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has PR The issue has a Pull Request associated L0 - security A security vulnerability within the Marked library is discovered
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants