VAITP Dataset

← Back to the dataset

CVE-2023-27043

Incorrect parsing of e-mail addresses in Python email module

  • CVSS 5.3
  • CWE-20 Improper Input Validation
  • Input Validation and Sanitization
  • Remote

The email module of Python through 3.11.3 incorrectly parses e-mail addresses that contain a special character. The wrong portion of an RFC2822 header is identified as the value of the addr-spec. In some applications, an attacker can bypass a protection mechanism in which application access is granted only after verifying receipt of e-mail to a specific domain (e.g., only @company.example.com addresses may be used for signup). This occurs in email/_parseaddr.py in recent versions of Python.

CVSS base score
5.3
Published
2023-04-19
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
Insecure Parsing or Deserialization
Accessibility scope
Remote
Impact
Unauthorized Access
Affected component
Python
Fixed by upgrading
Yes

Solution

Upgrade to Python version 3.11.4 or newer.

Vulnerable code sample

import re
from email.utils import parseaddr

def is_allowed_signup(email_header: str) -> bool:
    # VULNERABLE: misparses address with special chars, allowing bypass
    name, addr = parseaddr(email_header)
    domain = addr.split('@')[-1] if '@' in addr else ''
    return domain.lower() == 'company.example.com'

Patched code sample

import re
from email.headerregistry import Address
from email.parser import HeaderParser

def is_allowed_signup(email_header: str) -> bool:
    # FIX: proper RFC-compliant parsing prevents domain bypass
    hdr = HeaderParser().parsestr(f"From: {email_header}")
    addr_obj = hdr['From'].addresses[0] if hdr['From'].addresses else None
    domain = addr_obj.domain if isinstance(addr_obj, Address) else ''
    return domain.lower() == 'company.example.com'

Cite this entry

@misc{vaitp:cve202327043,
  title        = {{Incorrect parsing of e-mail addresses in Python email module}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2023},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2023-27043},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2023-27043/}}
}

Download this entry as JSON Download the whole dataset

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 ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.