Skip to main content

Overview

Improper Access Control occurs when an application fails to properly enforce what a user is allowed to do. This is different from authentication (who you are). This vulnerability means an authenticated user (e..g., a “viewer”) can perform actions reserved for a different role (e.g., an “admin”), such as accessing an admin panel or deleting data.

Business Impact

This is a critical vulnerability that can lead to full system compromise. A low-privilege attacker can escalate their privileges, modify or delete any data, and lock out legitimate administrators.

Reference Details

CWE ID: CWE-284 OWASP Top 10 (2021): A01:2021 - Broken Access Control Severity: High

Framework-Specific Analysis and Remediation

All frameworks provide powerful, declarative, and imperative ways to handle authorization. The vulnerability is almost always a developer forgetting to apply these controls to a new endpoint or function. The principle is “Deny by Default.”

Framework Context

Django and DRF provide view decorators (@login_required, @permission_required) and permission_classes on views. The vulnerability is a view that lacks these.

Vulnerable Scenario 1: A Missing Permission Check

An admin view is created that only checks if the user is logged in, not if they are an admin.

Vulnerable Scenario 2: DRF ViewSet

A DRF ModelViewSet that has no permission_classes set.

Mitigation and Best Practices

For function-based views, use @user_passes_test(lambda u: u.is_staff). For class-based views, use UserPassesTestMixin. For DRF, set permission_classes explicitly, e.g., permission_classes = [permissions.IsAdminUser].

Secure Code Example

Testing Strategy

Write integration tests where you authenticate as a non-admin user. Attempt to access the admin endpoint and assert that the response is a 403 Forbidden.