diff options
| author | Soumya Sambu <soumya.sambu@windriver.com> | 2024-09-03 12:50:49 +0000 |
|---|---|---|
| committer | Steve Sakoman <steve@sakoman.com> | 2024-09-09 06:08:10 -0700 |
| commit | 31ea437bf7785201dd4fb04622ec97feba110c93 (patch) | |
| tree | ff1cb0c80f8deb9d7219d83217b3eb980254f948 /meta/recipes-devtools/python/python3 | |
| parent | 9541ad965035b28697b8df400d7b9bddc4d2519a (diff) | |
| download | poky-31ea437bf7785201dd4fb04622ec97feba110c93.tar.gz | |
python3: Fix CVE-2024-8088
There is a HIGH severity vulnerability affecting the CPython "zipfile"
module. When iterating over names of entries in a zip archive (for example,
methodsof "zipfile.ZipFile" like "namelist()", "iterdir()", "extractall()",
etc) the process can be put into an infinite loop with a maliciously crafted
zip archive. This defect applies when reading only metadata or extracting
the contents of the zip archive. Programs that are not handling
user-controlled zip archives are not affected.
References:
https://nvd.nist.gov/vuln/detail/CVE-2024-8088
Upstream-Patch:
https://github.com/corydolphin/flask-cors/commit/7ae310c56ac30e0b94fb42129aa377bf633256ec
(From OE-Core rev: 2d98276ba70ed6c44afecd42a7352f1b3030438f)
Signed-off-by: Soumya Sambu <soumya.sambu@windriver.com>
Signed-off-by: Steve Sakoman <steve@sakoman.com>
Diffstat (limited to 'meta/recipes-devtools/python/python3')
| -rw-r--r-- | meta/recipes-devtools/python/python3/CVE-2024-8088.patch | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/meta/recipes-devtools/python/python3/CVE-2024-8088.patch b/meta/recipes-devtools/python/python3/CVE-2024-8088.patch new file mode 100644 index 0000000000..13836f1ccc --- /dev/null +++ b/meta/recipes-devtools/python/python3/CVE-2024-8088.patch | |||
| @@ -0,0 +1,128 @@ | |||
| 1 | From dcc5182f27c1500006a1ef78e10613bb45788dea Mon Sep 17 00:00:00 2001 | ||
| 2 | From: "Miss Islington (bot)" | ||
| 3 | <31488909+miss-islington@users.noreply.github.com> | ||
| 4 | Date: Mon, 12 Aug 2024 02:35:17 +0200 | ||
| 5 | Subject: [PATCH] gh-122905: Sanitize names in zipfile.Path. (GH-122906) | ||
| 6 | (#122923) | ||
| 7 | |||
| 8 | CVE: CVE-2024-8088 | ||
| 9 | |||
| 10 | Upstream-Status: Backport [https://github.com/python/cpython/commit/dcc5182f27c1500006a1ef78e10613bb45788dea] | ||
| 11 | |||
| 12 | Signed-off-by: Soumya Sambu <soumya.sambu@windriver.com> | ||
| 13 | --- | ||
| 14 | Lib/test/test_zipfile/_path/test_path.py | 17 +++++ | ||
| 15 | Lib/zipfile/_path/__init__.py | 64 ++++++++++++++++++- | ||
| 16 | ...-08-11-14-08-04.gh-issue-122905.7tDsxA.rst | 1 + | ||
| 17 | 3 files changed, 81 insertions(+), 1 deletion(-) | ||
| 18 | create mode 100644 Misc/NEWS.d/next/Library/2024-08-11-14-08-04.gh-issue-122905.7tDsxA.rst | ||
| 19 | |||
| 20 | diff --git a/Lib/test/test_zipfile/_path/test_path.py b/Lib/test/test_zipfile/_path/test_path.py | ||
| 21 | index 06d5aab..90885db 100644 | ||
| 22 | --- a/Lib/test/test_zipfile/_path/test_path.py | ||
| 23 | +++ b/Lib/test/test_zipfile/_path/test_path.py | ||
| 24 | @@ -577,3 +577,20 @@ class TestPath(unittest.TestCase): | ||
| 25 | zipfile.Path(alpharep) | ||
| 26 | with self.assertRaises(KeyError): | ||
| 27 | alpharep.getinfo('does-not-exist') | ||
| 28 | + | ||
| 29 | + def test_malformed_paths(self): | ||
| 30 | + """ | ||
| 31 | + Path should handle malformed paths. | ||
| 32 | + """ | ||
| 33 | + data = io.BytesIO() | ||
| 34 | + zf = zipfile.ZipFile(data, "w") | ||
| 35 | + zf.writestr("/one-slash.txt", b"content") | ||
| 36 | + zf.writestr("//two-slash.txt", b"content") | ||
| 37 | + zf.writestr("../parent.txt", b"content") | ||
| 38 | + zf.filename = '' | ||
| 39 | + root = zipfile.Path(zf) | ||
| 40 | + assert list(map(str, root.iterdir())) == [ | ||
| 41 | + 'one-slash.txt', | ||
| 42 | + 'two-slash.txt', | ||
| 43 | + 'parent.txt', | ||
| 44 | + ] | ||
| 45 | diff --git a/Lib/zipfile/_path/__init__.py b/Lib/zipfile/_path/__init__.py | ||
| 46 | index 78c4135..42f9fde 100644 | ||
| 47 | --- a/Lib/zipfile/_path/__init__.py | ||
| 48 | +++ b/Lib/zipfile/_path/__init__.py | ||
| 49 | @@ -83,7 +83,69 @@ class InitializedState: | ||
| 50 | super().__init__(*args, **kwargs) | ||
| 51 | |||
| 52 | |||
| 53 | -class CompleteDirs(InitializedState, zipfile.ZipFile): | ||
| 54 | +class SanitizedNames: | ||
| 55 | + """ | ||
| 56 | + ZipFile mix-in to ensure names are sanitized. | ||
| 57 | + """ | ||
| 58 | + | ||
| 59 | + def namelist(self): | ||
| 60 | + return list(map(self._sanitize, super().namelist())) | ||
| 61 | + | ||
| 62 | + @staticmethod | ||
| 63 | + def _sanitize(name): | ||
| 64 | + r""" | ||
| 65 | + Ensure a relative path with posix separators and no dot names. | ||
| 66 | + | ||
| 67 | + Modeled after | ||
| 68 | + https://github.com/python/cpython/blob/bcc1be39cb1d04ad9fc0bd1b9193d3972835a57c/Lib/zipfile/__init__.py#L1799-L1813 | ||
| 69 | + but provides consistent cross-platform behavior. | ||
| 70 | + | ||
| 71 | + >>> san = SanitizedNames._sanitize | ||
| 72 | + >>> san('/foo/bar') | ||
| 73 | + 'foo/bar' | ||
| 74 | + >>> san('//foo.txt') | ||
| 75 | + 'foo.txt' | ||
| 76 | + >>> san('foo/.././bar.txt') | ||
| 77 | + 'foo/bar.txt' | ||
| 78 | + >>> san('foo../.bar.txt') | ||
| 79 | + 'foo../.bar.txt' | ||
| 80 | + >>> san('\\foo\\bar.txt') | ||
| 81 | + 'foo/bar.txt' | ||
| 82 | + >>> san('D:\\foo.txt') | ||
| 83 | + 'D/foo.txt' | ||
| 84 | + >>> san('\\\\server\\share\\file.txt') | ||
| 85 | + 'server/share/file.txt' | ||
| 86 | + >>> san('\\\\?\\GLOBALROOT\\Volume3') | ||
| 87 | + '?/GLOBALROOT/Volume3' | ||
| 88 | + >>> san('\\\\.\\PhysicalDrive1\\root') | ||
| 89 | + 'PhysicalDrive1/root' | ||
| 90 | + | ||
| 91 | + Retain any trailing slash. | ||
| 92 | + >>> san('abc/') | ||
| 93 | + 'abc/' | ||
| 94 | + | ||
| 95 | + Raises a ValueError if the result is empty. | ||
| 96 | + >>> san('../..') | ||
| 97 | + Traceback (most recent call last): | ||
| 98 | + ... | ||
| 99 | + ValueError: Empty filename | ||
| 100 | + """ | ||
| 101 | + | ||
| 102 | + def allowed(part): | ||
| 103 | + return part and part not in {'..', '.'} | ||
| 104 | + | ||
| 105 | + # Remove the drive letter. | ||
| 106 | + # Don't use ntpath.splitdrive, because that also strips UNC paths | ||
| 107 | + bare = re.sub('^([A-Z]):', r'\1', name, flags=re.IGNORECASE) | ||
| 108 | + clean = bare.replace('\\', '/') | ||
| 109 | + parts = clean.split('/') | ||
| 110 | + joined = '/'.join(filter(allowed, parts)) | ||
| 111 | + if not joined: | ||
| 112 | + raise ValueError("Empty filename") | ||
| 113 | + return joined + '/' * name.endswith('/') | ||
| 114 | + | ||
| 115 | + | ||
| 116 | +class CompleteDirs(InitializedState, SanitizedNames, zipfile.ZipFile): | ||
| 117 | """ | ||
| 118 | A ZipFile subclass that ensures that implied directories | ||
| 119 | are always included in the namelist. | ||
| 120 | diff --git a/Misc/NEWS.d/next/Library/2024-08-11-14-08-04.gh-issue-122905.7tDsxA.rst b/Misc/NEWS.d/next/Library/2024-08-11-14-08-04.gh-issue-122905.7tDsxA.rst | ||
| 121 | new file mode 100644 | ||
| 122 | index 0000000..1be44c9 | ||
| 123 | --- /dev/null | ||
| 124 | +++ b/Misc/NEWS.d/next/Library/2024-08-11-14-08-04.gh-issue-122905.7tDsxA.rst | ||
| 125 | @@ -0,0 +1 @@ | ||
| 126 | +:class:`zipfile.Path` objects now sanitize names from the zipfile. | ||
| 127 | -- | ||
| 128 | 2.40.0 | ||
