VAITP Dataset

← Back to the dataset

CVE-2022-48566

Constant-time-defeating optimisations in compare_digest function

  • CVSS 5.9
  • CWE-362 Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition')
  • Cryptographic
  • Local

An issue was discovered in compare_digest in Lib/hmac.py in Python through 3.9.1. Constant-time-defeating optimizations were possible in the accumulator variable in hmac.compare_digest.

CVSS base score
5.9
Published
2023-08-22
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Timing/Serialization
Code defect classification
Timing Issues
Category
Cryptographic
Subcategory
Cryptographic Implementation Error
Accessibility scope
Local
Impact
Information Disclosure
Fixed by upgrading
Yes

Solution

Upgrade to Python 3.9.2 or later.

Vulnerable code sample

import hmac

def check_email_domain(email, domain):
    email = email.encode()
    domain = domain.encode()
    email_domain = email.split(b'@')[-1]
    return hmac.compare_digest(email_domain, domain)

# Test the function with some email addresses
print(check_email_domain("alice@company.example.com", "company.example.com")) # True
print(check_email_domain("bob@company.example.com", "company.example.com")) # True
print(check_email_domain("charlie@evil.com", "company.example.com")) # False
print(check_email_domain("alice@evil.com<alice@company.example.com>", "company.example.com")) # True

Patched code sample

from email_validator import validate_email

def check_email_domain(email, domain):
    email_parts = validate_email(email)
    if email_parts.domain == domain:
        return True
    else:
        return False

# Test the function with some email addresses
print(check_email_domain("alice@company.example.com", "company.example.com")) # True
print(check_email_domain("bob@company.example.com", "company.example.com")) # True
print(check_email_domain("charlie@evil.com", "company.example.com")) # False
print(check_email_domain("alice@evil.com<alice@company.example.com>", "company.example.com")) # False

Cite this entry

@misc{vaitp:cve202248566,
  title        = {{Constant-time-defeating optimisations in compare_digest function}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2023},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2022-48566},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-48566/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::