-
Notifications
You must be signed in to change notification settings - Fork 2k
Python: promote log injection #7735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
20d5454
8b5114d
bf1145e
9d41666
c03f89d
7511b33
26befeb
ecea392
119a7e4
c587084
bec8c0d
448e078
f21ac04
bd14ade
62598c0
3a995ec
62d4bb5
b59ab7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- move from custom concept `LogOutput` to standard concept `Logging`
- remove `Log.qll` from experimental frameworks
- fold models into standard models (naively for now)
- stdlib:
- make Logger module public
- broaden definition of instance
- add `extra` keyword as possible source
- flak: add app.logger as logger instance
- django: `add django.utils.log.request_logger` as logger instance
(should we add the rest?)
- remove LogOutput from experimental concepts- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -237,6 +237,42 @@ module Stdlib { | |
| } | ||
| } | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // logging | ||
| // --------------------------------------------------------------------------- | ||
| /** | ||
| * Provides models for the `logging.Logger` class and subclasses. | ||
| * | ||
| * See https://docs.python.org/3.9/library/logging.html#logging.Logger. | ||
| */ | ||
| module Logger { | ||
| /** | ||
| * An instance of `logging.Logger`. Extend this class to model new instances. | ||
| * Most major frameworks will provide a logger instance as a class attribute. | ||
| */ | ||
| abstract class LoggerInstance extends API::Node { | ||
| override string toString() { result = "logger" } | ||
| } | ||
|
|
||
| /** Gets a reference to the `logging.Logger` class or any subclass. */ | ||
| API::Node subclassRef() { | ||
| result = API::moduleImport("logging").getMember("Logger").getASubclass*() | ||
| } | ||
|
|
||
| /** Gets a reference to an instance of `logging.Logger` or any subclass. */ | ||
| API::Node instance() { | ||
| result instanceof LoggerInstance | ||
| or | ||
| result = subclassRef().getReturn() | ||
| or | ||
| result = API::moduleImport("logging") | ||
| or | ||
| result = API::moduleImport("logging").getMember("root") | ||
| or | ||
| result = API::moduleImport("logging").getMember("getLogger").getReturn() | ||
| } | ||
| } | ||
|
Comment on lines
+249
to
+287
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that I created this non-standard setup with just using Looking over the code again, I don't quite know why I did this in the first place.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Surely it is nicer, if we can get away with using an
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to standard setup as discussed offline. |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -2642,27 +2678,6 @@ private module StdlibPrivate { | |
| // --------------------------------------------------------------------------- | ||
| // logging | ||
| // --------------------------------------------------------------------------- | ||
| /** | ||
| * Provides models for the `logging.Logger` class and subclasses. | ||
| * | ||
| * See https://docs.python.org/3.9/library/logging.html#logging.Logger. | ||
| */ | ||
| module Logger { | ||
| /** Gets a reference to the `logging.Logger` class or any subclass. */ | ||
| API::Node subclassRef() { | ||
| result = API::moduleImport("logging").getMember("Logger").getASubclass*() | ||
| } | ||
|
|
||
| /** Gets a reference to an instance of `logging.Logger` or any subclass. */ | ||
| API::Node instance() { | ||
| result = subclassRef().getReturn() | ||
| or | ||
| result = API::moduleImport("logging").getMember("root") | ||
| or | ||
| result = API::moduleImport("logging").getMember("getLogger").getReturn() | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * A call to one of the logging methods from `logging` or on a `logging.Logger` | ||
| * subclass. | ||
|
|
@@ -2683,14 +2698,12 @@ private module StdlibPrivate { | |
| method = "log" and | ||
| msgIndex = 1 | ||
| | | ||
| this = Logger::instance().getMember(method).getACall() | ||
| or | ||
| this = API::moduleImport("logging").getMember(method).getACall() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't agree about this removal. I see that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there value in modelling instances specifically? Or could we just rename
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverted to previous modelling approach as discussed offline. |
||
| this = Stdlib::Logger::instance().getMember(method).getACall() | ||
| ) | ||
| } | ||
|
|
||
| override DataFlow::Node getAnInput() { | ||
| result = this.getArgByName("msg") | ||
| result = this.getArgByName(["msg", "extra"]) | ||
| or | ||
| result = this.getArg(any(int i | i >= msgIndex)) | ||
| } | ||
|
|
||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Security/CWE-117/LogInjection.ql |
Uh oh!
There was an error while loading. Please reload this page.