-
Notifications
You must be signed in to change notification settings - Fork 33
SONARTEXT-819 Create rule S6418: Secrets should not be hard-coded #5940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+65
−0
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
59f497a
Add secrets to rule S6418
daniel-teuchert-sonarsource afafe63
Add first draft
daniel-teuchert-sonarsource c012849
Merge branch 'master' into rule/S6418-add-secrets
daniel-teuchert-sonarsource 6a9d37f
Improve description
daniel-teuchert-sonarsource 234e41f
Minor clean up
daniel-teuchert-sonarsource 8715241
Add sentence to distinguish S6418 from S2068
daniel-teuchert-sonarsource 3e6b21d
Add reference to S2068
daniel-teuchert-sonarsource File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "title": "Secrets should not be hard-coded", | ||
| "type": "VULNERABILITY", | ||
| "quickfix": "infeasible", | ||
| "code": { | ||
| "impacts": { | ||
| "SECURITY": "LOW" | ||
| }, | ||
| "attribute": "TRUSTWORTHY" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| == Why is this an issue? | ||
|
|
||
| Hard-coding secrets in source code or binaries makes it easy for attackers to extract sensitive information, especially in distributed or open-source applications. This practice exposes credentials and tokens, increasing the risk of unauthorized access and data breaches. | ||
|
|
||
| This rule detects strings that look like secrets being hard-coded in the source code. | ||
|
|
||
| == How to fix it | ||
|
|
||
| Secrets should be stored in a configuration file that is not committed to the code repository, in a database, or managed by your cloud provider's secrets management service. If a secret is exposed in the source code, it must be rotated immediately. | ||
|
|
||
|
|
||
| === Code Examples | ||
|
|
||
| ==== Noncompliant Code Example | ||
|
|
||
| [source,properties,diff-id=1,diff-type=noncompliant] | ||
| ---- | ||
| api_key=iN1KtmV2xIgdtOs1la7ugo1Pt7gLDjykprJsTELMuULRJQrlBoftwZn92Redve5k // Noncompliant | ||
| ---- | ||
|
|
||
| ==== Compliant Solution | ||
|
|
||
| Use placeholders that will be replaced by the actual secret buy the build system or framework, environment variables or a secrets management service in order to not hard-code secrets in the source code. | ||
|
|
||
| [source,properties,diff-id=1,diff-type=compliant] | ||
| ---- | ||
| api_key=${MY_API_KEY} | ||
| ---- | ||
|
|
||
| == Resources | ||
|
|
||
| * OWASP - https://owasp.org/Top10/A07_2021-Identification_and_Authentication_Failures/[Top 10 2021 Category A7 - Identification and Authentication Failures] | ||
| * OWASP - https://owasp.org/www-project-top-ten/2017/A2_2017-Broken_Authentication[Top 10 2017 Category A2 - Broken Authentication] | ||
| * CWE - https://cwe.mitre.org/data/definitions/798[CWE-798 - Use of Hard-coded Credentials] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.