From 571be8be3e052737e13c50d1fcc4201891aafe4f Mon Sep 17 00:00:00 2001 From: Rasmus Lerchedahl Petersen Date: Wed, 26 Jun 2024 01:00:38 +0200 Subject: [PATCH] Python: model more loggers --- python/ql/lib/semmle/python/frameworks/Stdlib.qll | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/python/ql/lib/semmle/python/frameworks/Stdlib.qll b/python/ql/lib/semmle/python/frameworks/Stdlib.qll index 74e33429ed05..57bceeda79aa 100644 --- a/python/ql/lib/semmle/python/frameworks/Stdlib.qll +++ b/python/ql/lib/semmle/python/frameworks/Stdlib.qll @@ -254,10 +254,14 @@ module Stdlib { * See https://docs.python.org/3.9/library/logging.html#logging.Logger. */ module Logger { + private import semmle.python.dataflow.new.internal.DataFlowDispatch as DD + /** Gets a reference to the `logging.Logger` class or any subclass. */ API::Node subclassRef() { result = API::moduleImport("logging").getMember("Logger").getASubclass*() or + result = API::moduleImport("logging").getMember("getLoggerClass").getReturn().getASubclass*() + or result = ModelOutput::getATypeNode("logging.Logger~Subclass").getASubclass*() } @@ -277,6 +281,13 @@ module Stdlib { ClassInstantiation() { this = subclassRef().getACall() or + this = + DD::selfTracker(subclassRef() + .getAValueReachableFromSource() + .asExpr() + .(ClassExpr) + .getInnerScope()) + or this = API::moduleImport("logging").getMember("root").asSource() or this = API::moduleImport("logging").getMember("getLogger").getACall()