Secret leaks often occur when a sensitive piece of authentication data is stored with the source code of an application. Considering the source
code is intended to be deployed across multiple assets, including source code repositories or application hosting servers, the secrets might get
exposed to an unintended audience.
Why is this an issue?
In most cases, trust boundaries are violated when a secret is exposed in a source code repository or an uncontrolled deployment environment.
Unintended people who don’t need to know the secret might get access to it. They might then be able to use it to gain unwanted access to associated
services or resources.
The trust issue can be more or less severe depending on the people’s role and entitlement.
What is the potential impact?
A cryptographic private key is a piece of sensitive information that is used in asymmetric cryptography. They are used in conjunction with public
keys to secure communications and authenticate digital signatures.
Private keys can be used to achieve two main cryptographic operations, encryption or digital signature. Those operations are the basis of multiple
higher-level security mechanisms such as:
- User authentication
- Servers authentication, for example in the X509 trust model
- E-mail encryption
Disclosing a cryptographic private key to an unintended audience can have severe security consequences. The exact impact will vary depending on the
role of the key and the assets it protects.
For example, if the key is used in conjunction with an X509 certificate to authenticate a web server as part of TLS communications, attackers will
be able to impersonate that server. This leads to Man-In-The-Middle-Attacks that would affect both the confidentiality and integrity of the
communications from clients to that server.
If the key was used as part of e-mail protocols, attackers might be able to send e-mails on behalf of the key owner or decrypt previously encrypted
emails. This might lead to sensitive information disclosure and reputation loss.
How to fix it
Revoke the secret
Revoke any leaked secrets and remove them from the application source code.
Before revoking the secret, ensure that no other applications or processes are using it. Other usages of the secret will also be impacted when the
secret is revoked.
In most cases, if the key is used as part of a larger trust model (X509, PGP, etc), it is necessary to issue and publish a revocation certificate.
Doing so will ensure that all people and assets that rely on this key for security operations are aware of its compromise and stop trusting it.
Analyze recent secret use
When available, analyze authentication logs to identify any unintended or malicious use of the secret since its disclosure date. Doing this will
allow determining if an attacker took advantage of the leaked secret and to what extent.
This operation should be part of a global incident response process.
Use a secret vault
A secret vault should be used to generate and store the new secret. This will ensure the secret’s security and prevent any further unexpected
disclosure.
Depending on the development platform and the leaked secret type, multiple solutions are currently available.
Code examples
Noncompliant code example
private_key = "-----BEGIN EC PRIVATE KEY-----" \
"MF8CAQEEGEfVxjrMPigNhGP6DqH6DPeUZPbaoaCCXaAKBggqhkjOPQMBAaE0AzIA" \
"BCIxho34upZyXDi/AUy/TBisGeh4yKJN7pit9Z+nKs4QajVy97X8W9JdySlbWeRt" \
"2w==" \
"-----END EC PRIVATE KEY-----"
Compliant solution
with open("/path/to/private.key","r") as key_file:
private_key = key_file.read()
Resources
Standards