1
1
from django .http .response import HttpResponse , HttpResponseRedirect , HttpResponsePermanentRedirect , JsonResponse , HttpResponseNotFound
2
2
from django .views .generic import RedirectView
3
3
import django .shortcuts
4
+ import json
4
5
5
6
# Not an XSS sink, since the Content-Type is not "text/html"
6
7
# FP reported in https://github.com/github/codeql-python-team/issues/38
@@ -13,6 +14,21 @@ def safe__manual_json_response(request):
13
14
json_data = '{"json": "{}"}' .format (request .GET .get ("foo" ))
14
15
return HttpResponse (json_data , content_type = "application/json" ) # $HttpResponse mimetype=application/json responseBody=json_data
15
16
17
+ # reproduction of FP seen here:
18
+ # Usage: https://github.com/edx/edx-platform/blob/d70ebe6343a1573c694d6cf68f92c1ad40b73d7d/lms/djangoapps/commerce/api/v0/views.py#L106
19
+ # DetailResponse def: https://github.com/edx/edx-platform/blob/d70ebe6343a1573c694d6cf68f92c1ad40b73d7d/lms/djangoapps/commerce/http.py#L9
20
+ # JsonResponse def: https://github.com/edx/edx-platform/blob/d70ebe6343a1573c694d6cf68f92c1ad40b73d7d/common/djangoapps/util/json_request.py#L60
21
+ class MyJsonResponse (HttpResponse ):
22
+ def __init__ (self , data ):
23
+ serialized = json .dumps (data ).encode ("utf-8" ) # $ encodeFormat=JSON encodeInput=data encodeOutput=json.dumps(..)
24
+ super ().__init__ (serialized , content_type = "application/json" )
25
+
26
+ # Not an XSS sink, since the Content-Type is not "text/html"
27
+ def safe__custom_json_response (request ):
28
+ json_data = '{"json": "{}"}' .format (request .GET .get ("foo" ))
29
+ return MyJsonResponse (json_data ) # $HttpResponse responseBody=json_data SPURIOUS: mimetype=text/html MISSING: mimetype=application/json
30
+
31
+
16
32
# Not an XSS sink, since the Content-Type is not "text/html"
17
33
def safe__manual_content_type (request ):
18
34
return HttpResponse ('<img src="0" onerror="alert(1)">' , content_type = "text/plain" ) # $HttpResponse mimetype=text/plain responseBody='<img src="0" onerror="alert(1)">'
0 commit comments