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

Skip to content

Commit 43fe9ca

Browse files
tausbnRasmusWL
authored andcommitted
Python: Model rest_framework.exceptions.APIException
Only models the subclasses of `APIException` that share the same interface as `APIException` itself with regard to the `getBody` predicate.
1 parent 1f66659 commit 43fe9ca

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,23 @@ module RestFramework {
334334
* See https://www.django-rest-framework.org/api-guide/exceptions/#api-reference
335335
*/
336336
module ApiException {
337+
API::Node classRef() {
338+
exists(string className |
339+
className in [
340+
"APIException", "ValidationError", "ParseError", "AuthenticationFailed",
341+
"NotAuthenticated", "PermissionDenied", "NotFound", "NotAcceptable"
342+
] and
343+
result =
344+
API::moduleImport("rest_framework")
345+
.getMember("exceptions")
346+
.getMember(className)
347+
.getASubclass*()
348+
)
349+
or
350+
result =
351+
ModelOutput::getATypeNode("rest_framework.exceptions.APIException~Subclass").getASubclass*()
352+
}
353+
337354
/** A direct instantiation of `rest_framework.exceptions.ApiException` or subclass. */
338355
private class ClassInstantiation extends Http::Server::HttpResponse::Range,
339356
DataFlow::CallCfgNode
@@ -351,6 +368,8 @@ module RestFramework {
351368
.getMember("exceptions")
352369
.getMember(className)
353370
.getACall()
371+
or
372+
this = classRef().getACall() and className = "APIException"
354373
}
355374

356375
override DataFlow::Node getBody() {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,12 @@ class DjangoFileField extends FindSubclassesSpec {
445445
}
446446
}
447447

448+
class RestFrameworkApiException extends FindSubclassesSpec {
449+
RestFrameworkApiException() { this = "rest_framework.exceptions.APIException~Subclass" }
450+
451+
override API::Node getAlreadyModeledClass() { result = RestFramework::ApiException::classRef() }
452+
}
453+
448454
bindingset[fullyQualified]
449455
predicate fullyQualifiedToYamlFormat(string fullyQualified, string type2, string path) {
450456
exists(int firstDot | firstDot = fullyQualified.indexOf(".", 0, 0) |

0 commit comments

Comments
 (0)