mirror of
https://github.com/github/codeql.git
synced 2026-04-06 07:34:00 +02:00
Merge branch 'main' into stdlib-optparse
This commit is contained in:
@@ -81,6 +81,24 @@ module PEP249 {
|
||||
}
|
||||
}
|
||||
|
||||
/** A call to a method that fetches rows from a previous execution. */
|
||||
private class FetchMethodCall extends ThreatModelSource::Range, API::CallNode {
|
||||
FetchMethodCall() {
|
||||
exists(API::Node start |
|
||||
start instanceof DatabaseCursor or start instanceof DatabaseConnection
|
||||
|
|
||||
// note: since we can't currently provide accesspaths for sources, these are all
|
||||
// lumped together, although clearly the fetchmany/fetchall returns a
|
||||
// list/iterable with rows.
|
||||
this = start.getMember(["fetchone", "fetchmany", "fetchall"]).getACall()
|
||||
)
|
||||
}
|
||||
|
||||
override string getThreatModel() { result = "database" }
|
||||
|
||||
override string getSourceType() { result = "cursor.fetch*()" }
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// asyncio implementations
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
29
python/ql/lib/semmle/python/frameworks/Stdlib.model.yml
Normal file
29
python/ql/lib/semmle/python/frameworks/Stdlib.model.yml
Normal file
@@ -0,0 +1,29 @@
|
||||
extensions:
|
||||
- addsTo:
|
||||
pack: codeql/python-all
|
||||
extensible: sourceModel
|
||||
data:
|
||||
- ['os', 'Member[getenv].ReturnValue', 'environment']
|
||||
- ['os', 'Member[getenvb].ReturnValue', 'environment']
|
||||
- ['os', 'Member[environ]', 'environment']
|
||||
- ['os', 'Member[environb]', 'environment']
|
||||
- ['posix', 'Member[environ]', 'environment']
|
||||
|
||||
- ['sys', 'Member[argv]', 'commandargs']
|
||||
- ['sys', 'Member[orig_argv]', 'commandargs']
|
||||
|
||||
- ['sys', 'Member[stdin]', 'stdin']
|
||||
- ['builtins', 'Member[input].ReturnValue', 'stdin']
|
||||
- ['builtins', 'Member[raw_input].ReturnValue', 'stdin'] # python 2 only
|
||||
|
||||
|
||||
# if no argument is given, the default is to use sys.argv[1:]
|
||||
- ['argparse.ArgumentParser', 'Member[parse_args,parse_known_args].WithArity[0].ReturnValue', 'commandargs']
|
||||
|
||||
- ['os', 'Member[read].ReturnValue', 'file']
|
||||
- addsTo:
|
||||
pack: codeql/python-all
|
||||
extensible: summaryModel
|
||||
data:
|
||||
- ['argparse.ArgumentParser', 'Member[parse_args,parse_known_args]', 'Argument[0,args:]', 'ReturnValue', 'taint']
|
||||
# note: taint of attribute lookups is handled in QL
|
||||
@@ -349,7 +349,7 @@ module StdlibPrivate {
|
||||
* Modeling of path related functions in the `os` module.
|
||||
* Wrapped in QL module to make it easy to fold/unfold.
|
||||
*/
|
||||
private module OsFileSystemAccessModeling {
|
||||
module OsFileSystemAccessModeling {
|
||||
/**
|
||||
* A call to the `os.fsencode` function.
|
||||
*
|
||||
@@ -406,7 +406,7 @@ module StdlibPrivate {
|
||||
*
|
||||
* See https://docs.python.org/3/library/os.html#os.open
|
||||
*/
|
||||
private class OsOpenCall extends FileSystemAccess::Range, DataFlow::CallCfgNode {
|
||||
class OsOpenCall extends FileSystemAccess::Range, DataFlow::CallCfgNode {
|
||||
OsOpenCall() { this = os().getMember("open").getACall() }
|
||||
|
||||
override DataFlow::Node getAPathArgument() {
|
||||
@@ -1513,13 +1513,22 @@ module StdlibPrivate {
|
||||
* See https://docs.python.org/3/library/functions.html#open
|
||||
*/
|
||||
private class OpenCall extends FileSystemAccess::Range, Stdlib::FileLikeObject::InstanceSource,
|
||||
DataFlow::CallCfgNode
|
||||
ThreatModelSource::Range, DataFlow::CallCfgNode
|
||||
{
|
||||
OpenCall() { this = getOpenFunctionRef().getACall() }
|
||||
OpenCall() {
|
||||
this = getOpenFunctionRef().getACall() and
|
||||
// when analyzing stdlib code for os.py we wrongly assume that `os.open` is an
|
||||
// alias of the builtins `open` function
|
||||
not this instanceof OsFileSystemAccessModeling::OsOpenCall
|
||||
}
|
||||
|
||||
override DataFlow::Node getAPathArgument() {
|
||||
result in [this.getArg(0), this.getArgByName("file")]
|
||||
}
|
||||
|
||||
override string getThreatModel() { result = "file" }
|
||||
|
||||
override string getSourceType() { result = "open()" }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -5008,6 +5017,39 @@ module StdlibPrivate {
|
||||
|
||||
override string getKind() { result = Escaping::getHtmlKind() }
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// argparse
|
||||
// ---------------------------------------------------------------------------
|
||||
/**
|
||||
* if result of `parse_args` is tainted (because it uses command-line arguments),
|
||||
* then the parsed values accesssed on any attribute lookup is also tainted.
|
||||
*/
|
||||
private class ArgumentParserAnyAttributeStep extends TaintTracking::AdditionalTaintStep {
|
||||
override predicate step(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
|
||||
nodeFrom =
|
||||
API::moduleImport("argparse")
|
||||
.getMember("ArgumentParser")
|
||||
.getReturn()
|
||||
.getMember("parse_args")
|
||||
.getReturn()
|
||||
.getAValueReachableFromSource() and
|
||||
nodeTo.(DataFlow::AttrRead).getObject() = nodeFrom
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// sys
|
||||
// ---------------------------------------------------------------------------
|
||||
/**
|
||||
* An access of `sys.stdin`/`sys.stdout`/`sys.stderr`, to get additional FileLike
|
||||
* modeling.
|
||||
*/
|
||||
private class SysStandardStreams extends Stdlib::FileLikeObject::InstanceSource, DataFlow::Node {
|
||||
SysStandardStreams() {
|
||||
this = API::moduleImport("sys").getMember(["stdin", "stdout", "stderr"]).asSource()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -18,14 +18,19 @@ private import semmle.python.dataflow.new.RemoteFlowSources
|
||||
private import semmle.python.dataflow.new.DataFlow
|
||||
private import semmle.python.ApiGraphs
|
||||
private import semmle.python.dataflow.new.FlowSummary
|
||||
private import semmle.python.Concepts
|
||||
|
||||
/**
|
||||
* A remote flow source originating from a CSV source row.
|
||||
* A threat-model flow source originating from a data extension.
|
||||
*/
|
||||
private class RemoteFlowSourceFromCsv extends RemoteFlowSource::Range {
|
||||
RemoteFlowSourceFromCsv() { this = ModelOutput::getASourceNode("remote").asSource() }
|
||||
private class ThreatModelSourceFromDataExtension extends ThreatModelSource::Range {
|
||||
ThreatModelSourceFromDataExtension() { this = ModelOutput::getASourceNode(_).asSource() }
|
||||
|
||||
override string getSourceType() { result = "Remote flow (from model)" }
|
||||
override string getThreatModel() { this = ModelOutput::getASourceNode(result).asSource() }
|
||||
|
||||
override string getSourceType() {
|
||||
result = "Source node (" + this.getThreatModel() + ") [from data-extension]"
|
||||
}
|
||||
}
|
||||
|
||||
private class SummarizedCallableFromModel extends SummarizedCallable {
|
||||
|
||||
Reference in New Issue
Block a user