|
| 1 | +/** |
| 2 | + * Provides default sources, sinks and sanitizers for detecting |
| 3 | + * "regular expression injection" |
| 4 | + * vulnerabilities, as well as extension points for adding your own. |
| 5 | + */ |
| 6 | + |
| 7 | +private import python |
| 8 | +private import semmle.python.Concepts |
| 9 | +private import semmle.python.dataflow.new.DataFlow |
| 10 | +private import semmle.python.dataflow.new.TaintTracking |
| 11 | +private import semmle.python.dataflow.new.RemoteFlowSources |
| 12 | + |
| 13 | +/** |
| 14 | + * Provides default sources, sinks and sanitizers for detecting |
| 15 | + * "regular expression injection" |
| 16 | + * vulnerabilities, as well as extension points for adding your own. |
| 17 | + */ |
| 18 | +module RegexInjection { |
| 19 | + /** |
| 20 | + * A data flow source for "regular expression injection" vulnerabilities. |
| 21 | + */ |
| 22 | + abstract class Source extends DataFlow::Node { } |
| 23 | + |
| 24 | + /** |
| 25 | + * A sink for "regular expression injection" vulnerabilities is the execution of a regular expression. |
| 26 | + * If you have a custom way to execute regular expressions, you can extend `RegexExecution::Range`. |
| 27 | + */ |
| 28 | + class Sink extends RegexExecution { } |
| 29 | + |
| 30 | + /** |
| 31 | + * A sanitizer for "regular expression injection" vulnerabilities. |
| 32 | + */ |
| 33 | + abstract class Sanitizer extends DataFlow::Node { } |
| 34 | + |
| 35 | + /** |
| 36 | + * A sanitizer guard for "regular expression injection" vulnerabilities. |
| 37 | + */ |
| 38 | + abstract class SanitizerGuard extends DataFlow::BarrierGuard { } |
| 39 | + |
| 40 | + /** |
| 41 | + * A source of remote user input, considered as a flow source. |
| 42 | + */ |
| 43 | + class RemoteFlowSourceAsSource extends Source, RemoteFlowSource { } |
| 44 | + |
| 45 | + /** |
| 46 | + * A regex escaping, considered as a sanitizer. |
| 47 | + */ |
| 48 | + class RegexEscapingAsSanitizer extends Sanitizer { |
| 49 | + RegexEscapingAsSanitizer() { |
| 50 | + // Due to use-use flow, we want the output rather than an input |
| 51 | + // (so the input can still flow to other sinks). |
| 52 | + this = any(RegexEscaping esc).getOutput() |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments