Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1d4b4ee

Browse files
tausbnRasmusWL
authored andcommitted
Python: Add Requests response model
This required making some of the relevant bits public, but they are marked as internal anyway.
1 parent cb1efa9 commit 1d4b4ee

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

python/ql/lib/semmle/python/frameworks/Requests.qll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ private import semmle.python.ApiGraphs
1212
private import semmle.python.dataflow.new.TaintTracking
1313
private import semmle.python.frameworks.internal.InstanceTaintStepsHelper
1414
private import semmle.python.frameworks.Stdlib
15+
private import semmle.python.frameworks.data.ModelsAsData
1516

1617
/**
1718
* INTERNAL: Do not use.
@@ -22,7 +23,7 @@ private import semmle.python.frameworks.Stdlib
2223
* - https://pypi.org/project/requests/
2324
* - https://requests.readthedocs.io/en/latest/
2425
*/
25-
private module Requests {
26+
module Requests {
2627
/**
2728
* An outgoing HTTP request, from the `requests` library.
2829
*
@@ -91,10 +92,12 @@ private module Requests {
9192
*/
9293
module Response {
9394
/** Gets a reference to the `requests.models.Response` class. */
94-
private API::Node classRef() {
95+
API::Node classRef() {
9596
result = API::moduleImport("requests").getMember("models").getMember("Response")
9697
or
9798
result = API::moduleImport("requests").getMember("Response")
99+
or
100+
result = ModelOutput::getATypeNode("requests.models.Response~Subclass").getASubclass*()
98101
}
99102

100103
/**

python/ql/src/meta/ClassHierarchy/Find.ql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ private import semmle.python.frameworks.FastApi
1313
private import semmle.python.frameworks.Django
1414
private import semmle.python.frameworks.Tornado
1515
private import semmle.python.frameworks.Stdlib
16+
private import semmle.python.frameworks.Requests
1617
import semmle.python.frameworks.data.internal.ApiGraphModelsExtensions as Extensions
1718

1819
class FlaskViewClasses extends FindSubclassesSpec {
@@ -214,6 +215,12 @@ class FlaskResponse extends FindSubclassesSpec {
214215
override API::Node getAlreadyModeledClass() { result = Flask::Response::classRef() }
215216
}
216217

218+
class RequestsResponse extends FindSubclassesSpec {
219+
RequestsResponse() { this = "requests.models.Response~Subclass" }
220+
221+
override API::Node getAlreadyModeledClass() { result = Requests::Response::classRef() }
222+
}
223+
217224
bindingset[fullyQualified]
218225
predicate fullyQualifiedToYamlFormat(string fullyQualified, string type2, string path) {
219226
exists(int firstDot | firstDot = fullyQualified.indexOf(".", 0, 0) |

0 commit comments

Comments
 (0)