← All challenges
easydjango/django · v3.1

Settings are cleaned insufficiently.

Try this bug with AI

Fix it in the original repo with an AI agent and get feedback on how you worked.

2 free rounds each week

Round mode
  • Time limit60 min
  • Token budgetup to 1M
  • Worth up to135 XP
Sign up or sign in to start

Read the sample report

From a simulated Django round

You changed code before reproducing the bug.

Run the failing test before the first edit, so you know the failure you are fixing and can tell when it is gone.

Problem statement

Description

Posting publicly after checking with the rest of the security team.
I just ran into a case where django.views.debug.SafeExceptionReporterFilter.get_safe_settings() would return several un-cleansed values. Looking at cleanse_setting() I realized that we ​only take care of dicts but don't take other types of iterables into account but ​return them as-is.
Example:
In my settings.py I have this:
MY_SETTING = {
"foo": "value",
"secret": "value",
"token": "value",
"something": [
{"foo": "value"},
{"secret": "value"},
{"token": "value"},
],
"else": [
[
{"foo": "value"},
{"secret": "value"},
{"token": "value"},
],
[
{"foo": "value"},
{"secret": "value"},
{"token": "value"},
],
]
}
On Django 3.0 and below:

>> import pprint
>> from django.views.debug import get_safe_settings
>> pprint.pprint(get_safe_settings()["MY_SETTING"])

{'else': [[{'foo': 'value'}, {'secret': 'value'}, {'token': 'value'}],
[{'foo': 'value'}, {'secret': 'value'}, {'token': 'value'}]],
'foo': 'value',
'secret': '********************',
'something': [{'foo': 'value'}, {'secret': 'value'}, {'token': 'value'}],
'token': '********************'}
On Django 3.1 and up:

>> from django.views.debug import SafeExceptionReporterFilter
>> import pprint
>> pprint.pprint(SafeExceptionReporterFilter().get_safe_settings()["MY_SETTING"])

{'else': [[{'foo': 'value'}, {'secret': 'value'}, {'token': 'value'}],
[{'foo': 'value'}, {'secret': 'value'}, {'token': 'value'}]],
'foo': 'value',
'secret': '********************',
'something': [{'foo': 'value'}, {'secret': 'value'}, {'token': 'value'}],
'token': '********************'}

The environment starts at commit d51c50d836c5 (django/django 3.1), dependencies installed and tests runnable from the first minute. You are graded by hidden tests taken from the fix that was actually merged upstream.