OWASP/owasp-java-encoder

FEature: RegEx encoder

Weltraumschaf opened this issue · 4 comments

Just did a quick look through the code and it looks like there is no encoder for RegEx context.

I'm just facing this issue: I have untrusted user input and must escape all RegEx meta characters to avoid possible crashes.

java.util.regex.Pattern.quote(String)?

System.out.println(Pattern.matches("\\w+", "anything")); // true - matches any word

System.out.println(Pattern.matches(Pattern.quote("\\w+"), "anything")); // false - doesn't match any word
System.out.println(Pattern.matches(Pattern.quote("\\w+"), "\\w+")); // true - matches only "\w+" literally

We politely cannot support this, we really want to focus on XSS defense in web pages. RegEx escaping is out of bounds for us.