-
Notifications
You must be signed in to change notification settings - Fork 2k
Python: Add modeling of simplejson/ujson/idna #5864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7ed20a8
Python: Add reminder to update docs for new frameworks
RasmusWL 8afdf26
Python: Add modeling of idna PyPI package
RasmusWL 3fe9a3d
Python: Add modeling of simplejson PyPI package
RasmusWL 784e0cd
Python: Improve tests of `json` module
RasmusWL 63f28d7
Python: Model keyword args to json loads/dumps
RasmusWL 72d08f4
Python: Model json load/dump
RasmusWL c2a6b81
Python: Add modeling of ujson PyPI package
RasmusWL 1b0d505
Python: simplejson load/dump only works with lib installed
RasmusWL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| lgtm,codescanning | ||
| * Added modeling of the PyPI package `idna`, for encoding/decoding Internationalised Domain Names in Applications. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| lgtm,codescanning | ||
| * Added modeling of the PyPI package `simplejson`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| lgtm,codescanning | ||
| * Added modeling of the PyPI package `ujson`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /** | ||
| * Provides classes modeling security-relevant aspects of the `idna` PyPI package. | ||
| * See https://pypi.org/project/idna/. | ||
| */ | ||
|
|
||
| private import python | ||
| private import semmle.python.dataflow.new.DataFlow | ||
| private import semmle.python.dataflow.new.TaintTracking | ||
| private import semmle.python.Concepts | ||
| private import semmle.python.ApiGraphs | ||
|
|
||
| /** | ||
| * Provides models for the `idna` PyPI package. | ||
| * See https://pypi.org/project/idna/. | ||
| */ | ||
| private module IdnaModel { | ||
| /** A call to `idna.encode`. */ | ||
| private class IdnaEncodeCall extends Encoding::Range, DataFlow::CallCfgNode { | ||
| IdnaEncodeCall() { this = API::moduleImport("idna").getMember("encode").getACall() } | ||
|
|
||
| override DataFlow::Node getAnInput() { result = [this.getArg(0), this.getArgByName("s")] } | ||
|
|
||
| override DataFlow::Node getOutput() { result = this } | ||
|
|
||
| override string getFormat() { result = "IDNA" } | ||
| } | ||
|
|
||
| /** A call to `idna.decode`. */ | ||
| private class IdnaDecodeCall extends Decoding::Range, DataFlow::CallCfgNode { | ||
| IdnaDecodeCall() { this = API::moduleImport("idna").getMember("decode").getACall() } | ||
|
|
||
| override DataFlow::Node getAnInput() { result = [this.getArg(0), this.getArgByName("s")] } | ||
|
|
||
| override DataFlow::Node getOutput() { result = this } | ||
|
|
||
| override string getFormat() { result = "IDNA" } | ||
|
|
||
| override predicate mayExecuteInput() { none() } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /** | ||
| * Provides classes modeling security-relevant aspects of the `simplejson` PyPI package. | ||
| * See https://simplejson.readthedocs.io/en/latest/. | ||
| */ | ||
|
|
||
| private import python | ||
| private import semmle.python.dataflow.new.DataFlow | ||
| private import semmle.python.dataflow.new.TaintTracking | ||
| private import semmle.python.Concepts | ||
| private import semmle.python.ApiGraphs | ||
|
|
||
| /** | ||
| * Provides models for the `simplejson` PyPI package. | ||
| * See https://simplejson.readthedocs.io/en/latest/. | ||
| */ | ||
| private module SimplejsonModel { | ||
| /** | ||
| * A call to `simplejson.dumps`. | ||
| * | ||
| * See https://simplejson.readthedocs.io/en/latest/#simplejson.dumps | ||
| */ | ||
| private class SimplejsonDumpsCall extends Encoding::Range, DataFlow::CallCfgNode { | ||
| SimplejsonDumpsCall() { this = API::moduleImport("simplejson").getMember("dumps").getACall() } | ||
|
|
||
| override DataFlow::Node getAnInput() { result in [this.getArg(0), this.getArgByName("obj")] } | ||
|
|
||
| override DataFlow::Node getOutput() { result = this } | ||
|
|
||
| override string getFormat() { result = "JSON" } | ||
| } | ||
|
|
||
| /** | ||
| * A call to `simplejson.dump`. | ||
| * | ||
| * See https://simplejson.readthedocs.io/en/latest/#simplejson.dump | ||
| */ | ||
| private class SimplejsonDumpCall extends Encoding::Range, DataFlow::CallCfgNode { | ||
| SimplejsonDumpCall() { this = API::moduleImport("simplejson").getMember("dump").getACall() } | ||
|
|
||
| override DataFlow::Node getAnInput() { result in [this.getArg(0), this.getArgByName("obj")] } | ||
|
|
||
| override DataFlow::Node getOutput() { | ||
| result.(DataFlow::PostUpdateNode).getPreUpdateNode() in [ | ||
| this.getArg(1), this.getArgByName("fp") | ||
| ] | ||
| } | ||
|
|
||
| override string getFormat() { result = "JSON" } | ||
| } | ||
|
|
||
| /** | ||
| * A call to `simplejson.loads`. | ||
| * | ||
| * See https://simplejson.readthedocs.io/en/latest/#simplejson.loads | ||
| */ | ||
| private class SimplejsonLoadsCall extends Decoding::Range, DataFlow::CallCfgNode { | ||
| SimplejsonLoadsCall() { this = API::moduleImport("simplejson").getMember("loads").getACall() } | ||
|
|
||
| override DataFlow::Node getAnInput() { result in [this.getArg(0), this.getArgByName("s")] } | ||
|
|
||
| override DataFlow::Node getOutput() { result = this } | ||
|
|
||
| override string getFormat() { result = "JSON" } | ||
|
|
||
| override predicate mayExecuteInput() { none() } | ||
| } | ||
|
|
||
| /** | ||
| * A call to `simplejson.load`. | ||
| * | ||
| * See https://simplejson.readthedocs.io/en/latest/#simplejson.load | ||
| */ | ||
| private class SimplejsonLoadCall extends Decoding::Range, DataFlow::CallCfgNode { | ||
| SimplejsonLoadCall() { this = API::moduleImport("simplejson").getMember("load").getACall() } | ||
|
|
||
| override DataFlow::Node getAnInput() { result in [this.getArg(0), this.getArgByName("fp")] } | ||
|
|
||
| override DataFlow::Node getOutput() { result = this } | ||
|
|
||
| override string getFormat() { result = "JSON" } | ||
|
|
||
| override predicate mayExecuteInput() { none() } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /** | ||
| * Provides classes modeling security-relevant aspects of the `ujson` PyPI package. | ||
| * See https://pypi.org/project/ujson/. | ||
| */ | ||
|
|
||
| private import python | ||
| private import semmle.python.dataflow.new.DataFlow | ||
| private import semmle.python.dataflow.new.TaintTracking | ||
| private import semmle.python.Concepts | ||
| private import semmle.python.ApiGraphs | ||
|
|
||
| /** | ||
| * Provides models for the `ujson` PyPI package. | ||
| * See https://pypi.org/project/ujson/. | ||
| */ | ||
| private module UjsonModel { | ||
| /** | ||
| * A call to `usjon.dumps` or `ujson.encode`. | ||
| */ | ||
| private class UjsonDumpsCall extends Encoding::Range, DataFlow::CallCfgNode { | ||
| UjsonDumpsCall() { this = API::moduleImport("ujson").getMember(["dumps", "encode"]).getACall() } | ||
|
|
||
| override DataFlow::Node getAnInput() { result in [this.getArg(0), this.getArgByName("obj")] } | ||
|
|
||
| override DataFlow::Node getOutput() { result = this } | ||
|
|
||
| override string getFormat() { result = "JSON" } | ||
| } | ||
|
|
||
| /** | ||
| * A call to `ujson.dump`. | ||
| */ | ||
| private class UjsonDumpCall extends Encoding::Range, DataFlow::CallCfgNode { | ||
| UjsonDumpCall() { this = API::moduleImport("ujson").getMember("dump").getACall() } | ||
|
|
||
| override DataFlow::Node getAnInput() { result = this.getArg(0) } | ||
|
|
||
| override DataFlow::Node getOutput() { | ||
| result.(DataFlow::PostUpdateNode).getPreUpdateNode() = this.getArg(1) | ||
| } | ||
|
|
||
| override string getFormat() { result = "JSON" } | ||
| } | ||
|
|
||
| /** | ||
| * A call to `ujson.loads` or `ujson.decode`. | ||
| */ | ||
| private class UjsonLoadsCall extends Decoding::Range, DataFlow::CallCfgNode { | ||
| UjsonLoadsCall() { this = API::moduleImport("ujson").getMember(["loads", "decode"]).getACall() } | ||
|
|
||
| // Note: Most other JSON libraries allow the keyword argument `s`, but as of version | ||
| // 4.0.2 `ujson` uses `obj` instead. | ||
| override DataFlow::Node getAnInput() { result in [this.getArg(0), this.getArgByName("obj")] } | ||
|
|
||
| override DataFlow::Node getOutput() { result = this } | ||
|
|
||
| override string getFormat() { result = "JSON" } | ||
|
|
||
| override predicate mayExecuteInput() { none() } | ||
| } | ||
|
|
||
| /** | ||
| * A call to `ujson.load`. | ||
| */ | ||
| private class UjsonLoadCall extends Decoding::Range, DataFlow::CallCfgNode { | ||
| UjsonLoadCall() { this = API::moduleImport("ujson").getMember("load").getACall() } | ||
|
|
||
| override DataFlow::Node getAnInput() { result = this.getArg(0) } | ||
|
|
||
| override DataFlow::Node getOutput() { result = this } | ||
|
|
||
| override string getFormat() { result = "JSON" } | ||
|
|
||
| override predicate mayExecuteInput() { none() } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| import python | ||
| import experimental.meta.ConceptsTest |
3 changes: 3 additions & 0 deletions
3
python/ql/test/library-tests/frameworks/idna/InlineTaintTest.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| argumentToEnsureNotTaintedNotMarkedAsSpurious | ||
| untaintedArgumentToEnsureTaintedNotMarkedAsMissing | ||
| failures |
1 change: 1 addition & 0 deletions
1
python/ql/test/library-tests/frameworks/idna/InlineTaintTest.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| import experimental.meta.InlineTaintTest |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.