This document consolidates vulnerabilities from multiple lists into a single, de-duplicated list.
-
Vulnerability Name: Information Disclosure via OrderableListMixin
-
Description:
- An attacker accesses a publicly available list view that uses
OrderableListMixin
. - The attacker inspects the HTML source or available documentation to identify the
orderable_columns
defined in the view. - The attacker crafts a malicious URL by appending the
order_by
query parameter with a sensitive column name fromorderable_columns
, andordering
parameter to specify the order (asc or desc). - The server processes the request and orders the list of objects based on the attacker-specified sensitive column.
- Although the sensitive column's data may not be directly displayed, the attacker can infer information about the data by observing the order of the list. For example, if ordering by a column like
is_staff
changes the order of displayed items, the attacker can deduce which items correspond to staff users.
- An attacker accesses a publicly available list view that uses
-
Impact:
- Information Disclosure: Attackers can potentially infer sensitive information about the data being listed, such as internal statuses, flags, or timestamps, even if these details are not directly displayed in the list view. This can aid in further targeted attacks or profiling of the system's data.
-
Vulnerability Rank: High
-
Currently Implemented Mitigations:
- None in the
OrderableListMixin
itself. The mixin relies on developers to define a safe list oforderable_columns
.
- None in the
-
Missing Mitigations:
- Documentation should be improved to explicitly warn developers about the security implications of including sensitive column names in
orderable_columns
. - Input validation within
OrderableListMixin
to allow developers to define a safe-list or block-list of columns, and enforce it to prevent ordering by unintended columns. - A mechanism to sanitize or transform the
orderable_columns
list to ensure only safe, display-relevant columns are used for ordering.
- Documentation should be improved to explicitly warn developers about the security implications of including sensitive column names in
-
Preconditions:
- A Django application uses
django-braces
library. - A ListView in the application is implemented using
OrderableListMixin
. - The developer has mistakenly included sensitive internal database column names in the
orderable_columns
attribute of the view. - The ListView is publicly accessible without strict authorization controls.
- A Django application uses
-
Source Code Analysis:
- File:
/code/braces/views/_queries.py
- Class:
OrderableListMixin
- Method:
get_ordered_queryset(self, queryset=None)
def get_ordered_queryset(self, queryset=None): """ Augments ``QuerySet`` with order_by statement if possible :param QuerySet queryset: ``QuerySet`` to ``order_by`` :return: QuerySet """ get_order_by = self.request.GET.get("order_by") if get_order_by in self.get_orderable_columns(): # [!] Vulnerability Point: Checks if user-provided order_by is in developer-defined orderable_columns order_by = get_order_by else: order_by = self.get_orderable_columns_default() self.order_by = order_by self.ordering = self.get_ordering_default() if all([order_by, self.request.GET.get("ordering", self.ordering) == "desc" ]): order_by = f"-{order_by}" self.ordering = self.request.GET.get("ordering", self.ordering) return queryset.order_by(order_by) # [!] Vulnerability Point: Directly applies user-influenced order_by to queryset
- The
get_ordered_queryset
method retrieves theorder_by
parameter from the GET request. - It checks if this parameter is present in the
orderable_columns
list defined by the developer in the view. - Vulnerability: If the
order_by
parameter is inorderable_columns
, it is directly used inqueryset.order_by(order_by)
. Iforderable_columns
contains sensitive column names, an attacker can control the ordering and infer information. - There is no sanitization or validation of the column names beyond checking inclusion in the
orderable_columns
list.
- File:
-
Security Test Case:
- Setup:
- Create a Django model
SensitiveData
with fieldstitle
(CharField) andinternal_status
(CharField, choices=['VIP', 'Normal']). - Create a ListView
SensitiveDataListView
usingOrderableListMixin
to displaySensitiveData
objects. - In
SensitiveDataListView
, setmodel = SensitiveData
,template_name = 'sensitive_list.html'
, and crucially,orderable_columns = ('title', 'internal_status')
. - Create a template
sensitive_list.html
that only displays thetitle
of eachSensitiveData
object in a list. - Populate the database with
SensitiveData
objects having differentinternal_status
values ('VIP', 'Normal').
- Create a Django model
- Test Steps:
- Access the
SensitiveDataListView
in a browser using a GET request without any query parameters (e.g.,/sensitive_data_list/
). Observe the default order of the list. - Craft a URL with the query parameter to order by the sensitive column:
/sensitive_data_list/?order_by=internal_status&ordering=asc
. - Reload the page with the crafted URL.
- Observe if the order of the displayed titles in the list changes compared to the default order.
- Repeat step 2 and 3 with
/sensitive_data_list/?order_by=internal_status&ordering=desc
. - Compare the order of items in the list for default,
asc
, anddesc
ordering byinternal_status
.
- Access the
- Expected Result:
- If the order of titles in the list changes predictably when ordering by
internal_status
(e.g., 'Normal' status items appear before 'VIP' status items in 'asc' order), it confirms the information disclosure vulnerability. An attacker can infer theinternal_status
of items by manipulating theorder_by
parameter, even though theinternal_status
itself is not directly displayed.
- If the order of titles in the list changes predictably when ordering by
- Setup: