Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CVE-2024-7592: Denial of Service Vulnerability in http.cookies._unquote() #123067

Closed
ch4n3-yoon opened this issue Aug 16, 2024 · 6 comments
Closed
Labels
type-bug An unexpected behavior, bug, or error type-security A security issue

Comments

@ch4n3-yoon
Copy link

ch4n3-yoon commented Aug 16, 2024

Bug report

Bug description:

Description

A potential Denial of Service (DoS) vulnerability, identified as CVE-2024-7592, has been discovered in the _unquote() method of the http.cookies module in Python's standard library. This vulnerability is particularly concerning as it affects frameworks that utilize this method, including Django.

Vulnerable Code

The _unquote() function uses regular expressions _OctalPatt and _QuotePatt within a while loop to process input strings. The problematic patterns and their application can lead to exponential time complexity under certain conditions, akin to a Regular Expression Denial of Service (ReDoS) attack.

# http/cookies.py
_OctalPatt = re.compile(r"\\[0-3][0-7][0-7]")
_QuotePatt = re.compile(r"[\\].")
def _unquote(str):
    # ... (code omitted for brevity)
    while 0 <= i < n:
        o_match = _OctalPatt.search(str, i)
        q_match = _QuotePatt.search(str, i)
        # ... (further processing)

Impact

This vulnerability has also been verified in the Django framework, where the parse_cookie() function uses this method to process incoming cookie headers. This could potentially be exploited by sending specially crafted cookie values to trigger significant delays:

  • Cookie sizes of 8000+ bytes caused delays of approximately 0.15 seconds per HTTP request.
  • Cookie sizes of 20000+ bytes resulted in delays of about 1 second per request.

While many environments limit HTTP request sizes, the specific limits vary, and in some cases, this vulnerability could be exploited.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

@ch4n3-yoon ch4n3-yoon added the type-bug An unexpected behavior, bug, or error label Aug 16, 2024
@Eclips4 Eclips4 added the type-security A security issue label Aug 16, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Aug 16, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Aug 16, 2024
@serhiy-storchaka
Copy link
Member

The complexity is quadratic, not exponential.

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 17, 2024
…values with backslashes (pythonGH-123075)

This fixes CVE-2024-7592.
(cherry picked from commit 44e4583)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 17, 2024
…values with backslashes (pythonGH-123075)

This fixes CVE-2024-7592.
(cherry picked from commit 44e4583)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 17, 2024
…values with backslashes (pythonGH-123075)

This fixes CVE-2024-7592.
(cherry picked from commit 44e4583)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 17, 2024
…values with backslashes (pythonGH-123075)

This fixes CVE-2024-7592.
(cherry picked from commit 44e4583)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 17, 2024
…values with backslashes (pythonGH-123075)

This fixes CVE-2024-7592.
(cherry picked from commit 44e4583)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 17, 2024
…values with backslashes (pythonGH-123075)

This fixes CVE-2024-7592.
(cherry picked from commit 44e4583)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@sethmlarson
Copy link
Contributor

Closed in #123075

jeremyhylton pushed a commit to jeremyhylton/cpython that referenced this issue Aug 19, 2024
rickprice added a commit to ActiveState/cpython that referenced this issue Aug 21, 2024
pythongh-123067: Fix quadratic complexity in parsing "-quoted cookie …

…values with backslashes (pythonGH-123075)

This fixes CVE-2024-7592.
rickprice added a commit to ActiveState/cpython that referenced this issue Aug 22, 2024
pythongh-123067: Fix quadratic complexity in parsing "-quoted cookie …

…values with backslashes (pythonGH-123075)

This fixes CVE-2024-7592.

Redo tests without a subtest

Backport how RegEx stuff is handled to Python2
rickprice added a commit to ActiveState/cpython that referenced this issue Aug 22, 2024
pythongh-123067: Fix quadratic complexity in parsing "-quoted cookie …

…values with backslashes (pythonGH-123075)

This fixes CVE-2024-7592.
blhsing pushed a commit to blhsing/cpython that referenced this issue Aug 22, 2024
@hauntsaninja
Copy link
Contributor

@sethmlarson looks like the backports are all unmerged (usually we keep the issue open till that's done)
Do you know if there's anything we're waiting on to merge them? If not, I can at least merge to 3.13 and 3.12! :-)

@hauntsaninja hauntsaninja reopened this Aug 24, 2024
@sethmlarson
Copy link
Contributor

@hauntsaninja I don't think there's anything blocking the backports!

hauntsaninja pushed a commit that referenced this issue Aug 24, 2024
… values with backslashes (GH-123075) (#123103)

gh-123067: Fix quadratic complexity in parsing "-quoted cookie values with backslashes (GH-123075)

This fixes CVE-2024-7592.
(cherry picked from commit 44e4583)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
hauntsaninja pushed a commit that referenced this issue Aug 24, 2024
… values with backslashes (GH-123075) (#123104)

gh-123067: Fix quadratic complexity in parsing "-quoted cookie values with backslashes (GH-123075)

This fixes CVE-2024-7592.
(cherry picked from commit 44e4583)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@hauntsaninja
Copy link
Contributor

Great, I merged to 3.13 and 3.12, the other branches will need the RM to merge

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Aug 25, 2024

AFAIK backports to 3.13 should be approved by other core developer. This is why I did not merge them myself.

ambv pushed a commit that referenced this issue Sep 4, 2024
…values with backslashes (GH-123075) (#123108)

This fixes CVE-2024-7592.
(cherry picked from commit 44e4583)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
ambv pushed a commit that referenced this issue Sep 4, 2024
…values with backslashes (GH-123075) (#123107)

This fixes CVE-2024-7592.
(cherry picked from commit 44e4583)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
ambv pushed a commit that referenced this issue Sep 4, 2024
… values with backslashes (GH-123075) (#123105)

This fixes CVE-2024-7592.
(cherry picked from commit 44e4583)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
ambv pushed a commit that referenced this issue Sep 4, 2024
… values with backslashes (GH-123075) (#123106)

This fixes CVE-2024-7592.
(cherry picked from commit 44e4583)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@ambv ambv closed this as completed Sep 4, 2024
mcepl pushed a commit to openSUSE-Python/cpython that referenced this issue Sep 18, 2024
Fix quadratic complexity in parsing ``"``-quoted cookie values
with backslashes by `http.cookies`.

Fixes: gh#python#123067
Fixes: bsc#1229596 (CVE-2024-7592)
From-PR: gh#python/cpython!123075
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Patch: CVE-2024-7592-quad-complex-cookies.patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error type-security A security issue
Projects
None yet
Development

No branches or pull requests

6 participants