@@ -16,69 +16,53 @@ private import experimental.semmle.python.Frameworks
16
16
17
17
module XML {
18
18
/**
19
- * A data-flow node that collects functions parsing XML.
19
+ * A kind of XML vulnerability .
20
20
*
21
- * Extend this class to model new APIs. If you want to refine existing API models,
22
- * extend `XMLParsing` instead.
21
+ * See https://pypi.org/project/defusedxml/#python-xml-libraries
23
22
*/
24
- class XMLParsing extends DataFlow:: Node instanceof XMLParsing:: Range {
25
- /**
26
- * Gets the argument containing the content to parse.
27
- */
28
- DataFlow:: Node getAnInput ( ) { result = super .getAnInput ( ) }
23
+ class XMLVulnerabilityKind extends string {
24
+ XMLVulnerabilityKind ( ) {
25
+ this in [ "Billion Laughs" , "Quadratic Blowup" , "XXE" , "DTD retrieval" ]
26
+ }
29
27
30
- /**
31
- * Holds if the parsing method or the parser holding it is vulnerable to `kind`.
32
- */
33
- predicate vulnerable ( string kind ) { super .vulnerable ( kind ) }
34
- }
28
+ /** Holds for Billion Laughs vulnerability kind. */
29
+ predicate isBillionLaughs ( ) { this = "Billion Laughs" }
35
30
36
- /** Provides classes for modeling XML parsing APIs. */
37
- module XMLParsing {
38
- /**
39
- * A data-flow node that collects functions parsing XML.
40
- *
41
- * Extend this class to model new APIs. If you want to refine existing API models,
42
- * extend `XMLParsing` instead.
43
- */
44
- abstract class Range extends DataFlow:: Node {
45
- /**
46
- * Gets the argument containing the content to parse.
47
- */
48
- abstract DataFlow:: Node getAnInput ( ) ;
31
+ /** Holds for Quadratic Blowup vulnerability kind. */
32
+ predicate isQuadraticBlowup ( ) { this = "Quadratic Blowup" }
49
33
50
- /**
51
- * Holds if the parsing method or the parser holding it is vulnerable to `kind`.
52
- */
53
- abstract predicate vulnerable ( string kind ) ;
54
- }
34
+ /** Holds for XXE vulnerability kind. */
35
+ predicate isXxe ( ) { this = "XXE" }
36
+
37
+ /** Holds for DTD retrieval vulnerability kind. */
38
+ predicate isDtdRetrieval ( ) { this = "DTD retrieval" }
55
39
}
56
40
57
41
/**
58
- * A data-flow node that collects XML parsers .
42
+ * A data-flow node that parses XML.
59
43
*
60
44
* Extend this class to model new APIs. If you want to refine existing API models,
61
- * extend `XMLParser ` instead.
45
+ * extend `XMLParsing ` instead.
62
46
*/
63
- class XMLParser extends DataFlow:: Node instanceof XMLParser :: Range {
47
+ class XMLParsing extends DataFlow:: Node instanceof XMLParsing :: Range {
64
48
/**
65
49
* Gets the argument containing the content to parse.
66
50
*/
67
51
DataFlow:: Node getAnInput ( ) { result = super .getAnInput ( ) }
68
52
69
53
/**
70
- * Holds if the parser is vulnerable to `kind`.
54
+ * Holds if this XML parsing is vulnerable to `kind`.
71
55
*/
72
- predicate vulnerable ( string kind ) { super .vulnerable ( kind ) }
56
+ predicate vulnerableTo ( XMLVulnerabilityKind kind ) { super .vulnerableTo ( kind ) }
73
57
}
74
58
75
- /** Provides classes for modeling XML parsers . */
76
- module XMLParser {
59
+ /** Provides classes for modeling XML parsing APIs . */
60
+ module XMLParsing {
77
61
/**
78
- * A data-flow node that collects XML parsers .
62
+ * A data-flow node that parses XML.
79
63
*
80
64
* Extend this class to model new APIs. If you want to refine existing API models,
81
- * extend `XMLParser ` instead.
65
+ * extend `XMLParsing ` instead.
82
66
*/
83
67
abstract class Range extends DataFlow:: Node {
84
68
/**
@@ -87,9 +71,9 @@ module XML {
87
71
abstract DataFlow:: Node getAnInput ( ) ;
88
72
89
73
/**
90
- * Holds if the parser is vulnerable to `kind`.
74
+ * Holds if this XML parsing is vulnerable to `kind`.
91
75
*/
92
- abstract predicate vulnerable ( string kind ) ;
76
+ abstract predicate vulnerableTo ( XMLVulnerabilityKind kind ) ;
93
77
}
94
78
}
95
79
}
0 commit comments