Skip to content

Commit 2873afb

Browse files
[AutoPR- Security] Patch python3 for CVE-2026-1299 [MEDIUM] (#15864)
1 parent f2c2b18 commit 2873afb

6 files changed

Lines changed: 135 additions & 21 deletions

File tree

SPECS/python3/CVE-2026-1299.patch

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
From 8e35c877df664a0c424f4f7476d541d21a3b7288 Mon Sep 17 00:00:00 2001
2+
From: Seth Michael Larson <seth@python.org>
3+
Date: Fri, 23 Jan 2026 08:59:35 -0600
4+
Subject: [PATCH] gh-144125: email: verify headers are sound in BytesGenerator
5+
(cherry picked from commit 052e55e7d44718fe46cbba0ca995cb8fcc359413)
6+
7+
Co-authored-by: Seth Michael Larson <seth@python.org>
8+
Co-authored-by: Denis Ledoux <dle@odoo.com>
9+
Co-authored-by: Denis Ledoux <5822488+beledouxdenis@users.noreply.github.com>
10+
Co-authored-by: Petr Viktorin <302922+encukou@users.noreply.github.com>
11+
Co-authored-by: Bas Bloemsaat <1586868+basbloemsaat@users.noreply.github.com>
12+
Signed-off-by: Azure Linux Security Servicing Account <azurelinux-security@microsoft.com>
13+
Upstream-reference: https://github.com/python/cpython/pull/144188.patch
14+
---
15+
Lib/email/generator.py | 12 +++++++++++-
16+
Lib/test/test_email/test_generator.py | 4 +++-
17+
Lib/test/test_email/test_policy.py | 6 +++++-
18+
.../2026-01-21-12-34-05.gh-issue-144125.TAz5uo.rst | 4 ++++
19+
4 files changed, 23 insertions(+), 3 deletions(-)
20+
create mode 100644 Misc/NEWS.d/next/Security/2026-01-21-12-34-05.gh-issue-144125.TAz5uo.rst
21+
22+
diff --git a/Lib/email/generator.py b/Lib/email/generator.py
23+
index 47b9df8..8cbc43e 100644
24+
--- a/Lib/email/generator.py
25+
+++ b/Lib/email/generator.py
26+
@@ -22,6 +22,7 @@ NL = '\n' # XXX: no longer used by the code below.
27+
NLCRE = re.compile(r'\r\n|\r|\n')
28+
fcre = re.compile(r'^From ', re.MULTILINE)
29+
NEWLINE_WITHOUT_FWSP = re.compile(r'\r\n[^ \t]|\r[^ \n\t]|\n[^ \t]')
30+
+NEWLINE_WITHOUT_FWSP_BYTES = re.compile(br'\r\n[^ \t]|\r[^ \n\t]|\n[^ \t]')
31+
32+
33+
class Generator:
34+
@@ -429,7 +430,16 @@ class BytesGenerator(Generator):
35+
# This is almost the same as the string version, except for handling
36+
# strings with 8bit bytes.
37+
for h, v in msg.raw_items():
38+
- self._fp.write(self.policy.fold_binary(h, v))
39+
+ folded = self.policy.fold_binary(h, v)
40+
+ if self.policy.verify_generated_headers:
41+
+ linesep = self.policy.linesep.encode()
42+
+ if not folded.endswith(linesep):
43+
+ raise HeaderWriteError(
44+
+ f'folded header does not end with {linesep!r}: {folded!r}')
45+
+ if NEWLINE_WITHOUT_FWSP_BYTES.search(folded.removesuffix(linesep)):
46+
+ raise HeaderWriteError(
47+
+ f'folded header contains newline: {folded!r}')
48+
+ self._fp.write(folded)
49+
# A blank line always separates headers from body
50+
self.write(self._NL)
51+
52+
diff --git a/Lib/test/test_email/test_generator.py b/Lib/test/test_email/test_generator.py
53+
index c75a842..3ca79ed 100644
54+
--- a/Lib/test/test_email/test_generator.py
55+
+++ b/Lib/test/test_email/test_generator.py
56+
@@ -313,7 +313,7 @@ class TestGenerator(TestGeneratorBase, TestEmailBase):
57+
self.assertEqual(s.getvalue(), self.typ(expected))
58+
59+
def test_verify_generated_headers(self):
60+
- """gh-121650: by default the generator prevents header injection"""
61+
+ # gh-121650: by default the generator prevents header injection
62+
class LiteralHeader(str):
63+
name = 'Header'
64+
def fold(self, **kwargs):
65+
@@ -334,6 +334,8 @@ class TestGenerator(TestGeneratorBase, TestEmailBase):
66+
67+
with self.assertRaises(email.errors.HeaderWriteError):
68+
message.as_string()
69+
+ with self.assertRaises(email.errors.HeaderWriteError):
70+
+ message.as_bytes()
71+
72+
73+
class TestBytesGenerator(TestGeneratorBase, TestEmailBase):
74+
diff --git a/Lib/test/test_email/test_policy.py b/Lib/test/test_email/test_policy.py
75+
index baa35fd..71ec0fe 100644
76+
--- a/Lib/test/test_email/test_policy.py
77+
+++ b/Lib/test/test_email/test_policy.py
78+
@@ -296,7 +296,7 @@ class PolicyAPITests(unittest.TestCase):
79+
policy.fold("Subject", subject)
80+
81+
def test_verify_generated_headers(self):
82+
- """Turning protection off allows header injection"""
83+
+ # Turning protection off allows header injection
84+
policy = email.policy.default.clone(verify_generated_headers=False)
85+
for text in (
86+
'Header: Value\r\nBad: Injection\r\n',
87+
@@ -319,6 +319,10 @@ class PolicyAPITests(unittest.TestCase):
88+
message.as_string(),
89+
f"{text}\nBody",
90+
)
91+
+ self.assertEqual(
92+
+ message.as_bytes(),
93+
+ f"{text}\nBody".encode(),
94+
+ )
95+
96+
# XXX: Need subclassing tests.
97+
# For adding subclassed objects, make sure the usual rules apply (subclass
98+
diff --git a/Misc/NEWS.d/next/Security/2026-01-21-12-34-05.gh-issue-144125.TAz5uo.rst b/Misc/NEWS.d/next/Security/2026-01-21-12-34-05.gh-issue-144125.TAz5uo.rst
99+
new file mode 100644
100+
index 0000000..e6333e7
101+
--- /dev/null
102+
+++ b/Misc/NEWS.d/next/Security/2026-01-21-12-34-05.gh-issue-144125.TAz5uo.rst
103+
@@ -0,0 +1,4 @@
104+
+:mod:`~email.generator.BytesGenerator` will now refuse to serialize (write) headers
105+
+that are unsafely folded or delimited; see
106+
+:attr:`~email.policy.Policy.verify_generated_headers`. (Contributed by Bas
107+
+Bloemsaat and Petr Viktorin in :gh:`121650`).
108+
--
109+
2.45.4
110+

SPECS/python3/python3.spec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Summary: A high-level scripting language
77
Name: python3
88
Version: 3.12.9
9-
Release: 8%{?dist}
9+
Release: 9%{?dist}
1010
License: PSF
1111
Vendor: Microsoft Corporation
1212
Distribution: Azure Linux
@@ -29,6 +29,7 @@ Patch9: CVE-2025-13837.patch
2929
Patch10: CVE-2025-11468.patch
3030
Patch11: CVE-2026-0672.patch
3131
Patch12: CVE-2026-0865.patch
32+
Patch13: CVE-2026-1299.patch
3233

3334
BuildRequires: bzip2-devel
3435
BuildRequires: expat-devel >= 2.1.0
@@ -251,6 +252,9 @@ rm -rf %{buildroot}%{_bindir}/__pycache__
251252
%{_libdir}/python%{majmin}/test/*
252253

253254
%changelog
255+
* Mon Feb 16 2026 Azure Linux Security Servicing Account <azurelinux-security@microsoft.com> - 3.12.9-9
256+
- Patch for CVE-2026-1299
257+
254258
* Wed Jan 28 2026 Azure Linux Security Servicing Account <azurelinux-security@microsoft.com> - 3.12.9-8
255259
- Patch for CVE-2026-0865, CVE-2025-11468, CVE-2026-0672
256260

toolkit/resources/manifests/package/pkggen_core_aarch64.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ ca-certificates-base-3.0.0-14.azl3.noarch.rpm
244244
ca-certificates-3.0.0-14.azl3.noarch.rpm
245245
dwz-0.14-2.azl3.aarch64.rpm
246246
unzip-6.0-22.azl3.aarch64.rpm
247-
python3-3.12.9-8.azl3.aarch64.rpm
248-
python3-devel-3.12.9-8.azl3.aarch64.rpm
249-
python3-libs-3.12.9-8.azl3.aarch64.rpm
247+
python3-3.12.9-9.azl3.aarch64.rpm
248+
python3-devel-3.12.9-9.azl3.aarch64.rpm
249+
python3-libs-3.12.9-9.azl3.aarch64.rpm
250250
python3-setuptools-69.0.3-5.azl3.noarch.rpm
251251
python3-pygments-2.7.4-2.azl3.noarch.rpm
252252
which-2.21-8.azl3.aarch64.rpm

toolkit/resources/manifests/package/pkggen_core_x86_64.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ ca-certificates-base-3.0.0-14.azl3.noarch.rpm
244244
ca-certificates-3.0.0-14.azl3.noarch.rpm
245245
dwz-0.14-2.azl3.x86_64.rpm
246246
unzip-6.0-22.azl3.x86_64.rpm
247-
python3-3.12.9-8.azl3.x86_64.rpm
248-
python3-devel-3.12.9-8.azl3.x86_64.rpm
249-
python3-libs-3.12.9-8.azl3.x86_64.rpm
247+
python3-3.12.9-9.azl3.x86_64.rpm
248+
python3-devel-3.12.9-9.azl3.x86_64.rpm
249+
python3-libs-3.12.9-9.azl3.x86_64.rpm
250250
python3-setuptools-69.0.3-5.azl3.noarch.rpm
251251
python3-pygments-2.7.4-2.azl3.noarch.rpm
252252
which-2.21-8.azl3.x86_64.rpm

toolkit/resources/manifests/package/toolchain_aarch64.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -531,19 +531,19 @@ pyproject-rpm-macros-1.12.0-2.azl3.noarch.rpm
531531
pyproject-srpm-macros-1.12.0-2.azl3.noarch.rpm
532532
python-markupsafe-debuginfo-2.1.3-1.azl3.aarch64.rpm
533533
python-wheel-wheel-0.43.0-1.azl3.noarch.rpm
534-
python3-3.12.9-8.azl3.aarch64.rpm
534+
python3-3.12.9-9.azl3.aarch64.rpm
535535
python3-audit-3.1.2-1.azl3.aarch64.rpm
536536
python3-cracklib-2.9.11-1.azl3.aarch64.rpm
537-
python3-curses-3.12.9-8.azl3.aarch64.rpm
537+
python3-curses-3.12.9-9.azl3.aarch64.rpm
538538
python3-Cython-3.0.5-2.azl3.aarch64.rpm
539-
python3-debuginfo-3.12.9-8.azl3.aarch64.rpm
540-
python3-devel-3.12.9-8.azl3.aarch64.rpm
539+
python3-debuginfo-3.12.9-9.azl3.aarch64.rpm
540+
python3-devel-3.12.9-9.azl3.aarch64.rpm
541541
python3-flit-core-3.9.0-1.azl3.noarch.rpm
542542
python3-gpg-1.23.2-2.azl3.aarch64.rpm
543543
python3-jinja2-3.1.2-3.azl3.noarch.rpm
544544
python3-libcap-ng-0.8.4-1.azl3.aarch64.rpm
545545
python3-libmount-2.40.2-3.azl3.aarch64.rpm
546-
python3-libs-3.12.9-8.azl3.aarch64.rpm
546+
python3-libs-3.12.9-9.azl3.aarch64.rpm
547547
python3-libxml2-2.11.5-8.azl3.aarch64.rpm
548548
python3-lxml-4.9.3-1.azl3.aarch64.rpm
549549
python3-magic-5.45-1.azl3.noarch.rpm
@@ -555,8 +555,8 @@ python3-pygments-2.7.4-2.azl3.noarch.rpm
555555
python3-rpm-4.18.2-1.azl3.aarch64.rpm
556556
python3-rpm-generators-14-11.azl3.noarch.rpm
557557
python3-setuptools-69.0.3-5.azl3.noarch.rpm
558-
python3-test-3.12.9-8.azl3.aarch64.rpm
559-
python3-tools-3.12.9-8.azl3.aarch64.rpm
558+
python3-test-3.12.9-9.azl3.aarch64.rpm
559+
python3-tools-3.12.9-9.azl3.aarch64.rpm
560560
python3-wheel-0.43.0-1.azl3.noarch.rpm
561561
readline-8.2-2.azl3.aarch64.rpm
562562
readline-debuginfo-8.2-2.azl3.aarch64.rpm

toolkit/resources/manifests/package/toolchain_x86_64.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -539,19 +539,19 @@ pyproject-rpm-macros-1.12.0-2.azl3.noarch.rpm
539539
pyproject-srpm-macros-1.12.0-2.azl3.noarch.rpm
540540
python-markupsafe-debuginfo-2.1.3-1.azl3.x86_64.rpm
541541
python-wheel-wheel-0.43.0-1.azl3.noarch.rpm
542-
python3-3.12.9-8.azl3.x86_64.rpm
542+
python3-3.12.9-9.azl3.x86_64.rpm
543543
python3-audit-3.1.2-1.azl3.x86_64.rpm
544544
python3-cracklib-2.9.11-1.azl3.x86_64.rpm
545-
python3-curses-3.12.9-8.azl3.x86_64.rpm
545+
python3-curses-3.12.9-9.azl3.x86_64.rpm
546546
python3-Cython-3.0.5-2.azl3.x86_64.rpm
547-
python3-debuginfo-3.12.9-8.azl3.x86_64.rpm
548-
python3-devel-3.12.9-8.azl3.x86_64.rpm
547+
python3-debuginfo-3.12.9-9.azl3.x86_64.rpm
548+
python3-devel-3.12.9-9.azl3.x86_64.rpm
549549
python3-flit-core-3.9.0-1.azl3.noarch.rpm
550550
python3-gpg-1.23.2-2.azl3.x86_64.rpm
551551
python3-jinja2-3.1.2-3.azl3.noarch.rpm
552552
python3-libcap-ng-0.8.4-1.azl3.x86_64.rpm
553553
python3-libmount-2.40.2-3.azl3.x86_64.rpm
554-
python3-libs-3.12.9-8.azl3.x86_64.rpm
554+
python3-libs-3.12.9-9.azl3.x86_64.rpm
555555
python3-libxml2-2.11.5-8.azl3.x86_64.rpm
556556
python3-lxml-4.9.3-1.azl3.x86_64.rpm
557557
python3-magic-5.45-1.azl3.noarch.rpm
@@ -563,8 +563,8 @@ python3-pygments-2.7.4-2.azl3.noarch.rpm
563563
python3-rpm-4.18.2-1.azl3.x86_64.rpm
564564
python3-rpm-generators-14-11.azl3.noarch.rpm
565565
python3-setuptools-69.0.3-5.azl3.noarch.rpm
566-
python3-test-3.12.9-8.azl3.x86_64.rpm
567-
python3-tools-3.12.9-8.azl3.x86_64.rpm
566+
python3-test-3.12.9-9.azl3.x86_64.rpm
567+
python3-tools-3.12.9-9.azl3.x86_64.rpm
568568
python3-wheel-0.43.0-1.azl3.noarch.rpm
569569
readline-8.2-2.azl3.x86_64.rpm
570570
readline-debuginfo-8.2-2.azl3.x86_64.rpm

0 commit comments

Comments
 (0)