VAITP Dataset

← Back to the dataset

CVE-2017-1000246

Weak data encryption in pysaml2 < 4.4.0 due to IV reuse

  • CVSS 5.3
  • CWE-330 Use of Insufficiently Random Values
  • Cryptographic
  • Remote

Python package pysaml2 version 4.4.0 and earlier reuses the initialization vector across encryptions in the IDP server, resulting in weak encryption of data.

CVSS base score
5.3
Published
2017-11-17
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Cryptographic
Subcategory
Weak encryption algorithm
Accessibility scope
Remote
Impact
Information Disclosure
Affected component
pysaml2
Fixed by upgrading
Yes

Solution

Update to pysaml2 version 4.4.1 or higher.

Vulnerable code sample

from Cryptodome.Cipher import AES

class InsecureEncryption:
    def __init__(self, key, iv):
        self.key = key
        self.iv = iv  # Reused IV

    def encrypt(self, data):
        cipher = AES.new(self.key, AES.MODE_CBC, self.iv)
        # Pad data to be multiple of block size
        padded_data = self._pad(data)
        encrypted_data = cipher.encrypt(padded_data)
        return encrypted_data

    def _pad(self, data):
        # Pad data to be a multiple of the block size
        pad_len = AES.block_size - len(data) % AES.block_size
        return data + bytes([pad_len] * pad_len)

# Example usage
key = b'Sixteen byte key'  # AES-128
iv = b'Sixteen byte iv.'  # Reused IV
insecure_encryption = InsecureEncryption(key, iv)
encrypted = insecure_encryption.encrypt(b'Secret Message')

Patched code sample

from Cryptodome.Cipher import AES
from Cryptodome.Random import get_random_bytes

class SecureEncryption:
    def __init__(self, key):
        self.key = key

    def encrypt(self, data):
        # Generate a unique IV for each encryption
        iv = get_random_bytes(AES.block_size)
        cipher = AES.new(self.key, AES.MODE_CBC, iv)
        # Pad data to be multiple of block size
        padded_data = self._pad(data)
        encrypted_data = iv + cipher.encrypt(padded_data)
        return encrypted_data

    def _pad(self, data):
        # Pad data to be a multiple of the block size
        pad_len = AES.block_size - len(data) % AES.block_size
        return data + bytes([pad_len] * pad_len)

# Example usage
key = get_random_bytes(16)  # AES-128
secure_encryption = SecureEncryption(key)
encrypted = secure_encryption.encrypt(b'Secret Message')

Published fix

Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.

  • Always generate a random IV for AES operations (IdentityPython/pysaml2)
    src/saml2/aes.py, src/saml2/aes.py · AESCipher.build_cipher, src/saml2/aes.py · AESCipher.decrypt, src/saml2/aes.py · AESCipher.encrypt, src/saml2/aes.py · AESCipher.__init__, src/saml2/aes.py · run_test, src/saml2/authn.py · UsernamePasswordMako.__init__, src/saml2/server.py · Server.__init__

Cite this entry

@misc{vaitp:cve20171000246,
  title        = {{Weak data encryption in pysaml2 < 4.4.0 due to IV reuse}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2017},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2017-1000246},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2017-1000246/}}
}

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.