|
1 | 1 | """testing views for Django 2.x and 3.x""" |
2 | 2 | from django.urls import path, re_path |
3 | | -from django.http import HttpResponse |
| 3 | +from django.http import HttpResponse, HttpResponseRedirect, JsonResponse, HttpResponseNotFound |
4 | 4 | from django.views import View |
5 | 5 |
|
6 | 6 |
|
@@ -99,24 +99,26 @@ def not_valid_identifier(request): |
99 | 99 | ] |
100 | 100 |
|
101 | 101 |
|
102 | | -################################################################################ |
103 | | - |
| 102 | +# Not an XSS sink, since the Content-Type is not "text/html" |
| 103 | +# FP reported in https://github.com/github/codeql-python-team/issues/38 |
| 104 | +def fp_json_response(request): |
| 105 | + # implicitly sets Content-Type to "application/json" |
| 106 | + return JsonResponse({"foo": request.GET.get("foo")}) # TODO |
104 | 107 |
|
105 | | -# We should abort if a decorator is used. As demonstrated below, anything might happen |
| 108 | +# Not an XSS sink, since the Content-Type is not "text/html" |
| 109 | +def fp_manual_json_response(request): |
| 110 | + json_data = '{"json": "{}"}'.format(request.GET.get("foo")) |
| 111 | + return HttpResponse(json_data, content_type="application/json") # TODO |
106 | 112 |
|
107 | | -# def reverse_kwargs(f): |
108 | | -# @wraps(f) |
109 | | -# def f_(*args, **kwargs): |
110 | | -# new_kwargs = dict() |
111 | | -# for key, value in kwargs.items(): |
112 | | -# new_kwargs[key[::-1]] = value |
113 | | -# return f(*args, **new_kwargs) |
114 | | -# return f_ |
| 113 | +# Not an XSS sink, since the Content-Type is not "text/html" |
| 114 | +def fp_manual_content_type(reuqest): |
| 115 | + return HttpResponse('<img src="0" onerror="alert(1)">', content_type="text/plain") # TODO |
115 | 116 |
|
116 | | -# @reverse_kwargs |
117 | | -# def decorators_can_do_anything(request, oof, foo=None): |
118 | | -# return HttpResponse('This is a mess'[::-1]) |
| 117 | +# XSS FP reported in https://github.com/github/codeql/issues/3466 |
| 118 | +# Note: This should be a open-redirect sink, but not a XSS sink. |
| 119 | +def fp_redirect(request): |
| 120 | + return HttpResponseRedirect(request.GET.get("next")) # TODO |
119 | 121 |
|
120 | | -# urlpatterns = [ |
121 | | -# path('rev/<foo>', decorators_can_do_anything), |
122 | | -# ] |
| 122 | +# Ensure that subclasses are still vuln to XSS |
| 123 | +def tp_not_found(request): |
| 124 | + return HttpResponseNotFound(request.GET.get("name")) |
0 commit comments