mirror of
https://github.com/github/codeql.git
synced 2026-04-26 09:15:12 +02:00
Python: Model file threat-model
This commit is contained in:
@@ -17,6 +17,8 @@ extensions:
|
||||
|
||||
# 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
|
||||
|
||||
@@ -1499,13 +1499,17 @@ 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() }
|
||||
|
||||
override DataFlow::Node getAPathArgument() {
|
||||
result in [this.getArg(0), this.getArgByName("file")]
|
||||
}
|
||||
|
||||
override string getThreatModel() { result = "file" }
|
||||
|
||||
override string getSourceType() { result = "open()" }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,25 +5,25 @@ import stat
|
||||
import tempfile
|
||||
import shutil
|
||||
|
||||
open("file") # $ getAPathArgument="file"
|
||||
open(file="file") # $ getAPathArgument="file"
|
||||
open("file") # $ getAPathArgument="file" threatModelSource[file]=open(..)
|
||||
open(file="file") # $ getAPathArgument="file" threatModelSource[file]=open(..)
|
||||
|
||||
o = open
|
||||
|
||||
o("file") # $ getAPathArgument="file"
|
||||
o(file="file") # $ getAPathArgument="file"
|
||||
o("file") # $ getAPathArgument="file" threatModelSource[file]=o(..)
|
||||
o(file="file") # $ getAPathArgument="file" threatModelSource[file]=o(..)
|
||||
|
||||
|
||||
builtins.open("file") # $ getAPathArgument="file"
|
||||
builtins.open(file="file") # $ getAPathArgument="file"
|
||||
builtins.open("file") # $ getAPathArgument="file" threatModelSource[file]=builtins.open(..)
|
||||
builtins.open(file="file") # $ getAPathArgument="file" threatModelSource[file]=builtins.open(..)
|
||||
|
||||
|
||||
io.open("file") # $ getAPathArgument="file"
|
||||
io.open(file="file") # $ getAPathArgument="file"
|
||||
io.open("file") # $ getAPathArgument="file" threatModelSource[file]=io.open(..)
|
||||
io.open(file="file") # $ getAPathArgument="file" threatModelSource[file]=io.open(..)
|
||||
io.open_code("file") # $ getAPathArgument="file"
|
||||
io.FileIO("file") # $ getAPathArgument="file"
|
||||
|
||||
f = open("path") # $ getAPathArgument="path"
|
||||
f = open("path") # $ getAPathArgument="path" threatModelSource[file]=open(..)
|
||||
f.write("foo") # $ getAPathArgument="path" fileWriteData="foo"
|
||||
lines = ["foo"]
|
||||
f.writelines(lines) # $ getAPathArgument="path" fileWriteData=lines
|
||||
@@ -87,8 +87,8 @@ def test_fspath():
|
||||
os.fspath(path=TAINTED_STRING), # $ tainted
|
||||
)
|
||||
|
||||
os.open("path", os.O_RDONLY) # $ getAPathArgument="path"
|
||||
os.open(path="path", flags=os.O_RDONLY) # $ getAPathArgument="path"
|
||||
os.open("path", os.O_RDONLY) # $ getAPathArgument="path" SPURIOUS: threatModelSource[file]=os.open(..)
|
||||
os.open(path="path", flags=os.O_RDONLY) # $ getAPathArgument="path" SPURIOUS: threatModelSource[file]=os.open(..)
|
||||
|
||||
os.access("path", os.R_OK) # $ getAPathArgument="path"
|
||||
os.access(path="path", mode=os.R_OK) # $ getAPathArgument="path"
|
||||
|
||||
@@ -48,6 +48,19 @@ ensure_tainted(
|
||||
input(), # $ tainted threatModelSource[stdin]=input()
|
||||
)
|
||||
|
||||
########################################
|
||||
# reading data from files
|
||||
########################################
|
||||
|
||||
ensure_tainted(
|
||||
open("foo"), # $ tainted threatModelSource[file]=open(..) getAPathArgument="foo"
|
||||
open("foo").read(), # $ tainted threatModelSource[file]=open(..) getAPathArgument="foo"
|
||||
open("foo").readline(), # $ tainted threatModelSource[file]=open(..) getAPathArgument="foo"
|
||||
open("foo").readlines(), # $ tainted threatModelSource[file]=open(..) getAPathArgument="foo"
|
||||
|
||||
os.read(os.open("foo"), 1024), # $ tainted threatModelSource[file]=os.read(..) SPURIOUS: threatModelSource[file]=os.open(..) getAPathArgument="foo"
|
||||
)
|
||||
|
||||
########################################
|
||||
# socket
|
||||
########################################
|
||||
|
||||
Reference in New Issue
Block a user