Just to play devil’s advocate, is there a way (and is it useful to) do this change this without porting to re2
? I’m wondering if we can mitigate much of the risk without adding an additional dependency and migrating a reasonably large number of patterns. Might there be a notable performance difference between “re2
+ code” vs “Simplified re
+ code” (assuming the simplified use of re
avoids the ReDoS patterns)?
Also, is there a value in keeping the simpler patterns (ie those we can say with confidence don’t backtrack) using re
, and only porting the more “interesting” patterns to use re2
? That might give a best-of-both-worlds outcome - mitigate ReDoS whilst having some performance benefit. I don’t know how easy it is to determine (statically or otherwise) whether a given pattern backtracks or could have other ReDoS implications.