|
| 1 | +/** |
| 2 | + * Provides classes modeling security-relevant aspects of the log libraries. |
| 3 | + */ |
| 4 | + |
| 5 | +private import python |
| 6 | +private import semmle.python.dataflow.new.DataFlow |
| 7 | +private import semmle.python.dataflow.new.TaintTracking |
| 8 | +private import semmle.python.dataflow.new.RemoteFlowSources |
| 9 | +private import experimental.semmle.python.Concepts |
| 10 | +private import semmle.python.frameworks.Flask |
| 11 | +private import semmle.python.ApiGraphs |
| 12 | + |
| 13 | +/** |
| 14 | + * Provides models for Python's log-related libraries. |
| 15 | + */ |
| 16 | +private module log { |
| 17 | + /** |
| 18 | + * Log output method list. |
| 19 | + * |
| 20 | + * See https://docs.python.org/3/library/logging.html#logger-objects |
| 21 | + */ |
| 22 | + private class LogOutputMethods extends string { |
| 23 | + LogOutputMethods() { this in ["info", "error", "warn", "warning", "debug", "critical"] } |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * The class used to find the log output method of the `logging` module. |
| 28 | + * |
| 29 | + * See `LogOutputMethods` |
| 30 | + */ |
| 31 | + private class LoggingCall extends DataFlow::CallCfgNode, LogOutput::Range { |
| 32 | + LoggingCall() { |
| 33 | + this = API::moduleImport("logging").getMember(any(LogOutputMethods m)).getACall() |
| 34 | + } |
| 35 | + |
| 36 | + override DataFlow::Node getAnInput() { result = this.getArg(_) } |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * The class used to find log output methods related to the `logging.getLogger` instance. |
| 41 | + * |
| 42 | + * See `LogOutputMethods` |
| 43 | + */ |
| 44 | + private class LoggerCall extends DataFlow::CallCfgNode, LogOutput::Range { |
| 45 | + LoggerCall() { |
| 46 | + this = |
| 47 | + API::moduleImport("logging") |
| 48 | + .getMember("getLogger") |
| 49 | + .getReturn() |
| 50 | + .getMember(any(LogOutputMethods m)) |
| 51 | + .getACall() |
| 52 | + } |
| 53 | + |
| 54 | + override DataFlow::Node getAnInput() { result = this.getArg(_) } |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * The class used to find the relevant log output method of the `flask.Flask.logger` instance (flask application). |
| 59 | + * |
| 60 | + * See `LogOutputMethods` |
| 61 | + */ |
| 62 | + private class FlaskLoggingCall extends DataFlow::CallCfgNode, LogOutput::Range { |
| 63 | + FlaskLoggingCall() { |
| 64 | + this = |
| 65 | + Flask::FlaskApp::instance() |
| 66 | + .getMember("logger") |
| 67 | + .getMember(any(LogOutputMethods m)) |
| 68 | + .getACall() |
| 69 | + } |
| 70 | + |
| 71 | + override DataFlow::Node getAnInput() { result = this.getArg(_) } |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * The class used to find the relevant log output method of the `django.utils.log.request_logger` instance (django application). |
| 76 | + * |
| 77 | + * See `LogOutputMethods` |
| 78 | + */ |
| 79 | + private class DjangoLoggingCall extends DataFlow::CallCfgNode, LogOutput::Range { |
| 80 | + DjangoLoggingCall() { |
| 81 | + this = |
| 82 | + API::moduleImport("django") |
| 83 | + .getMember("utils") |
| 84 | + .getMember("log") |
| 85 | + .getMember("request_logger") |
| 86 | + .getMember(any(LogOutputMethods m)) |
| 87 | + .getACall() |
| 88 | + } |
| 89 | + |
| 90 | + override DataFlow::Node getAnInput() { result = this.getArg(_) } |
| 91 | + } |
| 92 | +} |
0 commit comments