|
| 1 | +/** |
| 2 | + * Provides classes modeling security-relevant aspects of the `opml` PyPI package. |
| 3 | + * |
| 4 | + * See |
| 5 | + * - https://pypi.org/project/opml/ |
| 6 | + */ |
| 7 | + |
| 8 | +private import python |
| 9 | +private import semmle.python.dataflow.new.DataFlow |
| 10 | +private import semmle.python.Concepts |
| 11 | +private import semmle.python.ApiGraphs |
| 12 | + |
| 13 | +/** |
| 14 | + * Provides classes modeling security-relevant aspects of the `opml` PyPI package |
| 15 | + * |
| 16 | + * See |
| 17 | + * - https://pypi.org/project/opml/ |
| 18 | + */ |
| 19 | +private module Opml { |
| 20 | + /** |
| 21 | + * A call to the `xpath` method of a parsed document. |
| 22 | + * |
| 23 | + * import opml |
| 24 | + * root = opml.from_string(file(XML_DB).read()) |
| 25 | + * find_text = root.xpath("`sink`") |
| 26 | + */ |
| 27 | + private class XPathCall extends XML::XPathExecution::Range, DataFlow::CallCfgNode { |
| 28 | + XPathCall() { |
| 29 | + exists(API::Node parseResult | |
| 30 | + parseResult = API::moduleImport("opml").getMember(["parse", "from_string"]).getReturn() |
| 31 | + | |
| 32 | + this = parseResult.getMember("xpath").getACall() |
| 33 | + ) |
| 34 | + } |
| 35 | + |
| 36 | + override DataFlow::Node getXPath() { result = this.getArg(0) } |
| 37 | + |
| 38 | + override string getName() { result = "opml" } |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * A call to either of: |
| 43 | + * - `opml.parse` |
| 44 | + * - `opml.from_string` |
| 45 | + */ |
| 46 | + private class OpmlParsing extends DataFlow::CallCfgNode, XML::XmlParsing::Range { |
| 47 | + OpmlParsing() { |
| 48 | + this = API::moduleImport("opml").getMember(["parse", "from_string"]).getACall() |
| 49 | + } |
| 50 | + |
| 51 | + override DataFlow::Node getAnInput() { result = this.getArg(0) } |
| 52 | + |
| 53 | + DataFlow::Node getParserArg() { none() } |
| 54 | + |
| 55 | + /** |
| 56 | + * The same as `Lxml::LxmlParsing::vulnerableTo`, because `opml` uses `lxml` for parsing. |
| 57 | + */ |
| 58 | + override predicate vulnerableTo(XML::XmlParsingVulnerabilityKind kind) { kind.isXxe() } |
| 59 | + |
| 60 | + override predicate mayExecuteInput() { none() } |
| 61 | + |
| 62 | + override DataFlow::Node getOutput() { result = this } |
| 63 | + } |
| 64 | +} |
0 commit comments