|
| 1 | +<p>Secret leaks often occur when a sensitive piece of authentication data is stored with the source code of an application. Considering the source |
| 2 | +code is intended to be deployed across multiple assets, including source code repositories or application hosting servers, the secrets might get |
| 3 | +exposed to an unintended audience.</p> |
1 | 4 | <h2>Why is this an issue?</h2>
|
2 |
| -<p>AWS credentials are designed to authenticate and authorize requests to AWS.</p> |
3 |
| -<p>If your application interacts with AWS then it requires AWS credentials to access all the resources it needs to function properly. Resources that |
4 |
| -can be accessed depend on the permission granted to the AWS account. These credentials may authenticate to the AWS account root user who has |
5 |
| -unrestricted access to all resources in your AWS account, including billing information.</p> |
6 |
| -<p>This rule flags instances of:</p> |
| 5 | +<p>In most cases, trust boundaries are violated when a secret is exposed in a source code repository or an uncontrolled deployment environment. |
| 6 | +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 |
| 7 | +services or resources.</p> |
| 8 | +<p>The trust issue can be more or less severe depending on the people’s role and entitlement.</p> |
| 9 | +<p>This rule detects the following leaks:</p> |
7 | 10 | <ul>
|
8 |
| - <li> AWS Secret Access Key </li> |
9 |
| - <li> AWS Access ID </li> |
10 |
| - <li> AWS Session Token </li> |
| 11 | + <li> AWS Secret Access Keys </li> |
| 12 | + <li> AWS Access IDs </li> |
| 13 | + <li> AWS Session Tokens </li> |
11 | 14 | </ul>
|
12 |
| -<h2>Recommended Secure Coding Practices</h2> |
13 |
| -<p>Only administrators should have access to the AWS credentials used by your application.</p> |
14 |
| -<p>As a consequence, AWS credentials should not be stored along with the application code as they would grant special privilege to anyone who has |
15 |
| -access to the application source code.</p> |
16 |
| -<p>Credentials should be stored outside of the code in a file that is never committed to your application code repository.</p> |
17 |
| -<p>If possible, a better alternative is to use your cloud provider’s service for managing secrets. On AWS this service is called <a |
18 |
| -href="https://aws.amazon.com/fr/secrets-manager/">Secrets Manager</a>.</p> |
19 |
| -<p>When credentials are disclosed in the application code, consider them as compromised and revoke them immediately.</p> |
| 15 | +<h3>What is the potential impact?</h3> |
| 16 | +<p>Below are some real-world scenarios that illustrate some impacts of an attacker exploiting the secret.</p> |
| 17 | +<h4>Phishing and spam</h4> |
| 18 | +<p>An attacker can use this secret to spam users or lure them into links to a malicious domain controlled by the attacker.</p> |
| 19 | +<p>Spam can cause users to be exposed to the following:</p> |
| 20 | +<ul> |
| 21 | + <li> Unsolicited, inappropriate content, such as pornographic material </li> |
| 22 | + <li> Fraudulent attempts to trick users into sending information or money </li> |
| 23 | + <li> Abusive or hateful statements </li> |
| 24 | + <li> False advertising or fraudulent claims </li> |
| 25 | +</ul> |
| 26 | +<p>Once a user has been phished on a legitimate-seeming third-party website, an attacker can collect the user’s credentials, bypass multi-factor |
| 27 | +authentication (MFA), and take over the user’s account on the trusted website.</p> |
| 28 | +<h4>Malware distribution</h4> |
| 29 | +<p>Due to this vulnerability, malware can be stored and spread, both to users of the service and to other potential targets.<br> A malware depends on |
| 30 | +the attacker’s intentions, as the following examples show:</p> |
| 31 | +<ul> |
| 32 | + <li> Cryptojacking malware, whose goal is to "mine" cryptocurrencies on the affected computers or servers. </li> |
| 33 | + <li> Spyware that spies out sensitive information from victims. </li> |
| 34 | +</ul> |
| 35 | +<p>In the worst case, malware can cause the target systems to be completely compromised and allow attackers to infiltrate the systems.</p> |
| 36 | +<h4>Financial loss</h4> |
| 37 | +<p>Financial losses can occur when a secret is used to access a paid third-party-provided service and is disclosed as part of the source code of |
| 38 | +client applications. Having the secret, each user of the application will be able to use it without limit to use the third party service to their own |
| 39 | +need, including in a way that was not expected.</p> |
| 40 | +<p>This additional use of the secret will lead to added costs with the service provider.</p> |
| 41 | +<p>Moreover, when rate or volume limiting is set up on the provider side, this additional use can prevent the regular operation of the affected |
| 42 | +application. This might result in a partial denial of service for all the application’s users.</p> |
| 43 | +<h2>How to fix it</h2> |
| 44 | +<p><strong>Revoke the secret</strong></p> |
| 45 | +<p>Revoke any leaked secrets and remove them from the application source code.</p> |
| 46 | +<p>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 |
| 47 | +secret is revoked.</p> |
| 48 | +<p><strong>Use a secret vault</strong></p> |
| 49 | +<p>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 |
| 50 | +disclosure.</p> |
| 51 | +<p>Depending on the development platform and the leaked secret type, multiple solutions are currently available.</p> |
| 52 | +<h3>Code examples</h3> |
| 53 | +<h4>Noncompliant code example</h4> |
| 54 | +<pre data-diff-id="1" data-diff-type="noncompliant"> |
| 55 | +props.set("aws-secret-access-key", "kHeUAwnSUizTWpSbyGAz4f+As5LshPIjvtpswqGb") |
| 56 | +</pre> |
| 57 | +<h4>Compliant solution</h4> |
| 58 | +<pre data-diff-id="1" data-diff-type="compliant"> |
| 59 | +props.set("aws-secret-access-key", System.getenv("AWS_SECRET_ACCESS_KEY")) |
| 60 | +</pre> |
20 | 61 | <h2>Resources</h2>
|
| 62 | +<h3>Standards</h3> |
21 | 63 | <ul>
|
22 |
| - <li> <a href="https://owasp.org/Top10/A07_2021-Identification_and_Authentication_Failures/">OWASP Top 10 2021 Category A7</a> - Identification and |
23 |
| - Authentication Failures </li> |
24 |
| - <li> <a href="https://www.owasp.org/www-project-top-ten/2017/A3_2017-Sensitive_Data_Exposure">OWASP Top 10 2017 Category A3</a> - Sensitive Data |
25 |
| - Exposure </li> |
26 |
| - <li> <a href="https://cwe.mitre.org/data/definitions/798">MITRE, CWE-798</a> - Use of Hard-coded Credentials </li> |
27 |
| - <li> <a href="https://cwe.mitre.org/data/definitions/259">MITRE, CWE-259</a> - Use of Hard-coded Password </li> |
28 |
| - <li> <a href="https://www.sans.org/top25-software-errors/#cat3">SANS Top 25</a> - Porous Defenses </li> |
| 64 | + <li> MITRE - <a href="https://cwe.mitre.org/data/definitions/798">CWE-798 - Use of Hard-coded Credentials</a> </li> |
| 65 | + <li> MITRE - <a href="https://cwe.mitre.org/data/definitions/259">CWE-259 - Use of Hard-coded Password</a> </li> |
| 66 | + <li> SANS - <a href="https://www.sans.org/top25-software-errors/#cat3">TOP 25 Most Dangerous Software Errors</a> </li> |
29 | 67 | </ul>
|
30 | 68 |
|
0 commit comments