org.sonar.l10n.py.rules.python.S4423.html Maven / Gradle / Ivy
This vulnerability exposes encrypted data to a number of attacks whose goal is to recover the plaintext.
Why is this an issue?
Encryption algorithms are essential for protecting sensitive information and ensuring secure communications in a variety of domains. They are used
for several important reasons:
- Confidentiality, privacy, and intellectual property protection
- Security during transmission or on storage devices
- Data integrity, general trust, and authentication
When selecting encryption algorithms, tools, or combinations, you should also consider two things:
- No encryption is unbreakable.
- The strength of an encryption algorithm is usually measured by the effort required to crack it within a reasonable time frame.
For these reasons, as soon as cryptography is included in a project, it is important to choose encryption algorithms that are considered strong and
secure by the cryptography community.
To provide communication security over a network, SSL and TLS are generally used. However, it is important to note that the following protocols are
all considered weak by the cryptographic community, and are officially deprecated:
- SSL versions 1.0, 2.0 and 3.0
- TLS versions 1.0 and 1.1
When these unsecured protocols are used, it is best practice to expect a breach: that a user or organization with malicious intent will perform
mathematical attacks on this data after obtaining it by other means.
What is the potential impact?
After retrieving encrypted data and performing cryptographic attacks on it on a given timeframe, attackers can recover the plaintext that
encryption was supposed to protect.
Depending on the recovered data, the impact may vary.
Below are some real-world scenarios that illustrate the potential impact of an attacker exploiting the vulnerability.
Additional attack surface
By modifying the plaintext of the encrypted message, an attacker may be able to trigger additional vulnerabilities in the code. An attacker can
further exploit a system to obtain more information.
Encrypted values are often considered trustworthy because it would not be possible for a
third party to modify them under normal circumstances.
Breach of confidentiality and privacy
When encrypted data contains personal or sensitive information, its retrieval by an attacker can lead to privacy violations, identity theft,
financial loss, reputational damage, or unauthorized access to confidential systems.
In this scenario, the company, its employees, users, and partners could be seriously affected.
The impact is twofold, as data breaches and exposure of encrypted data can undermine trust in the organization, as customers, clients and
stakeholders may lose confidence in the organization’s ability to protect their sensitive data.
Legal and compliance issues
In many industries and locations, there are legal and compliance requirements to protect sensitive data. If encrypted data is compromised and the
plaintext can be recovered, companies face legal consequences, penalties, or violations of privacy laws.
How to fix it in Python Standard Library
Code examples
Noncompliant code example
import ssl
ssl.SSLContext(ssl.PROTOCOL_SSLv3) # Noncompliant
Compliant solution
import ssl
context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
context.minimum_version = ssl.TLSVersion.TLSv1_2
How does this work?
As a rule of thumb, by default you should use the cryptographic algorithms and mechanisms that are considered strong by the cryptographic
community.
The best choices at the moment are the following.
Use TLS v1.2 or TLS v1.3
Even though TLS V1.3 is available, using TLS v1.2 is still considered good and secure practice by the cryptography community.
The use of TLS v1.2 ensures compatibility with a wide range of platforms and enables seamless communication between different systems that do not
yet have TLS v1.3 support.
The only drawback depends on whether the framework used is outdated: its TLS v1.2 settings may enable older and insecure cipher suites that are
deprecated as insecure.
On the other hand, TLS v1.3 removes support for older and weaker cryptographic algorithms, eliminates known vulnerabilities from previous TLS
versions, and improves performance.
How to fix it in OpenSSL
Code examples
Noncompliant code example
from OpenSSL import SSL
SSL.Context(SSL.SSLv3_METHOD) # Noncompliant
Compliant solution
from OpenSSL import SSL
context = SSL.Context(SSL.TLS_SERVER_METHOD)
context.set_min_proto_version(SSL.TLS1_2_VERSION)
How does this work?
As a rule of thumb, by default you should use the cryptographic algorithms and mechanisms that are considered strong by the cryptographic
community.
The best choices at the moment are the following.
Use TLS v1.2 or TLS v1.3
Even though TLS V1.3 is available, using TLS v1.2 is still considered good and secure practice by the cryptography community.
The use of TLS v1.2 ensures compatibility with a wide range of platforms and enables seamless communication between different systems that do not
yet have TLS v1.3 support.
The only drawback depends on whether the framework used is outdated: its TLS v1.2 settings may enable older and insecure cipher suites that are
deprecated as insecure.
On the other hand, TLS v1.3 removes support for older and weaker cryptographic algorithms, eliminates known vulnerabilities from previous TLS
versions, and improves performance.
How to fix it in AWS CDK
Code examples
Noncompliant code example
from aws_cdk.aws_apigateway import DomainName, SecurityPolicy
class ExampleStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
DomainName(self, "example",
domain_name="example.com",
certificate=certificate,
security_policy=SecurityPolicy.TLS_1_0 # Noncompliant
)
By default, AWS’s OpenSearch service CfnDomains
enables TLS 1.0, a weak cryptographic algorithm.
from aws_cdk.aws_opensearchservice import CfnDomain, EngineVersion
class ExampleStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
CfnDomain(self, "example",
version=EngineVersion.OPENSEARCH_1_3
) # Noncompliant
Compliant solution
from aws_cdk.aws_apigateway import DomainName, SecurityPolicy
class ExampleStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
DomainName(self, "example",
domain_name="example.com",
certificate=certificate,
security_policy=SecurityPolicy.TLS_1_2
)
from aws_cdk.aws_opensearchservice import CfnDomain, EngineVersion
class ExampleStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
CfnDomain(self, "example",
version=EngineVersion.OPENSEARCH_1_3
domain_endpoint_options=CfnDomain.DomainEndpointOptionsProperty(
tls_security_policy="Policy-Min-TLS-1-2-2019-07"
)
)
How does this work?
As a rule of thumb, by default you should use the cryptographic algorithms and mechanisms that are considered strong by the cryptographic
community.
The best choices at the moment are the following.
Use TLS v1.2 or TLS v1.3
Even though TLS V1.3 is available, using TLS v1.2 is still considered good and secure practice by the cryptography community.
The use of TLS v1.2 ensures compatibility with a wide range of platforms and enables seamless communication between different systems that do not
yet have TLS v1.3 support.
The only drawback depends on whether the framework used is outdated: its TLS v1.2 settings may enable older and insecure cipher suites that are
deprecated as insecure.
On the other hand, TLS v1.3 removes support for older and weaker cryptographic algorithms, eliminates known vulnerabilities from previous TLS
versions, and improves performance.
Resources
Articles & blog posts
- Wikipedia, Padding Oracle Attack
- Wikipedia, Chosen-Ciphertext Attack
- Wikipedia, Chosen-Plaintext Attack
- Wikipedia, Semantically Secure Cryptosystems
- Wikipedia, OAEP
- Wikipedia, Galois/Counter Mode
Standards
- OWASP - Top 10 2021 Category A2 - Cryptographic Failures
- OWASP - Top 10 2021 Category A7 - Identification and
Authentication Failures
- OWASP - Top 10 2017 Category A3 - Sensitive Data
Exposure
- OWASP - Top 10 2017 Category A6 - Security
Misconfiguration
- CWE - CWE-327 - Use of a Broken or Risky Cryptographic Algorithm