Skip to content

trim code after regexp#945

Closed
UziTech wants to merge 1 commit into
markedjs:masterfrom
UziTech:patch-1
Closed

trim code after regexp#945
UziTech wants to merge 1 commit into
markedjs:masterfrom
UziTech:patch-1

Conversation

@UziTech

@UziTech UziTech commented Oct 10, 2017

Copy link
Copy Markdown
Member

Trimming the code after the regexp (instead of inside the regexp) seems to fix the regexp DOS described in #937

fixes #937

here is code to test it:

function genstr(len, chr) {
  var result = '';
  for (i=0; i<=len; i++) {
    result = result + chr;
  }
  return result;
}

var regex,start,output,end;

var input =  '`x' + genstr(50000, ' ') + 'x`';

regex = /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/;
start = process.hrtime();
output = '<code>'+regex.exec(input)[2]+'</code>';
end = process.hrtime(start);

console.info(' DOS execution time (hr): %ds %dms', end[0], end[1] / 1000000);

regex = /^(`+)([\s\S]*?[^`])\1(?!`)/;
start = process.hrtime();
output = '<code>'+regex.exec(input)[2].trim()+'</code>';
end = process.hrtime(start);

console.info('Trim execution time (hr): %ds %dms', end[0], end[1] / 1000000);

@deksden deksden mentioned this pull request Oct 17, 2017
@kunagpal

Copy link
Copy Markdown

@UziTech Could you send this pull request to https://github.com/8fold/marked instead? It looks like this module is unmaintained 😞

@UziTech

UziTech commented Oct 17, 2017

Copy link
Copy Markdown
Member Author

Added the pull request https://github.com/8fold/marked/pull/1

@marcoscaceres

Copy link
Copy Markdown

@guypod or @maban, any chance of evaluating and adding this patch to @snyk? It might solve for https://snyk.io/vuln/npm:marked:20170907

@karenyavine

Copy link
Copy Markdown

Hey! We're already looking into it :)

@karenyavine

Copy link
Copy Markdown

We released a patch for this here: https://snyk.io/vuln/npm:marked:20170907
@marcoscaceres @UziTech

@marcoscaceres

Copy link
Copy Markdown

Amazing! Thanks so much @karenyavine! 🙏

@UziTech

UziTech commented Jan 6, 2018

Copy link
Copy Markdown
Member Author

this was merged with v0.3.9

@UziTech UziTech closed this Jan 6, 2018
@UziTech UziTech deleted the patch-1 branch April 5, 2018 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vulnerable Regular Expression

5 participants