Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package python315 for openSUSE:Factory 
checked in at 2026-11-30 14:27:37
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python315 (Old)
 and      /work/SRC/openSUSE:Factory/.python315.new.1340718 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "python315"

Mon Nov 30 14:27:37 2026 rev:25 rq:1401515 version:3.15.2

Changes:
--------
--- /work/SRC/openSUSE:Factory/python315/python315.changes      2026-11-24 
12:46:05.100415184 +0100
+++ /work/SRC/openSUSE:Factory/.python315.new.1340718/python315.changes 
2026-11-30 14:30:37.609620904 +0100
@@ -1,0 +2,28 @@
+Wed Nov 25 19:46:28 UTC 2026 - Matej Cepl <[email protected]>
+
+- CVE-2026-115791: Prevent shadowing stdlib in
+  gzip/tarfile/zipfile CLI (GH-161706) (bsc#1290431)
+  CVE-2026-115791-prevent-shadowing-stdlib.patch
+
+-------------------------------------------------------------------
+Wed Nov 25 19:45:36 UTC 2026 - Matej Cepl <[email protected]>
+
+- CVE-2026-19552: Check hostname in ssl.get_server_certificate
+  with custom ca_certs (GH-161507) (bsc#1290435)
+  CVE-2026-19552-ssl-get_server_certificate-hostname.patch
+
+-------------------------------------------------------------------
+Wed Nov 25 19:44:45 UTC 2026 - Matej Cepl <[email protected]>
+
+- CVE-2026-16052: Refuse ';' in all cookie attributes except
+  Comment (GH-161711) (bsc#1290439)
+  CVE-2026-16052-cookie-semicolon-attributes.patch
+
+-------------------------------------------------------------------
+Wed Nov 25 19:43:34 UTC 2026 - Matej Cepl <[email protected]>
+
+- CVE-2026-124249: Check cookie policy before deleting expired
+  cookies in http.cookiejar (GH-161570) (bsc#1290433)
+  CVE-2026-124249-cookiejar-delete-expired.patch
+
+-------------------------------------------------------------------

New:
----
  CVE-2026-115791-prevent-shadowing-stdlib.patch
  CVE-2026-124249-cookiejar-delete-expired.patch
  CVE-2026-16052-cookie-semicolon-attributes.patch
  CVE-2026-19552-ssl-get_server_certificate-hostname.patch

----------(New B)----------
  New:  gzip/tarfile/zipfile CLI (GH-161706) (bsc#1290431)
  CVE-2026-115791-prevent-shadowing-stdlib.patch
  New:  cookies in http.cookiejar (GH-161570) (bsc#1290433)
  CVE-2026-124249-cookiejar-delete-expired.patch
  New:  Comment (GH-161711) (bsc#1290439)
  CVE-2026-16052-cookie-semicolon-attributes.patch
  New:  with custom ca_certs (GH-161507) (bsc#1290435)
  CVE-2026-19552-ssl-get_server_certificate-hostname.patch
----------(New E)----------

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ python315.spec ++++++
--- /var/tmp/diff_new_pack.MWVLSC/_old  2026-11-30 14:30:40.758753192 +0100
+++ /var/tmp/diff_new_pack.MWVLSC/_new  2026-11-30 14:30:40.763753402 +0100
@@ -236,6 +236,18 @@
 # PATCH-FIX-UPSTREAM CVE-2026-103995-http-client-content-length.patch 
bsc#1288328 [email protected]
 # validate http.client Content-Length and chunk-size (GH-150752)
 Patch51:        CVE-2026-103995-http-client-content-length.patch
+# PATCH-FIX-UPSTREAM CVE-2026-124249-cookiejar-delete-expired.patch 
bsc#1290433 [email protected]
+# Check cookie policy before deleting expired cookies in http.cookiejar 
(GH-161570)
+Patch52:        CVE-2026-124249-cookiejar-delete-expired.patch
+# PATCH-FIX-UPSTREAM CVE-2026-16052-cookie-semicolon-attributes.patch 
bsc#1290439 [email protected]
+# Refuse ';' in all cookie attributes except Comment (GH-161711)
+Patch53:        CVE-2026-16052-cookie-semicolon-attributes.patch
+# PATCH-FIX-UPSTREAM CVE-2026-19552-ssl-get_server_certificate-hostname.patch 
bsc#1290435 [email protected]
+# Check hostname in ssl.get_server_certificate with custom ca_certs (GH-161507)
+Patch54:        CVE-2026-19552-ssl-get_server_certificate-hostname.patch
+# PATCH-FIX-UPSTREAM CVE-2026-115791-prevent-shadowing-stdlib.patch 
bsc#1290431 [email protected]
+# Prevent shadowing stdlib in gzip/tarfile/zipfile CLI (GH-161706)
+Patch55:        CVE-2026-115791-prevent-shadowing-stdlib.patch
 #### Python 3.15 DEVELOPMENT PATCHES
 BuildRequires:  autoconf-archive
 BuildRequires:  automake

++++++ CVE-2026-115791-prevent-shadowing-stdlib.patch ++++++
>From 169e65f75d3b9de04cc74ee971a57230cc93eb2d Mon Sep 17 00:00:00 2001
From: Victor Stinner <[email protected]>
Date: Tue, 10 Nov 2026 00:49:01 +0100
Subject: [PATCH] gh-161705: Prevent shadowing stdlib in gzip/tarfile/zipfile
 CLI (GH-161706)

Remove sys.path[0] in gzip, tarfile and zipfile command line
interface to prevent shadowing standard library modules from
extracted files.

* Add sys._path0 variable.
* pymain_sys_path_add_path0() sets sys._path0.
* Add runpy._remove_sys_path0().
* gzip, tarfile and zipfile main functions now call
  _remove_sys_path0() to prevent shadowing stdlib modules from
  extracted files.
(cherry picked from commit e891a9117985888df3e5d48145cf07ddda098335)

Co-authored-by: Victor Stinner <[email protected]>
Co-authored-by: Gregory P. Smith <[email protected]>
Co-authored-by: Ethan Furman <[email protected]>
Co-authored-by: Kirill Podoprigora <[email protected]>
---
 Doc/c-api/init_config.rst                     |  4 +-
 Doc/library/sys.rst                           | 18 ++++
 Doc/using/cmdline.rst                         | 24 +++--
 Lib/gzip.py                                   |  5 +
 Lib/runpy.py                                  | 20 ++++
 Lib/tarfile.py                                |  4 +
 Lib/test/test_runpy.py                        | 91 +++++++++++++++++++
 Lib/test/test_sys.py                          |  9 ++
 Lib/test/test_zipfile/test_core.py            | 22 ++++-
 Lib/zipfile/__init__.py                       |  4 +
 ...-11-07-15-56-47.gh-issue-161705.OjDK2d.rst |  6 ++
 Modules/main.c                                |  4 +
 Python/pathconfig.c                           |  2 +-
 Python/sysmodule.c                            |  2 +
 14 files changed, 194 insertions(+), 21 deletions(-)
 create mode 100644 
Misc/NEWS.d/next/Security/2026-11-07-15-56-47.gh-issue-161705.OjDK2d.rst

Index: Python-3.15.2/Doc/c-api/init_config.rst
===================================================================
--- Python-3.15.2.orig/Doc/c-api/init_config.rst        2026-10-25 
17:57:51.000000000 +0100
+++ Python-3.15.2/Doc/c-api/init_config.rst     2026-11-25 20:46:11.642186343 
+0100
@@ -1206,8 +1206,8 @@
 
    .. c:member:: int safe_path
 
-      If equals to zero, ``Py_RunMain()`` prepends a potentially unsafe path to
-      :data:`sys.path` at startup:
+      If equals to zero, ``Py_RunMain()`` prepends a potentially unsafe
+      :data:`sys._path0` to :data:`sys.path` at startup:
 
       * If :c:member:`argv[0] <PyConfig.argv>` is equal to ``L"-m"``
         (``python -m module``), prepend the current working directory.
Index: Python-3.15.2/Doc/library/sys.rst
===================================================================
--- Python-3.15.2.orig/Doc/library/sys.rst      2026-10-25 17:57:51.000000000 
+0100
+++ Python-3.15.2/Doc/library/sys.rst   2026-11-25 20:46:11.643186352 +0100
@@ -1625,6 +1625,24 @@
       * Module :mod:`site` This describes how to use .pth files to
         extend :data:`sys.path`.
 
+.. data:: _path0
+
+   Path prepended to :data:`sys.path` at Python startup:
+
+   * Current directory if running a module
+     with ``python -m module`` command line.
+   * Script's directory if running a script
+     with ``python script.py``.
+   * Otherwise an empty string, which means the current working directory,
+     for ``python -c code`` or ``python`` (REPL) command line.
+
+   If :option:`-P` or :option:`-I` command line options are used or if
+   :envvar:`PYTHONSAFEPATH` environment variable is used, :data:`sys._path0` is
+   ``None`` and :data:`sys.path` is left unchanged.
+
+   .. versionadded:: next
+
+
 .. data:: path_hooks
 
     A list of callables that take a path argument to try to create a
Index: Python-3.15.2/Doc/using/cmdline.rst
===================================================================
--- Python-3.15.2.orig/Doc/using/cmdline.rst    2026-10-25 17:57:51.000000000 
+0100
+++ Python-3.15.2/Doc/using/cmdline.rst 2026-11-25 20:46:11.644186362 +0100
@@ -322,10 +322,12 @@
    Run Python in isolated mode. This also implies :option:`-E`, :option:`-P`
    and :option:`-s` options.
 
-   In isolated mode :data:`sys.path` contains neither the script's directory 
nor
-   the user's site-packages directory. All ``PYTHON*`` environment
-   variables are ignored, too. Further restrictions may be imposed to prevent
-   the user from injecting malicious code.
+   In isolated mode, Python does not prepend the potentially unsafe path
+   :data:`sys._path0` to :data:`sys.path`, and ignores all ``PYTHON*``
+   environment variables, e.g.  :envvar:`PYTHONPATH` and :envvar:`PYTHONHOME`,
+   that might be set.
+   Further restrictions may be imposed to prevent the user from injecting
+   malicious code.
 
    .. versionadded:: 3.4
 
@@ -353,14 +355,8 @@
 
 .. option:: -P
 
-   Don't prepend a potentially unsafe path to :data:`sys.path`:
-
-   * ``python -m module`` command line: Don't prepend the current working
-     directory.
-   * ``python script.py`` command line: Don't prepend the script's directory.
-     If it's a symbolic link, resolve symbolic links.
-   * ``python -c code`` and ``python`` (REPL) command lines: Don't prepend an
-     empty string, which means the current working directory.
+   Don't prepend the potentially unsafe path :data:`sys._path0` to
+   :data:`sys.path`.
 
    See also the :envvar:`PYTHONSAFEPATH` environment variable, and :option:`-E`
    and :option:`-I` (isolated) options.
@@ -820,7 +816,9 @@
 .. envvar:: PYTHONSAFEPATH
 
    If this is set to a non-empty string, don't prepend a potentially unsafe
-   path to :data:`sys.path`: see the :option:`-P` option for details.
+   path :data:`sys._path0` to :data:`sys.path`.
+
+   See also the :option:`-P` option.
 
    .. versionadded:: 3.11
 
Index: Python-3.15.2/Lib/gzip.py
===================================================================
--- Python-3.15.2.orig/Lib/gzip.py      2026-10-29 14:16:09.119278912 +0100
+++ Python-3.15.2/Lib/gzip.py   2026-11-25 20:46:11.645176150 +0100
@@ -703,6 +703,11 @@
 
 def main():
     from argparse import ArgumentParser
+    import runpy
+
+    # Prevent shadowing a stdlib module from the extracted file
+    runpy._remove_sys_path0()
+
     parser = ArgumentParser(description=
         "A simple command line interface for the `gzip` module: act like 
`gzip`, "
         "but do not delete the input file.",
Index: Python-3.15.2/Lib/runpy.py
===================================================================
--- Python-3.15.2.orig/Lib/runpy.py     2026-10-29 14:16:09.889739946 +0100
+++ Python-3.15.2/Lib/runpy.py  2026-11-25 20:46:11.645684769 +0100
@@ -315,6 +315,26 @@
                 pass
 
 
+def _remove_sys_path0():
+    """
+    Remove sys._path0 from sys.path. Do nothing if sys._path0 is
+    sys._stdlib_dir or if it has already been removed. Similar to using -P
+    (safe path) command line option.
+    """
+    path0 = sys._path0
+    if path0 is None:
+        return
+
+    if path0 == sys._stdlib_dir:
+        return
+
+    # Remove all path0 copies, not only the first one.
+    # We are intentionally not trying to normalize & match alternate
+    # representations of path0, this is only intended to remove copies
+    # of the exact value the runtime itself may have added.
+    sys.path[:] = [path for path in sys.path if path != path0]
+
+
 if __name__ == "__main__":
     # Run the module specified as the next command line argument
     if len(sys.argv) < 2:
Index: Python-3.15.2/Lib/tarfile.py
===================================================================
--- Python-3.15.2.orig/Lib/tarfile.py   2026-10-29 14:16:09.970345970 +0100
+++ Python-3.15.2/Lib/tarfile.py        2026-11-25 20:46:11.646320117 +0100
@@ -3149,6 +3149,10 @@
 
 def main():
     import argparse
+    import runpy
+
+    # Prevent shadowing stdlib modules from extracted files
+    runpy._remove_sys_path0()
 
     description = 'A simple command-line interface for tarfile module.'
     parser = argparse.ArgumentParser(description=description)
Index: Python-3.15.2/Lib/test/test_runpy.py
===================================================================
--- Python-3.15.2.orig/Lib/test/test_runpy.py   2026-10-29 14:16:13.158629948 
+0100
+++ Python-3.15.2/Lib/test/test_runpy.py        2026-11-25 20:46:11.647095970 
+0100
@@ -21,6 +21,7 @@
     verbose,
 )
 from test import support
+from test.support import os_helper
 from test.support.import_helper import forget, make_legacy_pyc, unload
 from test.support.os_helper import create_empty_file, temp_dir, FakePath
 from test.support.script_helper import make_script, make_zip_script
@@ -917,5 +918,95 @@
         self.assertSigInt(["-m", ham.stem], cwd=ham.parent)
 
 
+class MiscTests(unittest.TestCase):
+    def test_remove_sys_path0(self):
+        # Check that all path0 copies are removed
+        PATH0 = '/path/zero'
+        STDLIB_PATH = '/to/stdlib'
+        OTHER_PATH = '/other/path'
+        sys_path = [PATH0, STDLIB_PATH, PATH0, '', OTHER_PATH, PATH0]
+        expected = [STDLIB_PATH, '', OTHER_PATH]
+        with (support.swap_attr(sys, '_stdlib_dir', STDLIB_PATH),
+              support.swap_attr(sys, '_path0', PATH0),
+              support.swap_attr(sys, 'path', sys_path)):
+            runpy._remove_sys_path0()
+            self.assertEqual(sys.path, expected)
+
+            # Calling it twice does nothing
+            runpy._remove_sys_path0()
+            self.assertEqual(sys.path, expected)
+
+        # Do nothing if sys._path0 is sys._stdlib_dir
+        sys_path = ['', STDLIB_PATH, OTHER_PATH]
+        expected = sys_path.copy()
+        with (support.swap_attr(sys, '_stdlib_dir', STDLIB_PATH),
+              support.swap_attr(sys, '_path0', STDLIB_PATH),
+              support.swap_attr(sys, 'path', sys_path)):
+            runpy._remove_sys_path0()
+            self.assertEqual(sys.path, expected)
+
+        # Do nothing if sys._path0 is None
+        sys_path = ['', STDLIB_PATH, OTHER_PATH]
+        expected = sys_path.copy()
+        with (support.swap_attr(sys, '_stdlib_dir', STDLIB_PATH),
+              support.swap_attr(sys, '_path0', None),
+              support.swap_attr(sys, 'path', sys_path)):
+            runpy._remove_sys_path0()
+            self.assertEqual(sys.path, expected)
+
+    def run_python(self, *args, PYTHONPATH=None):
+        cmd = [sys.executable, *args]
+        env = support.make_clean_env()
+        if PYTHONPATH:
+            env['PYTHONPATH'] = PYTHONPATH
+        proc = subprocess.run(cmd, text=True, stderr=subprocess.PIPE, env=env)
+        self.assertEqual(proc.returncode, 0, proc.stderr)
+
+    @support.requires_subprocess()
+    def test_remove_sys_path0_run_python(self):
+        CODE = textwrap.dedent("""
+            import runpy, sys
+
+            # Remove sys.path[0]
+            orig_path = sys.path.copy()
+            path0 = sys._path0
+            runpy._remove_sys_path0()
+
+            if path0 is not None and path0 in sys.path:
+                raise Exception(f"path0 {path0!r} found in sys.path 
{sys.path!r}")
+            if not sys.flags.safe_path:
+                if sys.path == orig_path:
+                    raise Exception("sys.path was not changed")
+            else:
+                if sys.path != orig_path:
+                    raise Exception("sys.path was changed")
+
+            # Calling it twice must do nothing
+            clean_path = sys.path.copy()
+            runpy._remove_sys_path0()
+            if sys.path != clean_path:
+                raise Exception("sys.path was changed")
+        """)
+
+        # Test "python -c code"
+        self.run_python('-c', CODE)
+        self.run_python('-P', '-c', CODE)
+
+        with tempfile.TemporaryDirectory() as tmpdir:
+            name = 'test_remove_sys_path0'
+            filename = os.path.join(tmpdir, f'{name}.py')
+            with open(filename, 'w') as fp:
+                fp.write(CODE)
+
+            # Test "python script.py"
+            self.run_python(filename)
+            self.run_python('-P', filename)
+
+            with os_helper.change_cwd(tmpdir):
+                # Test "python -m module"
+                self.run_python('-m', name)
+                self.run_python('-P', '-m', name, PYTHONPATH=tmpdir)
+
+
 if __name__ == "__main__":
     unittest.main()
Index: Python-3.15.2/Lib/test/test_sys.py
===================================================================
--- Python-3.15.2.orig/Lib/test/test_sys.py     2026-10-29 14:16:13.331982904 
+0100
+++ Python-3.15.2/Lib/test/test_sys.py  2026-11-25 20:46:11.647186391 +0100
@@ -1476,6 +1476,15 @@
         self.assertFalse(is_immortal(b'abc'.decode()))
         self.assertFalse(is_immortal('abc'.encode()))
 
+    def test_path(self):
+        self.assertIsInstance(sys.path, list)
+        for path in sys.path:
+            self.assertIsInstance(path, str)
+
+    def test_path0(self):
+        self.assertTrue(sys._path0 is None or isinstance(sys._path0, str),
+                        sys._path0)
+
 
 @test.support.cpython_only
 @test.support.force_not_colorized_test_class
Index: Python-3.15.2/Lib/test/test_zipfile/test_core.py
===================================================================
--- Python-3.15.2.orig/Lib/test/test_zipfile/test_core.py       2026-10-29 
14:16:13.859990253 +0100
+++ Python-3.15.2/Lib/test/test_zipfile/test_core.py    2026-11-25 
20:46:11.649186411 +0100
@@ -54,6 +54,15 @@
         test.assertFalse(f.closed)
 
 
[email protected]
+def save_restore_sys_path():
+    old_path = sys.path.copy()
+    try:
+        yield
+    finally:
+        sys.path[:] = old_path
+
+
 class LazyImportTest(unittest.TestCase):
     @cpython_only
     def test_lazy_import(self):
@@ -3799,17 +3808,18 @@
     def test_cli_with_metadata_encoding(self):
         errmsg = "Non-conforming encodings not supported with -c."
         args = ["--metadata-encoding=shift_jis", "-c", "nonesuch", "nonesuch"]
-        with captured_stdout() as stdout:
-            with captured_stderr() as stderr:
+        with (captured_stdout() as stdout,
+              captured_stderr() as stderr,
+              save_restore_sys_path()):
                 self.assertRaises(SystemExit, zipfile.main, args)
         self.assertEqual(stdout.getvalue(), "")
         self.assertIn(errmsg, stderr.getvalue())
 
-        with captured_stdout() as stdout:
+        with captured_stdout() as stdout, save_restore_sys_path():
             zipfile.main(["--metadata-encoding=shift_jis", "-t", TESTFN])
         listing = stdout.getvalue()
 
-        with captured_stdout() as stdout:
+        with captured_stdout() as stdout, save_restore_sys_path():
             zipfile.main(["--metadata-encoding=shift_jis", "-l", TESTFN])
         listing = stdout.getvalue()
         for name in self.file_names:
@@ -3828,7 +3838,9 @@
             except UnicodeEncodeError:
                 self.skipTest(f'cannot encode file name {fn!a}')
 
-        zipfile.main(["--metadata-encoding=shift_jis", "-e", TESTFN, TESTFN2])
+        with save_restore_sys_path():
+            zipfile.main(["--metadata-encoding=shift_jis", "-e",
+                          TESTFN, TESTFN2])
         listing = os.listdir(TESTFN2)
         for name in self.file_names:
             self.assertIn(name, listing)
Index: Python-3.15.2/Lib/zipfile/__init__.py
===================================================================
--- Python-3.15.2.orig/Lib/zipfile/__init__.py  2026-10-29 14:16:14.264082155 
+0100
+++ Python-3.15.2/Lib/zipfile/__init__.py       2026-11-25 20:46:11.650361526 
+0100
@@ -2368,6 +2368,10 @@
 
 def main(args=None):
     import argparse
+    import runpy
+
+    # Prevent shadowing stdlib modules from extracted files
+    runpy._remove_sys_path0()
 
     description = 'A simple command-line interface for zipfile module.'
     parser = argparse.ArgumentParser(description=description)
Index: 
Python-3.15.2/Misc/NEWS.d/next/Security/2026-11-07-15-56-47.gh-issue-161705.OjDK2d.rst
===================================================================
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
+++ 
Python-3.15.2/Misc/NEWS.d/next/Security/2026-11-07-15-56-47.gh-issue-161705.OjDK2d.rst
      2026-11-25 20:46:11.650703641 +0100
@@ -0,0 +1,6 @@
+.. cve: CVE-2026-115791
+
+Remove ``sys.path[0]`` in :mod:`gzip`, :mod:`tarfile` and :mod:`zipfile`
+command line interface to prevent shadowing standard library modules from
+extracted files. Issue reported by Jelle Zijlstra, patch by Gregory P.
+Smith and Victor Stinner.
Index: Python-3.15.2/Modules/main.c
===================================================================
--- Python-3.15.2.orig/Modules/main.c   2026-10-25 17:57:51.000000000 +0100
+++ Python-3.15.2/Modules/main.c        2026-11-25 20:46:11.651186430 +0100
@@ -182,6 +182,10 @@
         return -1;
     }
 
+    if (PyDict_SetItemString(sysdict, "_path0", path0) < 0) {
+        return -1;
+    }
+
     if (PyList_Insert(sys_path, 0, path0)) {
         return -1;
     }
Index: Python-3.15.2/Python/pathconfig.c
===================================================================
--- Python-3.15.2.orig/Python/pathconfig.c      2026-10-25 17:57:51.000000000 
+0100
+++ Python-3.15.2/Python/pathconfig.c   2026-11-25 20:46:11.652186440 +0100
@@ -338,7 +338,7 @@
 
 
 /* Compute module search path from argv[0] or the current working
-   directory ("-m module" case) which will be prepended to sys.argv:
+   directory ("-m module" case) which will be prepended to sys.path:
    sys.path[0].
 
    Return 1 if the path is correctly resolved and written into *path0_p.
Index: Python-3.15.2/Python/sysmodule.c
===================================================================
--- Python-3.15.2.orig/Python/sysmodule.c       2026-10-25 17:57:51.000000000 
+0100
+++ Python-3.15.2/Python/sysmodule.c    2026-11-25 20:46:11.653186450 +0100
@@ -4145,6 +4145,8 @@
     SET_SYS("path_importer_cache", PyDict_New());
     SET_SYS("path_hooks", PyList_New(0));
 
+    SET_SYS("_path0", Py_None);
+
     if (_PyErr_Occurred(tstate)) {
         goto err_occurred;
     }

++++++ CVE-2026-124249-cookiejar-delete-expired.patch ++++++
>From 236e6ef1fdd7b7de14450e4a4f6097bde4a1d25f Mon Sep 17 00:00:00 2001
From: Kirill Podoprigora <[email protected]>
Date: Sat, 7 Nov 2026 21:53:13 +0200
Subject: [PATCH] gh-161569: Check cookie policy before deleting expired
 cookies in `http.cookiejar` (GH-161570)

gh-161569: Check cookie policy before deleting expired cookies in http.cookiejar

An expired Set-Cookie header was allowed to delete a stored cookie using
the Domain and Path attributes taken verbatim from the header, before
CookiePolicy.set_ok() was consulted. A response from one host could
therefore delete cookies belonging to any other domain in a shared jar.

The policy is now consulted before an expired cookie may delete an
existing one, as required by RFC 6265 section 5.3.
(cherry picked from commit 8eb3d2c1c41ca7ce628554413981c1eb763a1494)

Co-authored-by: Kirill Podoprigora <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
---
 Lib/http/cookiejar.py                         | 45 +++++++++--------
 Lib/test/test_http_cookiejar.py               | 49 +++++++++++++++++++
 ...11-07-01-43-49.gh-issue-161569.cookiej.rst |  7 +++
 3 files changed, 81 insertions(+), 20 deletions(-)
 create mode 100644 
Misc/NEWS.d/next/Security/2026-11-07-01-43-49.gh-issue-161569.cookiej.rst

Index: Python-3.15.2/Lib/http/cookiejar.py
===================================================================
--- Python-3.15.2.orig/Lib/http/cookiejar.py    2026-10-29 14:16:09.143015146 
+0100
+++ Python-3.15.2/Lib/http/cookiejar.py 2026-11-25 20:42:48.708888816 +0100
@@ -1568,28 +1568,33 @@
         if expires is Absent:
             expires = None
             discard = True
-        elif expires <= self._now:
-            # Expiry date in past is request to delete cookie.  This can't be
-            # in DefaultCookiePolicy, because can't delete cookies there.
-            try:
-                self.clear(domain, path, name)
-            except KeyError:
-                pass
-            _debug("Expiring cookie, domain='%s', path='%s', name='%s'",
-                   domain, path, name)
+
+        cookie = Cookie(version,
+                        name, value,
+                        port, port_specified,
+                        domain, domain_specified, domain_initial_dot,
+                        path, path_specified,
+                        secure,
+                        expires,
+                        discard,
+                        comment,
+                        comment_url,
+                        rest)
+
+        if expires is not None and expires <= self._now:
+            # RFC 6265 section 5.3 ignores the cookie entirely if its Domain
+            # attribute does not match the request host (step 6) before an
+            # existing cookie is removed (steps 11-12)
+            if self._policy.set_ok(cookie, request):
+                try:
+                    self.clear(domain, path, name)
+                except KeyError:
+                    pass
+                _debug("Expiring cookie, domain='%s', path='%s', name='%s'",
+                       domain, path, name)
             return None
 
-        return Cookie(version,
-                      name, value,
-                      port, port_specified,
-                      domain, domain_specified, domain_initial_dot,
-                      path, path_specified,
-                      secure,
-                      expires,
-                      discard,
-                      comment,
-                      comment_url,
-                      rest)
+        return cookie
 
     def _cookies_from_attrs_set(self, attrs_set, request):
         cookie_tuples = self._normalized_cookie_tuples(attrs_set)
Index: Python-3.15.2/Lib/test/test_http_cookiejar.py
===================================================================
--- Python-3.15.2.orig/Lib/test/test_http_cookiejar.py  2026-10-29 
14:16:11.931732723 +0100
+++ Python-3.15.2/Lib/test/test_http_cookiejar.py       2026-11-25 
20:42:48.709888827 +0100
@@ -743,6 +743,55 @@
 
         # XXX RFC 2965 expiry rules (some apply to V0 too)
 
+    def test_expired_cookie_from_other_domain_is_ignored(self):
+        c = CookieJar()
+        interact_netscape(c, "http://www.victim.test/";,
+                          'session=secret; Domain=.victim.test; Path=/')
+
+        for domain in ('.victim.test', 'victim.test'):
+            for expires in (
+                'Max-Age=0',
+                'Expires=Thu, 01 Jan 1970 00:00:00 GMT',
+            ):
+                hdr = f'session=x; Domain={domain}; Path=/; {expires}'
+                with self.subTest(hdr=hdr):
+                    interact_netscape(c, "http://www.attacker.test/";, hdr)
+                    self.assertEqual(len(c), 1)
+                    self.assertIn(
+                        'session=secret',
+                        interact_netscape(c, "http://www.victim.test/";))
+
+        interact_netscape(c, "http://www.victim.test/";,
+                          'session=x; Domain=.victim.test; Path=/; Max-Age=0')
+        self.assertEqual(len(c), 0)
+
+    def test_expired_cookie_from_other_path_is_ignored(self):
+        pol = DefaultCookiePolicy(strict_ns_set_path=True)
+        c = CookieJar(pol)
+        interact_netscape(c, "http://www.acme.com/a/";,
+                          'token=secret; Path=/a')
+        self.assertEqual(len(c), 1)
+        interact_netscape(c, "http://www.acme.com/b/";,
+                          'token=x; Path=/a; Max-Age=0')
+        self.assertEqual(len(c), 1)
+        interact_netscape(c, "http://www.acme.com/a/";,
+                          'token=x; Path=/a; Max-Age=0')
+        self.assertEqual(len(c), 0)
+
+    def test_expired_cookie_for_blocked_domain_is_ignored(self):
+        c = CookieJar()
+        interact_netscape(c, "http://www.victim.test/";,
+                          'session=secret; Domain=.victim.test; Path=/')
+        self.assertEqual(len(c), 1)
+        c.set_policy(DefaultCookiePolicy(blocked_domains=[".victim.test"]))
+        interact_netscape(c, "http://www.victim.test/";,
+                          'session=x; Domain=.victim.test; Path=/; Max-Age=0')
+        self.assertEqual(len(c), 1)
+        c.set_policy(DefaultCookiePolicy())
+        interact_netscape(c, "http://www.victim.test/";,
+                          'session=x; Domain=.victim.test; Path=/; Max-Age=0')
+        self.assertEqual(len(c), 0)
+
     def test_default_path(self):
         # RFC 2965
         pol = DefaultCookiePolicy(rfc2965=True)
Index: 
Python-3.15.2/Misc/NEWS.d/next/Security/2026-11-07-01-43-49.gh-issue-161569.cookiej.rst
===================================================================
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
+++ 
Python-3.15.2/Misc/NEWS.d/next/Security/2026-11-07-01-43-49.gh-issue-161569.cookiej.rst
     2026-11-25 20:42:48.710951064 +0100
@@ -0,0 +1,7 @@
+.. cve: CVE-2026-124249
+
+Fix :class:`http.cookiejar.CookieJar` deleting a stored cookie when a
+response from an unrelated host sets an already expired cookie with a
+``Domain`` or ``Path`` attribute pointing at that cookie. The cookie policy
+is now consulted before an expired cookie is allowed to delete an existing
+one.

++++++ CVE-2026-16052-cookie-semicolon-attributes.patch ++++++
>From b13485485937ad453ae93dd611c0fac5f45e59d8 Mon Sep 17 00:00:00 2001
From: Brett Smith <[email protected]>
Date: Thu, 12 Nov 2026 10:50:42 -0500
Subject: [PATCH] gh-161707: Refuse `;` in all cookie attributes except Comment
 (cherry picked from commit 27026842f6774c167295f4b59972589f12ec5987)

Co-authored-by: Brett Smith <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
---
 Doc/library/http.cookies.rst                  | 13 +++++++
 Lib/http/cookies.py                           | 38 +++++++++++--------
 Lib/test/test_http_cookies.py                 | 24 ++++++++++++
 ...-11-09-17-19-29.gh-issue-161707.xWzwqQ.rst |  5 +++
 4 files changed, 64 insertions(+), 16 deletions(-)
 create mode 100644 
Misc/NEWS.d/next/Security/2026-11-09-17-19-29.gh-issue-161707.xWzwqQ.rst

Index: Python-3.15.2/Doc/library/http.cookies.rst
===================================================================
--- Python-3.15.2.orig/Doc/library/http.cookies.rst     2026-10-25 
17:57:51.000000000 +0100
+++ Python-3.15.2/Doc/library/http.cookies.rst  2026-11-25 20:44:30.300073731 
+0100
@@ -188,6 +188,11 @@
    .. versionchanged:: 3.14
       Added support for the :attr:`partitioned` attribute.
 
+   .. versionchanged:: next
+      :meth:`!__setitem__` and :meth:`!__ior__` now raise :exc:`CookieError` if
+      a value string for any attribute except :attr:`comment` contains the
+      reserved separator character ``;``. (If :attr:`comment` contains ``;``
+      it will be escaped in the output.)
 
 .. attribute:: Morsel.value
 
@@ -253,6 +258,10 @@
    .. versionchanged:: 3.5
       an error is raised for invalid keys.
 
+   .. versionchanged:: next
+      :exc:`CookieError` is now raised if a value string for any attribute
+      except :attr:`comment` contains the reserved separator character ``;``.
+      (If :attr:`comment` contains ``;`` it will be escaped in the output.)
 
 .. method:: Morsel.copy(value)
 
@@ -267,6 +276,10 @@
    Raise an error if key is not a valid :rfc:`2109` attribute, otherwise
    behave the same as :meth:`dict.setdefault`.
 
+   .. versionchanged:: next
+      :exc:`CookieError` is now raised if the value string for any attribute
+      except :attr:`comment` contains the reserved separator character ``;``.
+      (If :attr:`comment` contains ``;`` it will be escaped in the output.)
 
 .. _cookie-example:
 
Index: Python-3.15.2/Lib/http/cookies.py
===================================================================
--- Python-3.15.2.orig/Lib/http/cookies.py      2026-10-29 14:16:09.146039136 
+0100
+++ Python-3.15.2/Lib/http/cookies.py   2026-11-25 20:44:30.301160036 +0100
@@ -300,20 +300,31 @@
     def coded_value(self):
         return self._coded_value
 
+    def _check_attribute(self, key, val):
+        """Normalize and validate an attribute name and value
+
+        Raise `CookieError` if the key is not a recognized attribute name or
+        value contains illegal characters. Otherwise return the canonicalized
+        key.
+        """
+        key = key.lower()
+        val_str = str(val)
+        if key not in self._reserved:
+            raise CookieError(f"Invalid attribute {key!r}")
+        if _has_control_character(key, val_str):
+            raise CookieError(f"Control characters are not allowed in cookies 
{key!r} {val!r}")
+        # Comment is quoted like a cookie value so semicolons can be escaped.
+        # No other attribute expects `;` in the value, so refuse it.
+        if key != 'comment' and ';' in val_str:
+            raise CookieError(f"Reserved character ';' is not allowed in 
cookie attribute value {key!r} {val!r}")
+        return key
+
     def __setitem__(self, K, V):
-        K = K.lower()
-        if not K in self._reserved:
-            raise CookieError("Invalid attribute %r" % (K,))
-        if _has_control_character(K, V):
-            raise CookieError(f"Control characters are not allowed in cookies 
{K!r} {V!r}")
+        K = self._check_attribute(K, V)
         dict.__setitem__(self, K, V)
 
     def setdefault(self, key, val=None):
-        key = key.lower()
-        if key not in self._reserved:
-            raise CookieError("Invalid attribute %r" % (key,))
-        if _has_control_character(key, val):
-            raise CookieError("Control characters are not allowed in cookies 
%r %r" % (key, val,))
+        key = self._check_attribute(key, val)
         return dict.setdefault(self, key, val)
 
     def __eq__(self, morsel):
@@ -335,12 +346,7 @@
     def update(self, values):
         data = {}
         for key, val in dict(values).items():
-            key = key.lower()
-            if key not in self._reserved:
-                raise CookieError("Invalid attribute %r" % (key,))
-            if _has_control_character(key, val):
-                raise CookieError("Control characters are not allowed in "
-                                  f"cookies {key!r} {val!r}")
+            key = self._check_attribute(key, val)
             data[key] = val
         dict.update(self, data)
 
Index: Python-3.15.2/Lib/test/test_http_cookies.py
===================================================================
--- Python-3.15.2.orig/Lib/test/test_http_cookies.py    2026-10-29 
14:16:11.934458151 +0100
+++ Python-3.15.2/Lib/test/test_http_cookies.py 2026-11-25 20:44:30.301701869 
+0100
@@ -628,6 +628,30 @@
             with self.assertRaises(cookies.CookieError):
                 morsel |= {c0: "val"}
 
+    def test_no_semicolons_in_attribute_values(self):
+        for attrkey, attrname in cookies.Morsel._reserved.items():
+            if attrname == "Comment":
+                continue
+            with self.subTest(attrkey=attrkey, attrname=attrname):
+                morsel = cookies.Morsel()
+                with self.assertRaises(cookies.CookieError):
+                    morsel[attrkey] = "foo; SameSite=none"
+                with self.assertRaises(cookies.CookieError):
+                    morsel.setdefault(attrkey, "foo; SameSite=none")
+                with self.assertRaises(cookies.CookieError):
+                    morsel.update({attrkey: "foo; SameSite=none"})
+                with self.assertRaises(cookies.CookieError):
+                    morsel |= {attrkey: "foo; SameSite=none"}
+
+    def test_semicolon_escaped_in_comment(self):
+        morsel = cookies.Morsel()
+        morsel.set("key", "value", "coded")
+        morsel["comment"] = "foo;SameSite=none;Domain=example.com"
+        self.assertEqual(
+            morsel.OutputString(),
+            r'key=coded; Comment="foo\073SameSite=none\073Domain=example.com"',
+        )
+
     def test_control_characters_output(self):
         # Tests that even if the internals of Morsel are modified
         # that a call to .output() has control character safeguards.
Index: 
Python-3.15.2/Misc/NEWS.d/next/Security/2026-11-09-17-19-29.gh-issue-161707.xWzwqQ.rst
===================================================================
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
+++ 
Python-3.15.2/Misc/NEWS.d/next/Security/2026-11-09-17-19-29.gh-issue-161707.xWzwqQ.rst
      2026-11-25 20:44:30.301925531 +0100
@@ -0,0 +1,5 @@
+.. cve: CVE-2026-16052
+
+:mod:`http.cookies` now raises :exc:`~http.cookies.CookieError` on any attempt
+to set a value string that contains the reserved separator character ``;`` to
+any attribute except :attr:`~http.cookies.Morsel.comment`.

++++++ CVE-2026-19552-ssl-get_server_certificate-hostname.patch ++++++
>From b1ee4ce2110ffbdc1ff78eeeab44141c7aa23f39 Mon Sep 17 00:00:00 2001
From: Brett Smith <[email protected]>
Date: Sat, 7 Nov 2026 14:07:53 -0500
Subject: [PATCH] gh-161503: Check hostname in `ssl.get_server_certificate`
 with custom `ca_certs` (GH-161507) (cherry picked from commit
 8dde46eaa6baf5f027a7234845b20d50b509624e)

Co-authored-by: Brett Smith <[email protected]>
---
 Doc/library/ssl.rst                                       | 8 +++++++-
 Lib/ssl.py                                                | 4 +++-
 Lib/test/test_ssl.py                                      | 8 ++++++--
 .../2026-11-06-16-22-47.gh-issue-161503.FkIl87.rst        | 4 ++++
 4 files changed, 20 insertions(+), 4 deletions(-)
 create mode 100644 
Misc/NEWS.d/next/Security/2026-11-06-16-22-47.gh-issue-161503.FkIl87.rst

Index: Python-3.15.2/Doc/library/ssl.rst
===================================================================
--- Python-3.15.2.orig/Doc/library/ssl.rst      2026-11-19 14:13:39.811185210 
+0100
+++ Python-3.15.2/Doc/library/ssl.rst   2026-11-25 20:45:22.800686074 +0100
@@ -410,7 +410,8 @@
    same format as used for the *cafile* parameter in
    :meth:`SSLContext.load_verify_locations`.  The call will attempt to 
validate the
    server certificate against that set of root certificates, and will fail
-   if the validation attempt fails.  A timeout can be specified with the
+   if the validation attempt fails or the certificate hostname does not match
+   the server hostname.  A timeout can be specified with the
    ``timeout`` parameter.
 
    .. versionchanged:: 3.3
@@ -423,6 +424,11 @@
    .. versionchanged:: 3.10
       The *timeout* parameter was added.
 
+   .. versionchanged:: next
+      The function now raises :exc:`SSLCertVerificationError` if *ca_certs* is
+      specified but the certificate hostname does not match the server
+      hostname.
+
 .. function:: DER_cert_to_PEM_cert(der_cert_bytes)
 
    Given a certificate as a DER-encoded blob of bytes, returns a PEM-encoded
Index: Python-3.15.2/Lib/ssl.py
===================================================================
--- Python-3.15.2.orig/Lib/ssl.py       2026-11-19 14:13:39.811185210 +0100
+++ Python-3.15.2/Lib/ssl.py    2026-11-25 20:45:22.803289089 +0100
@@ -1566,7 +1566,8 @@
                            ca_certs=None, timeout=_GLOBAL_DEFAULT_TIMEOUT):
     """Retrieve the certificate from the server at the specified address,
     and return it as a PEM-encoded string.
-    If 'ca_certs' is specified, validate the server cert against it.
+    If 'ca_certs' is specified, validate the server cert against it and
+    check that it matches the hostname.
     If 'ssl_version' is specified, use it in the connection attempt.
     If 'timeout' is specified, use it in the connection attempt.
     """
@@ -1578,6 +1579,7 @@
         cert_reqs = CERT_NONE
     context = _create_stdlib_context(ssl_version,
                                      cert_reqs=cert_reqs,
+                                     check_hostname=ca_certs is not None,
                                      cafile=ca_certs)
     with create_connection(addr, timeout=timeout) as sock:
         with context.wrap_socket(sock, server_hostname=host) as sslsock:
Index: Python-3.15.2/Lib/test/test_ssl.py
===================================================================
--- Python-3.15.2.orig/Lib/test/test_ssl.py     2026-11-19 14:13:39.811185210 
+0100
+++ Python-3.15.2/Lib/test/test_ssl.py  2026-11-25 20:45:22.804686121 +0100
@@ -2617,6 +2617,10 @@
         # independent test method
         _test_get_server_certificate_fail(self, *self.server_addr)
 
+    def test_get_server_certificate_fail_by_hostname(self):
+        _, port = self.server_addr
+        _test_get_server_certificate_fail(self, socket_helper.HOSTv4, port, 
SIGNING_CA)
+
     def test_get_server_certificate_timeout(self):
         def servername_cb(ssl_sock, server_name, initial_context):
             time.sleep(0.2)
@@ -2869,10 +2873,10 @@
     if support.verbose:
         sys.stdout.write("\nVerified certificate for %s:%s is\n%s\n" % (host, 
port ,pem))
 
-def _test_get_server_certificate_fail(test, host, port):
+def _test_get_server_certificate_fail(test, host, port, ca_certs=CERTFILE):
     with warnings_helper.check_no_resource_warning(test):
         try:
-            pem = ssl.get_server_certificate((host, port), ca_certs=CERTFILE)
+            pem = ssl.get_server_certificate((host, port), ca_certs=ca_certs)
         except ssl.SSLError as x:
             #should fail
             if support.verbose:
Index: 
Python-3.15.2/Misc/NEWS.d/next/Security/2026-11-06-16-22-47.gh-issue-161503.FkIl87.rst
===================================================================
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
+++ 
Python-3.15.2/Misc/NEWS.d/next/Security/2026-11-06-16-22-47.gh-issue-161503.FkIl87.rst
      2026-11-25 20:45:22.806513304 +0100
@@ -0,0 +1,4 @@
+.. cve: CVE-2026-19552
+
+:func:`ssl.get_server_certificate` now verifies that the server hostname 
matches
+its certificate when the caller specifies *ca_certs*.

++++++ _scmsync.obsinfo ++++++
--- /var/tmp/diff_new_pack.MWVLSC/_old  2026-11-30 14:30:41.116768231 +0100
+++ /var/tmp/diff_new_pack.MWVLSC/_new  2026-11-30 14:30:41.128768736 +0100
@@ -1,6 +1,6 @@
-mtime: 1795436984
-commit: 0e6e75c8660629a964dfb4c473b165396d2a9d21a6ff2ec238d20e4ac5e316bb
+mtime: 1795636001
+commit: 1a587d727dbf71c96992356bd2256e6bbf2f5388410448e6135ad4446d62335f
 url: https://src.opensuse.org/python-interpreters/python315
-revision: 0e6e75c8660629a964dfb4c473b165396d2a9d21a6ff2ec238d20e4ac5e316bb
+revision: 1a587d727dbf71c96992356bd2256e6bbf2f5388410448e6135ad4446d62335f
 projectscmsync: https://src.opensuse.org/python-interpreters/_ObsPrj
 

++++++ build.specials.obscpio ++++++

++++++ build.specials.obscpio ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/.gitignore new/.gitignore
--- old/.gitignore      1970-01-01 01:00:00.000000000 +0100
+++ new/.gitignore      2026-11-25 20:46:41.000000000 +0100
@@ -0,0 +1,5 @@
+*.obscpio
+*.osc
+_build.*
+.pbuild
+python315-*-build/

Reply via email to