Skip to content

Commit 42b2c3e

Browse files
committed
Python: Model C-based loaders for PyYAML
Not really that important. But easy to do while I was working on this library.
1 parent 54e6f51 commit 42b2c3e

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lgtm,codescanning
2+
* Improved modeling of the `PyYAML` PyPI package, so we now correctly treat `CSafeLoader` and `CBaseLoader` as being safe loaders that can not lead to code execution.

python/ql/src/semmle/python/frameworks/Yaml.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ private module Yaml {
5656
not exists(DataFlow::Node loader_arg |
5757
loader_arg in [this.getArg(1), this.getArgByName("Loader")]
5858
|
59-
loader_arg = API::moduleImport("yaml").getMember(["SafeLoader", "BaseLoader"]).getAUse()
59+
loader_arg =
60+
API::moduleImport("yaml")
61+
.getMember(["SafeLoader", "BaseLoader", "CSafeLoader", "CBaseLoader"])
62+
.getAUse()
6063
)
6164
}
6265

python/ql/test/experimental/library-tests/frameworks/yaml/Decoding.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
# C-based loaders with `libyaml`
2222
yaml.load(payload, yaml.CLoader) # $ decodeInput=payload decodeOutput=Attribute() decodeFormat=YAML decodeMayExecuteInput
2323
yaml.load(payload, yaml.CFullLoader) # $ decodeInput=payload decodeOutput=Attribute() decodeFormat=YAML decodeMayExecuteInput
24-
yaml.load(payload, yaml.CSafeLoader) # $decodeInput=payload decodeOutput=Attribute() decodeFormat=YAML SPURIOUS: decodeMayExecuteInput
25-
yaml.load(payload, yaml.CBaseLoader) # $decodeInput=payload decodeOutput=Attribute() decodeFormat=YAML SPURIOUS: decodeMayExecuteInput
24+
yaml.load(payload, yaml.CSafeLoader) # $decodeInput=payload decodeOutput=Attribute() decodeFormat=YAML
25+
yaml.load(payload, yaml.CBaseLoader) # $decodeInput=payload decodeOutput=Attribute() decodeFormat=YAML

0 commit comments

Comments
 (0)