0

I'm writing a program like this.

const regexp = new RegExp(/* user input */);
if (message.text.match(regexp)) {
  /* do something */
}

I'm afraid of ReDoS so I want to terminate the .match calculation if it runs more than one second or something.

Is there any way to do this on Node.js?

legogo
  • 887
  • 1
  • 8
  • 11
  • No, but usually your frontend, like Nginx, should take care of timeouts. `.match` is not the only thing that can cause the program to hang. – georg Sep 09 '19 at 13:31
  • have your node server spawn a new process, pass it the input, and kill it if it doesn't output after however long. – I wrestled a bear once. Sep 09 '19 at 13:32

0 Answers0