details:   https://code.tryton.org/tryton/commit/53b58829d26b
branch:    7.0
user:      Cédric Krier <[email protected]>
date:      Sat Nov 21 18:13:00 2026 +0100
description:
        Limit the decompressed size of request

        Closes #15257
        (grafted from e592ed66d339edf8ff2d6d970ab08ea74a0f524b)
diffstat:

 trytond/CHANGELOG                     |   1 +
 trytond/trytond/protocols/wrappers.py |  15 ++++++++-------
 trytond/trytond/wsgi.py               |   1 +
 3 files changed, 10 insertions(+), 7 deletions(-)

diffs (61 lines):

diff -r 906d6cc6f548 -r 53b58829d26b trytond/CHANGELOG
--- a/trytond/CHANGELOG Sat Nov 21 15:24:53 2026 +0100
+++ b/trytond/CHANGELOG Sat Nov 21 18:13:00 2026 +0100
@@ -1,3 +1,4 @@
+* Limit the decompressed size of request (issue15257)
 * Define the forbidden fields that cannot be set as preferences (issue15256)
 
 Version 7.0.61 - 2026-11-06
diff -r 906d6cc6f548 -r 53b58829d26b trytond/trytond/protocols/wrappers.py
--- a/trytond/trytond/protocols/wrappers.py     Sat Nov 21 15:24:53 2026 +0100
+++ b/trytond/trytond/protocols/wrappers.py     Sat Nov 21 18:13:00 2026 +0100
@@ -2,10 +2,10 @@
 # this repository contains the full copyright notices and license terms.
 import base64
 import gzip
+import io
 import logging
 import time
 from functools import wraps
-from io import BytesIO
 
 try:
     from http import HTTPStatus
@@ -14,7 +14,7 @@
 
 from werkzeug import exceptions
 from werkzeug.datastructures import Authorization
-from werkzeug.exceptions import abort
+from werkzeug.exceptions import abort, RequestEntityTooLarge
 from werkzeug.utils import redirect
 from werkzeug.wrappers import Request as _Request
 from werkzeug.wrappers import Response
@@ -72,11 +72,12 @@
     @property
     def decoded_data(self):
         if self.content_encoding == 'gzip':
-            if self.user_id:
-                zipfile = gzip.GzipFile(fileobj=BytesIO(self.data), mode='rb')
-                return zipfile.read()
-            else:
-                abort(HTTPStatus.UNSUPPORTED_MEDIA_TYPE)
+            with gzip.GzipFile(
+                    fileobj=io.BytesIO(self.data), mode='rb') as stream:
+                data = stream.read(self.max_content_length + 1)
+            if len(data) > self.max_content_length:
+                raise RequestEntityTooLarge()
+            return data
         else:
             return self.data
 
diff -r 906d6cc6f548 -r 53b58829d26b trytond/trytond/wsgi.py
--- a/trytond/trytond/wsgi.py   Sat Nov 21 15:24:53 2026 +0100
+++ b/trytond/trytond/wsgi.py   Sat Nov 21 18:13:00 2026 +0100
@@ -106,6 +106,7 @@
         try:
             endpoint, request.view_args = adapter.match()
             max_request_size = getattr(endpoint, 'max_request_size', None)
+            request.max_content_length = max_request_size
             self.check_request_size(request, max_request_size)
             return endpoint(request, **request.view_args)
         except exceptions.HTTPException as e:

Reply via email to