티스토리 수익 글 보기

티스토리 수익 글 보기

[1.7.x] Fixed a settings leak possibility in the date template filter. · django/django@8a01c6b · GitHub
Skip to content

Commit 8a01c6b

Browse files
apollo13timgraham
authored andcommitted
[1.7.x] Fixed a settings leak possibility in the date template filter.
This is a security fix.
1 parent 3bd4359 commit 8a01c6b

File tree

3 files changed

+37
1
lines changed

3 files changed

+37
1
lines changed

django/utils/formats.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@
3131
}
3232

3333

34+
FORMAT_SETTINGS = frozenset([
35+
'DECIMAL_SEPARATOR',
36+
'THOUSAND_SEPARATOR',
37+
'NUMBER_GROUPING',
38+
'FIRST_DAY_OF_WEEK',
39+
'MONTH_DAY_FORMAT',
40+
'TIME_FORMAT',
41+
'DATE_FORMAT',
42+
'DATETIME_FORMAT',
43+
'SHORT_DATE_FORMAT',
44+
'SHORT_DATETIME_FORMAT',
45+
'YEAR_MONTH_FORMAT',
46+
'DATE_INPUT_FORMATS',
47+
'TIME_INPUT_FORMATS',
48+
'DATETIME_INPUT_FORMATS',
49+
])
50+
51+
3452
def reset_format_cache():
3553
"""Clear any cached formats.
3654
@@ -85,6 +103,8 @@ def get_format(format_type, lang=None, use_l10n=None):
85103
be localized (or not), overriding the value of settings.USE_L10N.
86104
"""
87105
format_type = force_str(format_type)
106+
if format_type not in FORMAT_SETTINGS:
107+
return format_type
88108
if use_l10n or (use_l10n is None and settings.USE_L10N):
89109
if lang is None:
90110
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
========

tests/i18n/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,9 @@ def test_localized_as_text_as_hidden_input(self):
828828
'<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" />'
829829
)
830830

831+
def test_format_arbitrary_settings(self):
832+
self.assertEqual(get_format('DEBUG'), 'DEBUG')
833+
831834

832835
class MiscTests(TestCase):
833836

0 commit comments

Comments
 (0)