<div dir="ltr">Hello,<div><br></div><div>RegExp needs to be anchored to something.</div><div>This seemingly innocuous RegExp is vulnerable to ReDOS:</div><div>/a+$/</div><div><br></div><div>To fix it, it needs to be anchored to something:</div><div>/([^a]|^)a+$/</div><div><br></div><div>If one knows that the string is has something else before, it simplifies to:</div><div>/[^a]a+$/</div><div><br></div><div>console.time("redos");</div><div>('a'.repeat(50000) + '\x00a').match(/a+$/);</div><div>console.timeEnd("redos")<br>redos: 2.506s</div><div><br>console.time("no redos");</div><div>('a'.repeat(50000) + '\x00a').match(/[^a]a+$/);</div><div>console.timeEnd("no redos")<br>no redos: 0.639ms</div><div><br></div><div>See you !</div><div>Jérémy</div><div><br><div><br></div></div></div>