diff --git a/CVE-2023-46136.patch b/CVE-2023-46136.patch new file mode 100644 index 0000000000000000000000000000000000000000..ec88becfebbe660c0a0cf12cd2b028b5478e98bf --- /dev/null +++ b/CVE-2023-46136.patch @@ -0,0 +1,38 @@ +From: =?utf-8?q?Pawe=C5=82_Srokosz?= +Date: Thu, 12 Oct 2023 18:50:04 +0200 +Subject: Fix: slow multipart parsing for huge files with few CR/LF characters + +(cherry picked from commit b1916c0c083e0be1c9d887ee2f3d696922bfc5c1) +--- + src/werkzeug/sansio/multipart.py | 10 +++++++++- + 1 file changed, 9 insertions(+), 1 deletion(-) + +diff --git a/src/werkzeug/sansio/multipart.py b/src/werkzeug/sansio/multipart.py +index a20fa87..2c3cab5 100644 +--- a/src/werkzeug/sansio/multipart.py ++++ b/src/werkzeug/sansio/multipart.py +@@ -188,12 +188,20 @@ class MultipartDecoder: + if self.max_parts is not None and self._parts_decoded > self.max_parts: + raise RequestEntityTooLarge() + elif self.state == State.DATA: +- if self.buffer.find(b"--" + self.boundary) == -1: ++ boundary = b"--" + self.boundary ++ ++ if self.buffer.find(boundary) == -1: + # No complete boundary in the buffer, but there may be + # a partial boundary at the end. As the boundary + # starts with either a nl or cr find the earliest and + # return up to that as data. + data_length = del_index = self.last_newline() ++ # If amount of data after last newline is far from ++ # possible length of partial boundary, we should ++ # assume that there is no partial boundary in the buffer ++ # and return all pending data. ++ if (len(self.buffer) - data_length) > len(b"\n" + boundary): ++ data_length = del_index = len(self.buffer) + more_data = True + else: + match = self.boundary_re.search(self.buffer) +-- +2.33.0 + diff --git a/CVE-2024-34069-1.patch b/CVE-2024-34069-1.patch new file mode 100644 index 0000000000000000000000000000000000000000..f600400cb5e35b18d7de222f18d1fdb37522666c --- /dev/null +++ b/CVE-2024-34069-1.patch @@ -0,0 +1,146 @@ +From: David Lord +Date: Thu, 2 May 2024 11:55:52 -0700 +Subject: restrict debugger trusted hosts + +Add a list of `trusted_hosts` to the `DebuggedApplication` middleware. It defaults to only allowing `localhost`, `.localhost` subdomains, and `127.0.0.1`. `run_simple(use_debugger=True)` adds its `hostname` argument to the trusted list as well. The middleware can be used directly to further modify the trusted list in less common development scenarios. + +The debugger UI uses the full `document.location` instead of only `document.location.pathname`. + +Either of these fixes on their own mitigates the reported vulnerability. + +(cherry picked from commit 71b69dfb7df3d912e66bab87fbb1f21f83504967) +--- + docs/debug.rst | 35 +++++++++++++++++++++++---- + src/werkzeug/debug/__init__.py | 10 ++++++++ + src/werkzeug/debug/shared/debugger.js | 4 +-- + src/werkzeug/serving.py | 4 +++ + 4 files changed, 46 insertions(+), 7 deletions(-) + +diff --git a/docs/debug.rst b/docs/debug.rst +index 25a9f0b..d842135 100644 +--- a/docs/debug.rst ++++ b/docs/debug.rst +@@ -16,7 +16,8 @@ interactive debug console to execute code in any frame. + The debugger allows the execution of arbitrary code which makes it a + major security risk. **The debugger must never be used on production + machines. We cannot stress this enough. Do not enable the debugger +- in production.** ++ in production.** Production means anything that is not development, ++ and anything that is publicly accessible. + + .. note:: + +@@ -72,10 +73,9 @@ argument to get a detailed list of all the attributes it has. + Debugger PIN + ------------ + +-Starting with Werkzeug 0.11 the debug console is protected by a PIN. +-This is a security helper to make it less likely for the debugger to be +-exploited if you forget to disable it when deploying to production. The +-PIN based authentication is enabled by default. ++The debug console is protected by a PIN. This is a security helper to make it ++less likely for the debugger to be exploited if you forget to disable it when ++deploying to production. The PIN based authentication is enabled by default. + + The first time a console is opened, a dialog will prompt for a PIN that + is printed to the command line. The PIN is generated in a stable way +@@ -92,6 +92,31 @@ intended to make it harder for an attacker to exploit the debugger. + Never enable the debugger in production.** + + ++Allowed Hosts ++------------- ++ ++The debug console will only be served if the request comes from a trusted host. ++If a request comes from a browser page that is not served on a trusted URL, a ++400 error will be returned. ++ ++By default, ``localhost``, any ``.localhost`` subdomain, and ``127.0.0.1`` are ++trusted. ``run_simple`` will trust its ``hostname`` argument as well. To change ++this further, use the debug middleware directly rather than through ++``use_debugger=True``. ++ ++.. code-block:: python ++ ++ if os.environ.get("USE_DEBUGGER") in {"1", "true"}: ++ app = DebuggedApplication(app, evalex=True) ++ app.trusted_hosts = [...] ++ ++ run_simple("localhost", 8080, app) ++ ++**This feature is not meant to entirely secure the debugger. It is ++intended to make it harder for an attacker to exploit the debugger. ++Never enable the debugger in production.** ++ ++ + Pasting Errors + -------------- + +diff --git a/src/werkzeug/debug/__init__.py b/src/werkzeug/debug/__init__.py +index dbbe965..675c3f9 100644 +--- a/src/werkzeug/debug/__init__.py ++++ b/src/werkzeug/debug/__init__.py +@@ -279,6 +279,14 @@ class DebuggedApplication: + else: + self.pin = None + ++ self.trusted_hosts: list[str] = [".localhost", "127.0.0.1"] ++ """List of domains to allow requests to the debugger from. A leading dot ++ allows all subdomains. This only allows ``".localhost"`` domains by ++ default. ++ ++ .. versionadded:: 3.0.3 ++ """ ++ + @property + def pin(self) -> t.Optional[str]: + if not hasattr(self, "_pin"): +@@ -471,6 +479,8 @@ class DebuggedApplication: + # form data! Otherwise the application won't have access to that data + # any more! + request = Request(environ) ++ request.trusted_hosts = self.trusted_hosts ++ assert request.host # will raise 400 error if not trusted + response = self.debug_application + if request.args.get("__debugger__") == "yes": + cmd = request.args.get("cmd") +diff --git a/src/werkzeug/debug/shared/debugger.js b/src/werkzeug/debug/shared/debugger.js +index 2354f03..bee079f 100644 +--- a/src/werkzeug/debug/shared/debugger.js ++++ b/src/werkzeug/debug/shared/debugger.js +@@ -48,7 +48,7 @@ function initPinBox() { + btn.disabled = true; + + fetch( +- `${document.location.pathname}?__debugger__=yes&cmd=pinauth&pin=${pin}&s=${encodedSecret}` ++ `${document.location}?__debugger__=yes&cmd=pinauth&pin=${pin}&s=${encodedSecret}` + ) + .then((res) => res.json()) + .then(({auth, exhausted}) => { +@@ -79,7 +79,7 @@ function promptForPin() { + if (!EVALEX_TRUSTED) { + const encodedSecret = encodeURIComponent(SECRET); + fetch( +- `${document.location.pathname}?__debugger__=yes&cmd=printpin&s=${encodedSecret}` ++ `${document.location}?__debugger__=yes&cmd=printpin&s=${encodedSecret}` + ); + const pinPrompt = document.getElementsByClassName("pin-prompt")[0]; + fadeIn(pinPrompt); +diff --git a/src/werkzeug/serving.py b/src/werkzeug/serving.py +index 80e4192..7a6549b 100644 +--- a/src/werkzeug/serving.py ++++ b/src/werkzeug/serving.py +@@ -914,6 +914,10 @@ def run_simple( + from .debug import DebuggedApplication + + application = DebuggedApplication(application, use_evalex) ++ # Allow the specified hostname to use the debugger, in addition to ++ # localhost domains. ++ application.trusted_hosts.append(hostname) ++ + if static_files: + from .middleware.shared_data import SharedDataMiddleware + +-- +2.33.0 + diff --git a/CVE-2024-34069-2.patch b/CVE-2024-34069-2.patch new file mode 100644 index 0000000000000000000000000000000000000000..26b88bf96839c7ea1c3bbde534381925f6997f85 --- /dev/null +++ b/CVE-2024-34069-2.patch @@ -0,0 +1,117 @@ +From: David Lord +Date: Fri, 3 May 2024 14:49:43 -0700 +Subject: only require trusted host for evalex + +(cherry picked from commit 890b6b62634fa61224222aee31081c61b054ff01) +--- + src/werkzeug/debug/__init__.py | 26 +++++++++++++++++++++----- + src/werkzeug/sansio/utils.py | 2 +- + 2 files changed, 22 insertions(+), 6 deletions(-) + +diff --git a/src/werkzeug/debug/__init__.py b/src/werkzeug/debug/__init__.py +index 675c3f9..1073698 100644 +--- a/src/werkzeug/debug/__init__.py ++++ b/src/werkzeug/debug/__init__.py +@@ -14,7 +14,9 @@ from os.path import basename + from os.path import join + + from .._internal import _log ++from ..exceptions import SecurityError + from ..http import parse_cookie ++from ..sansio.utils import host_is_trusted + from ..security import gen_salt + from ..wrappers.request import Request + from ..wrappers.response import Response +@@ -351,7 +353,8 @@ class DebuggedApplication: + else: + is_trusted = bool(self.check_pin_trust(environ)) + yield traceback.render_full( +- evalex=self.evalex, evalex_trusted=is_trusted, secret=self.secret ++ evalex=self.evalex and self.check_host_trust(environ), ++ evalex_trusted=is_trusted, secret=self.secret + ).encode("utf-8", "replace") + + traceback.log(environ["wsgi.errors"]) +@@ -360,10 +363,16 @@ class DebuggedApplication: + self, request: Request, command: str, frame: t.Union[Frame, _ConsoleFrame] + ) -> Response: + """Execute a command in a console.""" ++ if not self.check_host_trust(request.environ): ++ return SecurityError() # type: ignore[return-value] ++ + return Response(frame.console.eval(command), mimetype="text/html") + + def display_console(self, request: Request) -> Response: + """Display a standalone shell.""" ++ if not self.check_host_trust(request.environ): ++ return SecurityError() # type: ignore[return-value] ++ + if 0 not in self.frames: + if self.console_init_func is None: + ns = {} +@@ -407,12 +416,18 @@ class DebuggedApplication: + return None + return (time.time() - PIN_TIME) < int(ts) + ++ def check_host_trust(self, environ: "WSGIEnvironment") -> t.Optional[bool]: ++ return host_is_trusted(environ.get("HTTP_HOST"), self.trusted_hosts) ++ + def _fail_pin_auth(self) -> None: + time.sleep(5.0 if self._failed_pin_auth > 5 else 0.5) + self._failed_pin_auth += 1 + + def pin_auth(self, request: Request) -> Response: + """Authenticates with the pin.""" ++ if not self.check_host_trust(request.environ): ++ return SecurityError() # type: ignore[return-value] ++ + exhausted = False + auth = False + trust = self.check_pin_trust(request.environ) +@@ -462,8 +477,11 @@ class DebuggedApplication: + rv.delete_cookie(self.pin_cookie_name) + return rv + +- def log_pin_request(self) -> Response: ++ def log_pin_request(self, request: Request) -> Response: + """Log the pin if needed.""" ++ if not self.check_host_trust(request.environ): ++ return SecurityError() # type: ignore[return-value] ++ + if self.pin_logging and self.pin is not None: + _log( + "info", " * To enable the debugger you need to enter the security pin:" +@@ -479,8 +497,6 @@ class DebuggedApplication: + # form data! Otherwise the application won't have access to that data + # any more! + request = Request(environ) +- request.trusted_hosts = self.trusted_hosts +- assert request.host # will raise 400 error if not trusted + response = self.debug_application + if request.args.get("__debugger__") == "yes": + cmd = request.args.get("cmd") +@@ -492,7 +508,7 @@ class DebuggedApplication: + elif cmd == "pinauth" and secret == self.secret: + response = self.pin_auth(request) # type: ignore + elif cmd == "printpin" and secret == self.secret: +- response = self.log_pin_request() # type: ignore ++ response = self.log_pin_request(request) # type: ignore + elif ( + self.evalex + and cmd is not None +diff --git a/src/werkzeug/sansio/utils.py b/src/werkzeug/sansio/utils.py +index 1b4d892..73a307d 100644 +--- a/src/werkzeug/sansio/utils.py ++++ b/src/werkzeug/sansio/utils.py +@@ -6,7 +6,7 @@ from ..urls import uri_to_iri + from ..urls import url_quote + + +-def host_is_trusted(hostname: str, trusted_list: t.Iterable[str]) -> bool: ++def host_is_trusted(hostname: t.Optional[str], trusted_list: t.Iterable[str]) -> bool: + """Check if a host matches a list of trusted names. + + :param hostname: The name to check. +-- +2.33.0 + diff --git a/python-werkzeug.spec b/python-werkzeug.spec index 17e4f1535efb23d8bcd723913e386c9410783732..8e82d94d245fc3090597a6823bc3092e9ddaec6f 100644 --- a/python-werkzeug.spec +++ b/python-werkzeug.spec @@ -1,7 +1,7 @@ %global _empty_manifest_terminate_build 0 Name: python-werkzeug Version: 2.0.3 -Release: 5 +Release: 6 Summary: The comprehensive WSGI web application library. License: BSD-3-Clause URL: https://palletsprojects.com/p/werkzeug/ @@ -12,6 +12,9 @@ Patch0002: backport-fix-flake8-bugbear-finding.patch Patch0003: CVE-2023-23934.patch Patch0004: CVE-2023-25577.patch Patch0005: CVE-2024-49767--apply-max_form_memory_size-another-level-up.patch +Patch0006: CVE-2023-46136.patch +Patch0007: CVE-2024-34069-1.patch +Patch0008: CVE-2024-34069-2.patch BuildArch: noarch BuildRequires: python3-werkzeug @@ -181,6 +184,9 @@ export PYTHONPATH=$PYTHONPATH:$depath %{_docdir}/* %changelog +* Thu Jul 31 2025 yaoxin <1024769339@qq.com> - 2.0.3-6 +- Fix CVE-2023-46136 and CVE-2024-34069 + * Tue Nov 12 2024 liningjie - 2.0.3-5 - Fix CVE-2024-49767