|
| 1 | +/** |
| 2 | + * Provides default sources, sinks and sanitizers for detecting |
| 3 | + * "command injection" |
| 4 | + * vulnerabilities, as well as extension points for adding your own. |
| 5 | + */ |
| 6 | + |
| 7 | +private import python |
| 8 | +private import semmle.python.dataflow.new.DataFlow |
| 9 | +private import semmle.python.Concepts |
| 10 | +private import semmle.python.dataflow.new.RemoteFlowSources |
| 11 | +private import semmle.python.dataflow.new.BarrierGuards |
| 12 | + |
| 13 | +/** |
| 14 | + * Provides default sources, sinks and sanitizers for detecting |
| 15 | + * "command injection" |
| 16 | + * vulnerabilities, as well as extension points for adding your own. |
| 17 | + */ |
| 18 | +module LogInjection { |
| 19 | + /** |
| 20 | + * A data flow source for "command injection" vulnerabilities. |
| 21 | + */ |
| 22 | + abstract class Source extends DataFlow::Node { } |
| 23 | + |
| 24 | + /** |
| 25 | + * A data flow sink for "command injection" vulnerabilities. |
| 26 | + */ |
| 27 | + abstract class Sink extends DataFlow::Node { } |
| 28 | + |
| 29 | + /** |
| 30 | + * A sanitizer for "command injection" vulnerabilities. |
| 31 | + */ |
| 32 | + abstract class Sanitizer extends DataFlow::Node { } |
| 33 | + |
| 34 | + /** |
| 35 | + * A sanitizer guard for "command injection" vulnerabilities. |
| 36 | + */ |
| 37 | + abstract class SanitizerGuard extends DataFlow::BarrierGuard { } |
| 38 | + |
| 39 | + /** |
| 40 | + * A source of remote user input, considered as a flow source. |
| 41 | + */ |
| 42 | + class RemoteFlowSourceAsSource extends Source, RemoteFlowSource { } |
| 43 | + |
| 44 | + /** |
| 45 | + * A logging operation, considered as a flow sink. |
| 46 | + */ |
| 47 | + class LoggingAsSink extends Sink { |
| 48 | + LoggingAsSink() { this = any(Logging write).getAnInput() } |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * A comparison with a constant string, considered as a sanitizer-guard. |
| 53 | + */ |
| 54 | + class StringConstCompareAsSanitizerGuard extends SanitizerGuard, StringConstCompare { } |
| 55 | + |
| 56 | + /** |
| 57 | + * A call to replace line breaks functions as a sanitizer. |
| 58 | + */ |
| 59 | + class ReplaceLineBreaksSanitizer extends Sanitizer, DataFlow::CallCfgNode { |
| 60 | + ReplaceLineBreaksSanitizer() { |
| 61 | + this.getFunction().(DataFlow::AttrRead).getAttributeName() = "replace" and |
| 62 | + this.getArg(0).asExpr().(StrConst).getText() in ["\r\n", "\n"] |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments