4 ms·
> if you're allowing users to input arbitrary regex patterns you have a whole lot of other problems. Why? I am legitimately asking, you say that like it is mea
by Someone1234 10y ago
> if you're allowing users to input arbitrary regex patterns you have a whole lot of other problems.
Why? I am legitimately asking, you say that like it is meant to be obvious or common knowledge. But many regular expression engines are self contained entities that can crash but cannot expose information or poison other parts of the program.
A DoS-like attack might be an argument against unfettered user inputed regular expressions. But that off the top of my head is the only BIG risk. Particularly in secure-by-design languages like Java, C#, and Rust.
- Twirrim 10y agoIt would be easy to create a regex that consumes a lot of CPU power. It's very difficult to vet a regex in an automated fashion.
- Someone1234 10y agoThen don't vet it. Just run it as is, and limit how many local resources it can consume (CPU cycles and RAM). Then add on a timeout for good measure, and you are good to go.
- ZoFreX 10y agoAlternatively, where possible, use a regular expression engine that does not have that issue: https://swtch.com/~rsc/regexp/regexp1.html https://swtch.com/~rsc/regexp/regexp1.html
- ZoFreX 10y agoAllowing users to enter regular expressions is definitely something that should only be entered into with caution. It is effectively code in a programming language that will be run, after all. For example, it means their input needs parsing - and parsing is very hard to get right and frequently results in exploitable bugs. There are also potential problems where regexps could take a very long time to execute, which could be a denial of service issue.