Skip to content

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

Closed

Description

@ch4n3-yoon

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

Activity

  1. added 2 commits that reference this issue on Aug 16, 2024
  2. serhiy-storchaka commented on Aug 16, 2024

    @serhiy-storchaka
    Member

    The complexity is quadratic, not exponential.

  3. added a commit that references this issue on Aug 17, 2024
  4. added 6 commits that reference this issue on Aug 17, 2024
  5. sethmlarson commented on Aug 19, 2024

    @sethmlarson
    Contributor

    Closed in #123075

  6. added a commit that references this issue on Aug 19, 2024
  7. 3 remaining items

  8. added a commit that references this issue on Aug 22, 2024
  9. hauntsaninja commented on Aug 24, 2024

    @hauntsaninja
    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! :-)

  10. sethmlarson commented on Aug 24, 2024

    @sethmlarson
    Contributor

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

  11. added 2 commits that reference this issue on Aug 24, 2024
  12. hauntsaninja commented on Aug 24, 2024

    @hauntsaninja
    Contributor

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

  13. serhiy-storchaka commented on Aug 25, 2024

    @serhiy-storchaka
    Member

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

  14. added 4 commits that reference this issue on Sep 4, 2024
  15. added a commit that references this issue on Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or errortype-securityA security issue

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions