!60 [sync] PR-57: fix CVE-2024-52304
From: @openeuler-sync-bot Reviewed-by: @lyn1001 Signed-off-by: @lyn1001
This commit is contained in:
commit
aa475252d0
108
CVE-2024-52304.patch
Normal file
108
CVE-2024-52304.patch
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
From 541d86d9e7884590c655876cd40042565293d8df Mon Sep 17 00:00:00 2001
|
||||||
|
From: "J. Nick Koston" <nick@koston.org>
|
||||||
|
Date: Wed, 13 Nov 2024 08:14:06 -0600
|
||||||
|
Subject: [PATCH] Fix incorrect parsing of chunk extensions with the pure
|
||||||
|
Python parser (#9851)
|
||||||
|
|
||||||
|
---
|
||||||
|
CHANGES/9851.bugfix.rst | 1 +
|
||||||
|
aiohttp/http_parser.py | 7 ++++++
|
||||||
|
tests/test_http_parser.py | 48 ++++++++++++++++++++++++++++++++++++++-
|
||||||
|
3 files changed, 55 insertions(+), 1 deletion(-)
|
||||||
|
create mode 100644 CHANGES/9851.bugfix.rst
|
||||||
|
|
||||||
|
diff --git a/CHANGES/9851.bugfix.rst b/CHANGES/9851.bugfix.rst
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000..02541a9
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/CHANGES/9851.bugfix.rst
|
||||||
|
@@ -0,0 +1 @@
|
||||||
|
+Fixed incorrect parsing of chunk extensions with the pure Python parser -- by :user:`bdraco`.
|
||||||
|
diff --git a/aiohttp/http_parser.py b/aiohttp/http_parser.py
|
||||||
|
index b182877..af42272 100644
|
||||||
|
--- a/aiohttp/http_parser.py
|
||||||
|
+++ b/aiohttp/http_parser.py
|
||||||
|
@@ -730,6 +730,13 @@ class HttpPayloadParser:
|
||||||
|
i = chunk.find(CHUNK_EXT, 0, pos)
|
||||||
|
if i >= 0:
|
||||||
|
size_b = chunk[:i] # strip chunk-extensions
|
||||||
|
+ # Verify no LF in the chunk-extension
|
||||||
|
+ if b"\n" in (ext := chunk[i:pos]):
|
||||||
|
+ exc = BadHttpMessage(
|
||||||
|
+ f"Unexpected LF in chunk-extension: {ext!r}"
|
||||||
|
+ )
|
||||||
|
+ set_exception(self.payload, exc)
|
||||||
|
+ raise exc
|
||||||
|
else:
|
||||||
|
size_b = chunk[:pos]
|
||||||
|
|
||||||
|
diff --git a/tests/test_http_parser.py b/tests/test_http_parser.py
|
||||||
|
index 9db34dd..6e14827 100644
|
||||||
|
--- a/tests/test_http_parser.py
|
||||||
|
+++ b/tests/test_http_parser.py
|
||||||
|
@@ -10,6 +10,7 @@ from yarl import URL
|
||||||
|
|
||||||
|
import aiohttp
|
||||||
|
from aiohttp import http_exceptions, streams
|
||||||
|
+from aiohttp.base_protocol import BaseProtocol
|
||||||
|
from aiohttp.http_parser import (
|
||||||
|
DeflateBuffer,
|
||||||
|
HttpPayloadParser,
|
||||||
|
@@ -758,8 +759,53 @@ def test_parse_no_length_payload(parser) -> None:
|
||||||
|
msg, payload = parser.feed_data(text)[0][0]
|
||||||
|
assert payload.is_eof()
|
||||||
|
|
||||||
|
+@pytest.mark.skipif(NO_EXTENSIONS, reason="Only tests C parser.")
|
||||||
|
+async def test_parse_chunked_payload_with_lf_in_extensions_c_parser(
|
||||||
|
+ loop: asyncio.AbstractEventLoop, protocol: BaseProtocol
|
||||||
|
+) -> None:
|
||||||
|
+ """Test the C-parser with a chunked payload that has a LF in the chunk extensions."""
|
||||||
|
+ # The C parser will raise a BadHttpMessage from feed_data
|
||||||
|
+ parser = HttpRequestParserC(
|
||||||
|
+ protocol,
|
||||||
|
+ loop,
|
||||||
|
+ 2**16,
|
||||||
|
+ max_line_size=8190,
|
||||||
|
+ max_field_size=8190,
|
||||||
|
+ )
|
||||||
|
+ payload = (
|
||||||
|
+ b"GET / HTTP/1.1\r\nHost: localhost:5001\r\n"
|
||||||
|
+ b"Transfer-Encoding: chunked\r\n\r\n2;\nxx\r\n4c\r\n0\r\n\r\n"
|
||||||
|
+ b"GET /admin HTTP/1.1\r\nHost: localhost:5001\r\n"
|
||||||
|
+ b"Transfer-Encoding: chunked\r\n\r\n0\r\n\r\n"
|
||||||
|
+ )
|
||||||
|
+ with pytest.raises(http_exceptions.BadHttpMessage, match="\\\\nxx"):
|
||||||
|
+ parser.feed_data(payload)
|
||||||
|
+async def test_parse_chunked_payload_with_lf_in_extensions_py_parser(
|
||||||
|
+ loop: asyncio.AbstractEventLoop, protocol: BaseProtocol
|
||||||
|
+) -> None:
|
||||||
|
+ """Test the py-parser with a chunked payload that has a LF in the chunk extensions."""
|
||||||
|
+ # The py parser will not raise the BadHttpMessage directly, but instead
|
||||||
|
+ # it will set the exception on the StreamReader.
|
||||||
|
+ parser = HttpRequestParserPy(
|
||||||
|
+ protocol,
|
||||||
|
+ loop,
|
||||||
|
+ 2**16,
|
||||||
|
+ max_line_size=8190,
|
||||||
|
+ max_field_size=8190,
|
||||||
|
+ )
|
||||||
|
+ payload = (
|
||||||
|
+ b"GET / HTTP/1.1\r\nHost: localhost:5001\r\n"
|
||||||
|
+ b"Transfer-Encoding: chunked\r\n\r\n2;\nxx\r\n4c\r\n0\r\n\r\n"
|
||||||
|
+ b"GET /admin HTTP/1.1\r\nHost: localhost:5001\r\n"
|
||||||
|
+ b"Transfer-Encoding: chunked\r\n\r\n0\r\n\r\n"
|
||||||
|
+ )
|
||||||
|
+ messages, _, _ = parser.feed_data(payload)
|
||||||
|
+ reader = messages[0][1]
|
||||||
|
+ assert isinstance(reader.exception(), http_exceptions.BadHttpMessage)
|
||||||
|
+ assert "\\nxx" in str(reader.exception())
|
||||||
|
+
|
||||||
|
|
||||||
|
-def test_partial_url(parser) -> None:
|
||||||
|
+def test_partial_url(parser: HttpRequestParser) -> None:
|
||||||
|
messages, upgrade, tail = parser.feed_data(b"GET /te")
|
||||||
|
assert len(messages) == 0
|
||||||
|
messages, upgrade, tail = parser.feed_data(b"st HTTP/1.1\r\n\r\n")
|
||||||
|
--
|
||||||
|
2.43.0
|
||||||
|
|
||||||
@ -1,7 +1,7 @@
|
|||||||
%global _empty_manifest_terminate_build 0
|
%global _empty_manifest_terminate_build 0
|
||||||
Name: python-aiohttp
|
Name: python-aiohttp
|
||||||
Version: 3.7.4
|
Version: 3.7.4
|
||||||
Release: 4
|
Release: 5
|
||||||
Summary: Async http client/server framework (asyncio)
|
Summary: Async http client/server framework (asyncio)
|
||||||
License: Apache 2
|
License: Apache 2
|
||||||
URL: https://github.com/aio-libs/aiohttp
|
URL: https://github.com/aio-libs/aiohttp
|
||||||
@ -9,6 +9,7 @@ Source0: https://files.pythonhosted.org/packages/99/f5/90ede947a3ce2d6de1614799f
|
|||||||
Patch0: change-require-chardet-package-version.patch
|
Patch0: change-require-chardet-package-version.patch
|
||||||
Patch1: CVE-2023-47641.patch
|
Patch1: CVE-2023-47641.patch
|
||||||
Patch2: CVE-2023-49081.patch
|
Patch2: CVE-2023-49081.patch
|
||||||
|
Patch3: CVE-2024-52304.patch
|
||||||
|
|
||||||
BuildRequires: python3-attrs
|
BuildRequires: python3-attrs
|
||||||
BuildRequires: python3-chardet
|
BuildRequires: python3-chardet
|
||||||
@ -79,6 +80,9 @@ mv %{buildroot}/doclist.lst .
|
|||||||
%{_docdir}/*
|
%{_docdir}/*
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Wed Nov 20 2024 Deyuan Fan <fandeyuan@kylinos.cn> - 3.7.4-5
|
||||||
|
- Fix CVE-2024-52304
|
||||||
|
|
||||||
* Fri Dec 01 2023 wangkai <13474090681@163.com> - 3.7.4-4
|
* Fri Dec 01 2023 wangkai <13474090681@163.com> - 3.7.4-4
|
||||||
- Fix CVE-2023-49081
|
- Fix CVE-2023-49081
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user