Skip to content

Commit a23904c

Browse files
committed
Add taint tests
1 parent 3ab5fd5 commit a23904c

File tree

1 file changed

+19
-1
lines changed
  • python/ql/test/library-tests/frameworks/rest_framework

1 file changed

+19
-1
lines changed

python/ql/test/library-tests/frameworks/rest_framework/taint_test.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,30 @@ def get(self, request: Request, routed_param): # $ requestHandler routedParamete
107107

108108
return Response("ok") # $ HttpResponse
109109

110+
# Viewsets
111+
# see https://www.django-rest-framework.org/api-guide/viewsets/
112+
113+
class MyModelViewSet(viewsets.ModelViewSet):
114+
def retrieve(self, request, *args, **kwargs): # $ requestHandler
115+
ensure_tainted(
116+
request, # $ tainted
117+
request.GET, # $ tainted
118+
request.GET.get("pk"), # $ tainted
119+
)
120+
121+
ensure_tainted(
122+
kwargs, # $ tainted
123+
kwargs["pk"], # $ tainted
124+
kwargs.get("pk"), # $ tainted
125+
)
126+
return Response("retrieve") # $ HttpResponse
110127

111128

112129
# fake setup, you can't actually run this
113130
urlpatterns = [
114131
path("test-taint/<routed_param>", test_taint), # $ routeSetup="test-taint/<routed_param>"
115-
path("ClassView/<routed_param>", MyClass.as_view()), # $ routeSetup="ClassView/<routed_param>"
132+
path("ClassView/<routed_param>", MyClass.as_view()), # $ routeSetup="ClassView/<routed_param>",
133+
path("MyModelViewSet/<routed_param>", MyModelViewSet.as_view()) # $ routeSetup="MyModelViewSet/<routed_param>",
116134
]
117135

118136
# tests with no route-setup, but we can still tell that these are using Django REST

0 commit comments

Comments
 (0)