@@ -21,49 +21,49 @@ private import semmle.python.ApiGraphs
2121 * - https://pyyaml.org/wiki/PyYAMLDocumentation
2222 * - https://pyyaml.docsforge.com/master/documentation/
2323 */
24- private module Yaml { }
25-
26- /**
27- * A call to any of the loading functions in `yaml` (`load`, `load_all`, `full_load`,
28- * `full_load_all`, `unsafe_load`, `unsafe_load_all`, `safe_load`, `safe_load_all`)
29- *
30- * See https://pyyaml.org/wiki/PyYAMLDocumentation (you will have to scroll down).
31- */
32- private class YamlLoadCall extends Decoding:: Range , DataFlow:: CallCfgNode {
33- override CallNode node ;
34- string func_name ;
35-
36- YamlLoadCall ( ) {
37- func_name in [
38- "load" , "load_all" , "full_load" , "full_load_all" , "unsafe_load" , "unsafe_load_all" ,
39- "safe_load" , "safe_load_all"
40- ] and
41- this = API:: moduleImport ( "yaml" ) .getMember ( func_name ) .getACall ( )
42- }
43-
24+ private module Yaml {
4425 /**
45- * This function was thought safe from the 5.1 release in 2017, when the default loader was changed to `FullLoader`.
46- * In 2020 new exploits were found, meaning it's not safe. The Current plan is to change the default to `SafeLoader` in release 6.0
47- * (as explained in https://github.com/yaml/pyyaml/issues/420#issuecomment-696752389).
48- * Until 6.0 is released, we will mark `yaml.load` as possibly leading to arbitrary code execution.
49- * See https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input)-Deprecation for more details.
26+ * A call to any of the loading functions in `yaml` (`load`, `load_all`, `full_load`,
27+ * `full_load_all`, `unsafe_load`, `unsafe_load_all`, `safe_load`, `safe_load_all`)
28+ *
29+ * See https://pyyaml.org/wiki/PyYAMLDocumentation (you will have to scroll down).
5030 */
51- override predicate mayExecuteInput ( ) {
52- func_name in [ "full_load" , "full_load_all" , "unsafe_load" , "unsafe_load_all" ]
53- or
54- func_name in [ "load" , "load_all" ] and
55- // If the `Loader` is not set to either `SafeLoader` or `BaseLoader` or not set at all,
56- // then the default loader will be used, which is not safe.
57- not exists ( DataFlow:: Node loader_arg |
58- loader_arg in [ this .getArg ( 1 ) , this .getArgByName ( "Loader" ) ]
59- |
60- loader_arg = API:: moduleImport ( "yaml" ) .getMember ( [ "SafeLoader" , "BaseLoader" ] ) .getAUse ( )
61- )
62- }
31+ private class YamlLoadCall extends Decoding:: Range , DataFlow:: CallCfgNode {
32+ override CallNode node ;
33+ string func_name ;
34+
35+ YamlLoadCall ( ) {
36+ func_name in [
37+ "load" , "load_all" , "full_load" , "full_load_all" , "unsafe_load" , "unsafe_load_all" ,
38+ "safe_load" , "safe_load_all"
39+ ] and
40+ this = API:: moduleImport ( "yaml" ) .getMember ( func_name ) .getACall ( )
41+ }
6342
64- override DataFlow:: Node getAnInput ( ) { result = this .getArg ( 0 ) }
43+ /**
44+ * This function was thought safe from the 5.1 release in 2017, when the default loader was changed to `FullLoader`.
45+ * In 2020 new exploits were found, meaning it's not safe. The Current plan is to change the default to `SafeLoader` in release 6.0
46+ * (as explained in https://github.com/yaml/pyyaml/issues/420#issuecomment-696752389).
47+ * Until 6.0 is released, we will mark `yaml.load` as possibly leading to arbitrary code execution.
48+ * See https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input)-Deprecation for more details.
49+ */
50+ override predicate mayExecuteInput ( ) {
51+ func_name in [ "full_load" , "full_load_all" , "unsafe_load" , "unsafe_load_all" ]
52+ or
53+ func_name in [ "load" , "load_all" ] and
54+ // If the `Loader` is not set to either `SafeLoader` or `BaseLoader` or not set at all,
55+ // then the default loader will be used, which is not safe.
56+ not exists ( DataFlow:: Node loader_arg |
57+ loader_arg in [ this .getArg ( 1 ) , this .getArgByName ( "Loader" ) ]
58+ |
59+ loader_arg = API:: moduleImport ( "yaml" ) .getMember ( [ "SafeLoader" , "BaseLoader" ] ) .getAUse ( )
60+ )
61+ }
6562
66- override DataFlow:: Node getOutput ( ) { result = this }
63+ override DataFlow:: Node getAnInput ( ) { result = this . getArg ( 0 ) }
6764
68- override string getFormat ( ) { result = "YAML" }
65+ override DataFlow:: Node getOutput ( ) { result = this }
66+
67+ override string getFormat ( ) { result = "YAML" }
68+ }
6969}
0 commit comments