티스토리 수익 글 보기

티스토리 수익 글 보기

[1.8.x] Fixed a settings leak possibility in the date template filter. · django/django@9f83fc2 · GitHub
Skip to content

Commit 9f83fc2

Browse files
apollo13timgraham
authored andcommitted
[1.8.x] Fixed a settings leak possibility in the date template filter.
This is a security fix.
1 parent 581b9e5 commit 9f83fc2

File tree

4 files changed

+51
2
lines changed

4 files changed

+51
2
lines changed

django/utils/formats.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@
3333
}
3434

3535

36+
FORMAT_SETTINGS = frozenset([
37+
'DECIMAL_SEPARATOR',
38+
'THOUSAND_SEPARATOR',
39+
'NUMBER_GROUPING',
40+
'FIRST_DAY_OF_WEEK',
41+
'MONTH_DAY_FORMAT',
42+
'TIME_FORMAT',
43+
'DATE_FORMAT',
44+
'DATETIME_FORMAT',
45+
'SHORT_DATE_FORMAT',
46+
'SHORT_DATETIME_FORMAT',
47+
'YEAR_MONTH_FORMAT',
48+
'DATE_INPUT_FORMATS',
49+
'TIME_INPUT_FORMATS',
50+
'DATETIME_INPUT_FORMATS',
51+
])
52+
53+
3654
def reset_format_cache():
3755
"""Clear any cached formats.
3856
@@ -95,6 +113,8 @@ def get_format(format_type, lang=None, use_l10n=None):
95113
be localized (or not), overriding the value of settings.USE_L10N.
96114
"""
97115
format_type = force_str(format_type)
116+
if format_type not in FORMAT_SETTINGS:
117+
return format_type
98118
if use_l10n or (use_l10n is None and settings.USE_L10N):
99119
if lang is None:
100120
lang = get_language()

docs/releases/1.7.11.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,20 @@ Django 1.7.11 release notes
44

55
*Under development*
66

7-
Django 1.7.11 fixes a data loss bug in 1.7.10.
7+
Django 1.7.11 fixes a security issue and a data loss bug in 1.7.10.
8+
9+
Fixed settings leak possibility in ``date`` template filter
10+
===========================================================
11+
12+
If an application allows users to specify an unvalidated format for dates and
13+
passes this format to the :tfilter:`date` filter, e.g.
14+
``{{ last_updated|date:user_date_format }}``, then a malicious user could
15+
obtain any secret in the application's settings by specifying a settings key
16+
instead of a date format. e.g. ``"SECRET_KEY"`` instead of ``"j/m/Y"``.
17+
18+
To remedy this, the underlying function used by the ``date`` template filter,
19+
``django.utils.formats.get_format()``, now only allows accessing the date/time
20+
formatting settings.
821

922
Bugfixes
1023
========

docs/releases/1.8.7.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,24 @@ Django 1.8.7 release notes
44

55
*Under development*
66

7-
Django 1.8.7 fixes several bugs in 1.8.6.
7+
Django 1.8.7 fixes a security issue and several bugs in 1.8.6.
88

99
Additionally, Django's vendored version of six, :mod:`django.utils.six`, has
1010
been upgraded to the latest release (1.10.0).
1111

12+
Fixed settings leak possibility in ``date`` template filter
13+
===========================================================
14+
15+
If an application allows users to specify an unvalidated format for dates and
16+
passes this format to the :tfilter:`date` filter, e.g.
17+
``{{ last_updated|date:user_date_format }}``, then a malicious user could
18+
obtain any secret in the application's settings by specifying a settings key
19+
instead of a date format. e.g. ``"SECRET_KEY"`` instead of ``"j/m/Y"``.
20+
21+
To remedy this, the underlying function used by the ``date`` template filter,
22+
``django.utils.formats.get_format()``, now only allows accessing the date/time
23+
formatting settings.
24+
1225
Bugfixes
1326
========
1427

tests/i18n/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,9 @@ def test_localized_as_text_as_hidden_input(self):
927927
'<input id="id_date_added" name="date_added" type="hidden" value="31.12.2009 06:00:00" />; <input id="id_cents_paid" name="cents_paid" type="hidden" value="59,47" />'
928928
)
929929

930+
def test_format_arbitrary_settings(self):
931+
self.assertEqual(get_format('DEBUG'), 'DEBUG')
932+
930933

931934
class MiscTests(TestCase):
932935

0 commit comments

Comments
 (0)