티스토리 수익 글 보기

티스토리 수익 글 보기

[3.1.x] Fixed CVE-2020-24584 — Fixed permission escalation in interm… · django/django@2b099ca · GitHub
Skip to content

Commit 2b099ca

Browse files
felixxmcarltongibson
authored andcommitted
[3.1.x] Fixed CVE-2020-24584 — Fixed permission escalation in intermediate-level directories of the file system cache on Python 3.7+.
Backport of f56b57976133129b0b351a38bba4ac882badabf0 from master.
1 parent 934430d commit 2b099ca

File tree

5 files changed

+55
5
lines changed

5 files changed

+55
5
lines changed

django/core/cache/backends/filebased.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,13 @@ def _cull(self):
114114
self._delete(fname)
115115

116116
def _createdir(self):
117-
os.makedirs(self._dir, 0o700, exist_ok=True)
117+
# Set the umask because os.makedirs() doesn't apply the "mode" argument
118+
# to intermediate-level directories.
119+
old_umask = os.umask(0o077)
120+
try:
121+
os.makedirs(self._dir, 0o700, exist_ok=True)
122+
finally:
123+
os.umask(old_umask)
118124

119125
def _key_to_file(self, key, version=None):
120126
"""

docs/releases/2.2.16.txt

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

55
*Expected September 1, 2020*
66

7-
Django 2.2.16 fixes a security issue and two data loss bugs in 2.2.15.
7+
Django 2.2.16 fixes two security issues and two data loss bugs in 2.2.15.
88

99
CVE-2020-24583: Incorrect permissions on intermediate-level directories on Python 3.7+
1010
======================================================================================
@@ -17,6 +17,13 @@ files and to intermediate-level collected static directories when using the
1717
You should review and manually fix permissions on existing intermediate-level
1818
directories.
1919

20+
CVE-2020-24584: Permission escalation in intermediate-level directories of the file system cache on Python 3.7+
21+
===============================================================================================================
22+
23+
On Python 3.7+, the intermediate-level directories of the file system cache had
24+
the system's standard umask rather than ``0o077`` (no group or others
25+
permissions).
26+
2027
Bugfixes
2128
========
2229

docs/releases/3.0.10.txt

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

55
*Expected September 1, 2020*
66

7-
Django 3.0.10 fixes a security issue and two data loss bugs in 3.0.9.
7+
Django 3.0.10 fixes two security issues and two data loss bugs in 3.0.9.
88

99
CVE-2020-24583: Incorrect permissions on intermediate-level directories on Python 3.7+
1010
======================================================================================
@@ -17,6 +17,13 @@ files and to intermediate-level collected static directories when using the
1717
You should review and manually fix permissions on existing intermediate-level
1818
directories.
1919

20+
CVE-2020-24584: Permission escalation in intermediate-level directories of the file system cache on Python 3.7+
21+
===============================================================================================================
22+
23+
On Python 3.7+, the intermediate-level directories of the file system cache had
24+
the system's standard umask rather than ``0o077`` (no group or others
25+
permissions).
26+
2027
Bugfixes
2128
========
2229

docs/releases/3.1.1.txt

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

55
*Expected September 1, 2020*
66

7-
Django 3.1.1 fixes a security issue and several bugs in 3.1.
7+
Django 3.1.1 fixes two security issues and several bugs in 3.1.
88

99
CVE-2020-24583: Incorrect permissions on intermediate-level directories on Python 3.7+
1010
======================================================================================
@@ -17,6 +17,13 @@ files and to intermediate-level collected static directories when using the
1717
You should review and manually fix permissions on existing intermediate-level
1818
directories.
1919

20+
CVE-2020-24584: Permission escalation in intermediate-level directories of the file system cache on Python 3.7+
21+
===============================================================================================================
22+
23+
On Python 3.7+, the intermediate-level directories of the file system cache had
24+
the system's standard umask rather than ``0o077`` (no group or others
25+
permissions).
26+
2027
Bugfixes
2128
========
2229

tests/cache/tests.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
import pickle
77
import re
88
import shutil
9+
import sys
910
import tempfile
1011
import threading
1112
import time
1213
import unittest
1314
from pathlib import Path
14-
from unittest import mock
15+
from unittest import mock, skipIf
1516

1617
from django.conf import settings
1718
from django.core import management, signals
@@ -1466,6 +1467,28 @@ def test_get_ignores_enoent(self):
14661467
# Returns the default instead of erroring.
14671468
self.assertEqual(cache.get('foo', 'baz'), 'baz')
14681469

1470+
@skipIf(
1471+
sys.platform == 'win32',
1472+
'Windows only partially supports umasks and chmod.',
1473+
)
1474+
def test_cache_dir_permissions(self):
1475+
os.rmdir(self.dirname)
1476+
dir_path = Path(self.dirname) / 'nested' / 'filebasedcache'
1477+
for cache_params in settings.CACHES.values():
1478+
cache_params['LOCATION'] = dir_path
1479+
setting_changed.send(self.__class__, setting='CACHES', enter=False)
1480+
cache.set('foo', 'bar')
1481+
self.assertIs(dir_path.exists(), True)
1482+
tests = [
1483+
dir_path,
1484+
dir_path.parent,
1485+
dir_path.parent.parent,
1486+
]
1487+
for directory in tests:
1488+
with self.subTest(directory=directory):
1489+
dir_mode = directory.stat().st_mode & 0o777
1490+
self.assertEqual(dir_mode, 0o700)
1491+
14691492
def test_get_does_not_ignore_non_filenotfound_exceptions(self):
14701493
with mock.patch('builtins.open', side_effect=OSError):
14711494
with self.assertRaises(OSError):

0 commit comments

Comments
 (0)