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

nested lists Maximum call stack size exceeded #1471

Closed
UziTech opened this issue Apr 12, 2019 · 5 comments
Closed

nested lists Maximum call stack size exceeded #1471

UziTech opened this issue Apr 12, 2019 · 5 comments
Labels
category: lists L0 - security A security vulnerability within the Marked library is discovered

Comments

@UziTech
Copy link
Member

UziTech commented Apr 12, 2019

I found another security issue trying to get nested lists to fail with a recursion error similar to #1462

const marked = require('marked');

const iterations = 300;
let spaces = 0;
let markdown = '';
for (let i = 0; i < iterations; i++) {
  markdown += ' '.repeat(spaces) + '- a\n';
  spaces += 2;
}

marked(markdown);

300 iterations takes about 3 seconds
600 iterations takes about 40 seconds

@UziTech UziTech added category: lists L0 - security A security vulnerability within the Marked library is discovered labels Apr 12, 2019
@UziTech
Copy link
Member Author

UziTech commented Apr 12, 2019

commonmark.js has a similar issue commonmark/commonmark.js#160

@andersk
Copy link
Contributor

andersk commented Apr 17, 2019

A more straightforward way to get a recursion error with nested lists is marked('- '.repeat(5000) + 'a').

@UziTech
Copy link
Member Author

UziTech commented Apr 17, 2019

@andersk good call, looks like the DoS is in the number of characters. but we still have an issue with Maximum call stack size exceeded.

I'm not sure this one will be as easy to fix as blockquote since nested lists are not always the only thing in the list item.

We might just have to limit the number of nested lists.

@UziTech UziTech changed the title nested lists create redos nested lists Maximum call stack size exceeded Apr 17, 2019
@x13machine
Copy link
Contributor

Looks like the list regex needs to be fixed or replaced with javascript.

@UziTech
Copy link
Member Author

UziTech commented May 3, 2019

In this case, it isn't a problem with a regex. It is a problem with using recursion in the lexer. The solution would be to use regex and loop like in the block quote fix.

For now I think this is a case where failing is fine because it doesn't cause a redos attack and it is very unlikely someone would legitimately have 5000 nested lists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: lists L0 - security A security vulnerability within the Marked library is discovered
Projects
None yet
Development

No branches or pull requests

3 participants