Page MenuHomePhabricator

Implement ReDoS detection
Closed, ResolvedPublic

Description

Basically, this would mean recognizing preg_* and similar functions as EXEC. What taint type, I don't know. I don't think there's a proper way to sanitize user input in regexps, so probably a new type that cannot be cleared. Low priority because this will likely have a ton of false positives.

Event Timeline

I don't think there's a proper way to sanitize user input in regexps, so probably a new type that cannot be cleared.

From what I know, there are filtering and allow-lists which can be somewhat effective, but naive solutions like that quickly fail to accommodate for the entire regex grammar. Such solutions (and more elaborate ones) have been discussed for a few different projects from time-to-time (e.g. T214378, T176312).

I don't think there's a proper way to sanitize user input in regexps, so probably a new type that cannot be cleared.

Such solutions (and more elaborate ones) have been discussed for a few different projects from time-to-time (e.g. T214378, T176312).

Yeah, I also remember some releated discussions at T187669 and T240884.

From what I know, there are filtering and allow-lists which can be somewhat effective, but naive solutions like that quickly fail to accommodate for the entire regex grammar.

Exactly. I'm not even sure where the regex grammar sits in the Chomsky hierarchy, as it also depends on the regex flavour. At any rate, it's certainly impossible to sanitize a regexp without tokenizing it, but I don't think many people do that...

So, this should have the MISC taint type, which is the same type used for eval, require, and similar constructs for which you usually cannot sanitize the input.

Yeah, I also remember some releated discussions at T187669 and T240884.

In addition to some of the external research mentioned on these tasks, I feel like @Bawolff sent me this other paper on potential static analysis for ReDoS prevention, which I, um, haven't quite digested just yet.

Change 644800 had a related patch set uploaded (by Daimona Eaytoy; owner: Daimona Eaytoy):
[mediawiki/tools/phan/SecurityCheckPlugin@master] Implement ReDoS detection

https://gerrit.wikimedia.org/r/644800

Change 644800 merged by jenkins-bot:
[mediawiki/tools/phan/SecurityCheckPlugin@master] Implement ReDoS detection

https://gerrit.wikimedia.org/r/644800

This might have a lot of false positives (haven't tested on mw-core), but if this is the case, I guess we can just disable it like we do for the SerializeInjection issue.