Menu

Your DRF Permission Class Protects /projects/42, but /projects Still Lists Every Tenant
📰

Your DRF Permission Class Protects /projects/42, but /projects Still Lists Every Tenant

DEV Community: django·ByteBridge Talent LLC·about 20 hours ago
#ok7oZn72
#devtodjango#devto#dev#object#list
Reading 0:00
15s threshold

The problem

A question on a public coding board this month pointed at a quiet hole in a multi-tenant API. The author had a Django REST Framework (DRF) permission class that checked obj.workspace_id == request.user.workspace_id . Retrieve, update and delete all call get_object() , so those routes were protected. The list route does not call get_object() . If get_queryset still returned Project.objects.all() , the list handed back every workspace's rows.

The same gap shows up on a custom @action(detail=False) , or on a get_object you write yourself and forget to hook up. Filtering in get_queryset closes the hole, but then the rule lives in two places, and a new viewset can ship without the filter. The post asked how people keep that from happening.

This is not a rumor. The official DRF permissions page says it straight.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.