|
| 1 | +/** |
| 2 | + * Provides classes modeling security-relevant aspects of the `simplejson` PyPI package. |
| 3 | + * See https://simplejson.readthedocs.io/en/latest/. |
| 4 | + */ |
| 5 | + |
| 6 | +private import python |
| 7 | +private import semmle.python.dataflow.new.DataFlow |
| 8 | +private import semmle.python.dataflow.new.TaintTracking |
| 9 | +private import semmle.python.Concepts |
| 10 | +private import semmle.python.ApiGraphs |
| 11 | + |
| 12 | +/** |
| 13 | + * Provides models for the `simplejson` PyPI package. |
| 14 | + * See https://simplejson.readthedocs.io/en/latest/. |
| 15 | + */ |
| 16 | +private module SimplejsonModel { |
| 17 | + /** |
| 18 | + * A call to `simplejson.dumps`. |
| 19 | + * |
| 20 | + * See https://simplejson.readthedocs.io/en/latest/#simplejson.dumps |
| 21 | + */ |
| 22 | + private class SimplejsonDumpsCall extends Encoding::Range, DataFlow::CallCfgNode { |
| 23 | + SimplejsonDumpsCall() { this = API::moduleImport("simplejson").getMember("dumps").getACall() } |
| 24 | + |
| 25 | + override DataFlow::Node getAnInput() { result in [this.getArg(0), this.getArgByName("obj")] } |
| 26 | + |
| 27 | + override DataFlow::Node getOutput() { result = this } |
| 28 | + |
| 29 | + override string getFormat() { result = "JSON" } |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * A call to `simplejson.dump`. |
| 34 | + * |
| 35 | + * See https://simplejson.readthedocs.io/en/latest/#simplejson.dump |
| 36 | + */ |
| 37 | + private class SimplejsonDumpCall extends Encoding::Range, DataFlow::CallCfgNode { |
| 38 | + SimplejsonDumpCall() { this = API::moduleImport("simplejson").getMember("dump").getACall() } |
| 39 | + |
| 40 | + override DataFlow::Node getAnInput() { result in [this.getArg(0), this.getArgByName("obj")] } |
| 41 | + |
| 42 | + override DataFlow::Node getOutput() { |
| 43 | + result.(DataFlow::PostUpdateNode).getPreUpdateNode() in [ |
| 44 | + this.getArg(1), this.getArgByName("fp") |
| 45 | + ] |
| 46 | + } |
| 47 | + |
| 48 | + override string getFormat() { result = "JSON" } |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * A call to `simplejson.loads`. |
| 53 | + * |
| 54 | + * See https://simplejson.readthedocs.io/en/latest/#simplejson.loads |
| 55 | + */ |
| 56 | + private class SimplejsonLoadsCall extends Decoding::Range, DataFlow::CallCfgNode { |
| 57 | + SimplejsonLoadsCall() { this = API::moduleImport("simplejson").getMember("loads").getACall() } |
| 58 | + |
| 59 | + override DataFlow::Node getAnInput() { result in [this.getArg(0), this.getArgByName("s")] } |
| 60 | + |
| 61 | + override DataFlow::Node getOutput() { result = this } |
| 62 | + |
| 63 | + override string getFormat() { result = "JSON" } |
| 64 | + |
| 65 | + override predicate mayExecuteInput() { none() } |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * A call to `simplejson.load`. |
| 70 | + * |
| 71 | + * See https://simplejson.readthedocs.io/en/latest/#simplejson.load |
| 72 | + */ |
| 73 | + private class SimplejsonLoadCall extends Decoding::Range, DataFlow::CallCfgNode { |
| 74 | + SimplejsonLoadCall() { this = API::moduleImport("simplejson").getMember("load").getACall() } |
| 75 | + |
| 76 | + override DataFlow::Node getAnInput() { result in [this.getArg(0), this.getArgByName("fp")] } |
| 77 | + |
| 78 | + override DataFlow::Node getOutput() { result = this } |
| 79 | + |
| 80 | + override string getFormat() { result = "JSON" } |
| 81 | + |
| 82 | + override predicate mayExecuteInput() { none() } |
| 83 | + } |
| 84 | +} |
0 commit comments