CVE-2021-21239
PySAML2 before 6.5.0: Improper SAML signature verification
- CVSS 6.5
- CWE-347 Improper Verification of Cryptographic Signature
- Cryptographic
- Remote
PySAML2 is a pure python implementation of SAML Version 2 Standard. PySAML2 before 6.5.0 has an improper verification of cryptographic signature vulnerability. Users of pysaml2 that use the default CryptoBackendXmlSec1 backend and need to verify signed SAML documents are impacted. PySAML2 does not ensure that a signed SAML document is correctly signed. The default CryptoBackendXmlSec1 backend is using the xmlsec1 binary to verify the signature of signed SAML documents, but by default xmlsec1 accepts any type of key found within the given document. xmlsec1 needs to be configured explicitly to only use only _x509 certificates_ for the verification process of the SAML document signature. This is fixed in PySAML2 6.5.0.
- CVSS base score
- 6.5
- Published
- 2021-01-21
- OWASP
- A08 Software and Data Integrity Failures
- Orthogonal defect classification
- Checking
- Code defect classification
- Incorrect Check
- Category
- Cryptographic
- Subcategory
- Cryptographic Implementation Error
- Accessibility scope
- Remote
- Impact
- Unauthorized Access
- Fixed by upgrading
- Yes
Solution
Update PySAML2 to version 6.5.0 or higher.
Vulnerable code sample
from saml2 import saml
from saml2.sigver import SignatureVerifier
from saml2.config import Config
from saml2.backend import InMemory
config = Config().load({
})
backend = InMemory(config)
verifier = SignatureVerifier(backend)
def verify_signed_saml_document(signed_document):
"""Vulnerable function that demonstrates the security issue."""
try:
saml_response = saml.from_string(signed_document)
if verifier.verify(saml_response):
print("Signature is valid.")
else:
print("Signature verification failed.")
except Exception as e:
print(f"An error occurred during verification: {e}")
signed_saml = "<Your Signed SAML Document Here>"
verify_signed_saml_document(signed_saml)Patched code sample
from saml2 import saml, sigver
from saml2.sigver import SignatureVerifier
from saml2.config import Config
from saml2.backend import InMemory
config = Config().load({
})
backend = InMemory(config)
verifier = SignatureVerifier(backend, use_x509=True)
def verify_signed_saml_document(signed_document):
"""Secure function that fixes the vulnerability."""
try:
saml_response = saml.from_string(signed_document)
if verifier.verify(saml_response):
print("Signature is valid.")
else:
print("Signature verification failed.")
except Exception as e:
print(f"An error occurred during verification: {e}")
signed_saml = "<Your Signed SAML Document Here>"
verify_signed_saml_document(signed_saml)Cite this entry
@misc{vaitp:cve202121239,
title = {{PySAML2 before 6.5.0: Improper SAML signature verification}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2021},
note = {VAITP Python Vulnerability Dataset, entry CVE-2021-21239},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-21239/}}
}
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 ::
