Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Is it safe to use external strings for regexes?

by Corion (Patriarch)
on Oct 06, 2021 at 13:37 UTC ( #11137259=note: print w/replies, xml ) Need Help??


in reply to Is it safe to use external strings for regexes?

Depending on how nasty your users are, allowing arbitrary regular expressions is an unwise choice. The following regex is valid but will use up lots of CPU:

"aaaaaaaaaaaaaaaaaaaaaaaaaaaaa" =~ /a*a*a*b/

If you can come up with a whitelist of allowed regexes, that would improve things, or maybe consider running the regex search as a time-limited subprocess.

Replies are listed 'Best First'.
Re^2: Is it safe to use external strings for regexes?
by stevieb (Canon) on Oct 06, 2021 at 13:44 UTC

    Thanks Corion, that's a good point. The regexes will only be added/edited by seasoned programmers, but I do know that many people who think they know regexes really don't.

    I can definitely add in some checks in conjunction with our existing review processes, but I mostly like the idea of time-limited sub processes to handle the actual work (which can alert if something takes too long).

      It was discussed here in Cloudflare blames PCRE for outage and a blog at cloudflare but they found out a couple years ago even "seasoned programmers" can shoot themselves in the foot as well.

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

        even "seasoned programmers" can shoot themselves in the foot as well.

        Yep, been there, done that myself once or twice. It's especially easy to shoot one's self in the foot when carrying a fully loaded automatic with one hand while not having trigger discipline (ie. a complex regex).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11137259]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2022-01-21 08:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (57 votes). Check out past polls.

    Notices?