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

Skip to content

Commit e7c9bc3

Browse files
Rasmus Lerchedahl PetersenRasmus Lerchedahl Petersen
authored andcommitted
Python: support some custom subclasses
1 parent e693497 commit e7c9bc3

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

python/ql/src/experimental/semmle/python/frameworks/Django.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,9 @@ private module Django {
710710
t.start() and
711711
result = http_attr("HttpResponse")
712712
or
713+
// subclass
714+
result.asExpr().(ClassExpr).getABase() = classRef(t.continue()).asExpr()
715+
or
713716
exists(DataFlow::TypeTracker t2 | result = classRef(t2).track(t2, t))
714717
}
715718

python/ql/test/experimental/library-tests/frameworks/django-v1/response_test.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,11 @@ def __init__(self, banner, content, *args, **kwargs):
4343
super().__init__(content, *args, content_type="text/html", **kwargs)
4444

4545
def xss__custom_response(request):
46-
return CustomResponse("ACME Responses", request.GET("name")) # $f-:HttpResponse $f-:mimetype=text/html $f-:responseBody=Attribute()
46+
return CustomResponse("ACME Responses", request.GET("name")) # $HttpResponse $f-:mimetype=text/html $f-:responseBody=Attribute() $f+:responseBody="ACME Responses"
47+
48+
class CustomJsonResponse(JsonResponse):
49+
def __init__(self, banner, content, *args, **kwargs):
50+
super().__init__(content, *args, content_type="text/html", **kwargs)
51+
52+
def safe__custom_json_response(request):
53+
return CustomJsonResponse("ACME Responses", {"foo": request.GET.get("foo")}) # $f-:HttpResponse $f-:mimetype=application/json $f-:responseBody=Dict

0 commit comments

Comments
 (0)