Create rule S6758: NPM access tokens should not be disclosed (APPSEC-1064) (#3041)
You can preview this rule [here](https://sonarsource.github.io/rspec/#/rspec/S6758/secrets) (updated a few minutes after each push). ## Review A dedicated reviewer checked the rule description successfully for: - [ ] logical errors and incorrect information - [ ] information gaps and missing content - [ ] text style and tone - [ ] PR summary and labels follow [the guidelines](https://github.com/SonarSource/rspec/#to-modify-an-existing-rule) --------- Co-authored-by: egon-okerman-sonarsource <egon-okerman-sonarsource@users.noreply.github.com> Co-authored-by: Egon Okerman <egon.okerman@sonarsource.com>
This commit is contained in:
parent
d22709e54f
commit
06e4b6313d
1
rules/S6758/metadata.json
Normal file
1
rules/S6758/metadata.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{}
|
56
rules/S6758/secrets/metadata.json
Normal file
56
rules/S6758/secrets/metadata.json
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
{
|
||||||
|
"title": "NPM access tokens should not be disclosed",
|
||||||
|
"type": "VULNERABILITY",
|
||||||
|
"code": {
|
||||||
|
"impacts": {
|
||||||
|
"SECURITY": "HIGH"
|
||||||
|
},
|
||||||
|
"attribute": "TRUSTWORTHY"
|
||||||
|
},
|
||||||
|
"status": "ready",
|
||||||
|
"remediation": {
|
||||||
|
"func": "Constant\/Issue",
|
||||||
|
"constantCost": "30min"
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"cwe",
|
||||||
|
"cert"
|
||||||
|
],
|
||||||
|
"extra": {
|
||||||
|
"replacementRules": []
|
||||||
|
},
|
||||||
|
"defaultSeverity": "Blocker",
|
||||||
|
"ruleSpecification": "RSPEC-6758",
|
||||||
|
"sqKey": "S6758",
|
||||||
|
"scope": "All",
|
||||||
|
"securityStandards": {
|
||||||
|
"CWE": [
|
||||||
|
798,
|
||||||
|
259
|
||||||
|
],
|
||||||
|
"OWASP": [
|
||||||
|
"A3"
|
||||||
|
],
|
||||||
|
"CERT": [
|
||||||
|
"MSC03-J."
|
||||||
|
],
|
||||||
|
"OWASP Top 10 2021": [
|
||||||
|
"A7"
|
||||||
|
],
|
||||||
|
"PCI DSS 3.2": [
|
||||||
|
"6.5.10"
|
||||||
|
],
|
||||||
|
"PCI DSS 4.0": [
|
||||||
|
"6.2.4"
|
||||||
|
],
|
||||||
|
"ASVS 4.0": [
|
||||||
|
"2.10.4",
|
||||||
|
"3.5.2",
|
||||||
|
"6.4.1"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"defaultQualityProfiles": [
|
||||||
|
"Sonar way"
|
||||||
|
],
|
||||||
|
"quickfix": "unknown"
|
||||||
|
}
|
61
rules/S6758/secrets/rule.adoc
Normal file
61
rules/S6758/secrets/rule.adoc
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
include::../../../shared_content/secrets/description.adoc[]
|
||||||
|
|
||||||
|
== Why is this an issue?
|
||||||
|
|
||||||
|
include::../../../shared_content/secrets/rationale.adoc[]
|
||||||
|
|
||||||
|
If an attacker gains access to an NPM access token, they might be able to gain access to any private package linked to this token.
|
||||||
|
|
||||||
|
=== What is the potential impact?
|
||||||
|
|
||||||
|
The exact impact of the compromise of an NPM access token varies depending on the permissions granted to this token. It can range from loss of sensitive data and source code to severe supply chain attacks.
|
||||||
|
|
||||||
|
include::../../../shared_content/secrets/impact/source_code_compromise.adoc[]
|
||||||
|
|
||||||
|
include::../../../shared_content/secrets/impact/supply_chain_attack.adoc[]
|
||||||
|
|
||||||
|
== How to fix it
|
||||||
|
|
||||||
|
include::../../../shared_content/secrets/fix/revoke.adoc[]
|
||||||
|
|
||||||
|
include::../../../shared_content/secrets/fix/vault.adoc[]
|
||||||
|
|
||||||
|
=== Code examples
|
||||||
|
|
||||||
|
==== Noncompliant code example
|
||||||
|
|
||||||
|
[source,yaml,diff-id=1,diff-type=noncompliant]
|
||||||
|
----
|
||||||
|
steps:
|
||||||
|
- run: |
|
||||||
|
npm install
|
||||||
|
- env:
|
||||||
|
NPM_TOKEN: npm_tCEMceczuiTXKQaBjGIaAezYQ63PqI972ANG
|
||||||
|
----
|
||||||
|
|
||||||
|
==== Compliant solution
|
||||||
|
|
||||||
|
[source,yaml,diff-id=1,diff-type=compliant]
|
||||||
|
----
|
||||||
|
steps:
|
||||||
|
- run: |
|
||||||
|
npm install
|
||||||
|
- env:
|
||||||
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
----
|
||||||
|
|
||||||
|
//=== How does this work?
|
||||||
|
|
||||||
|
//=== Pitfalls
|
||||||
|
|
||||||
|
=== Going the extra mile
|
||||||
|
|
||||||
|
include::../../../shared_content/secrets/extra_mile/permissions_scope.adoc[]
|
||||||
|
|
||||||
|
== Resources
|
||||||
|
|
||||||
|
=== Documentation
|
||||||
|
|
||||||
|
npm Docs - https://docs.npmjs.com/revoking-access-tokens[Revoking access tokens]
|
||||||
|
|
||||||
|
include::../../../shared_content/secrets/resources/standards.adoc[]
|
5
shared_content/secrets/extra_mile/permissions_scope.adoc
Normal file
5
shared_content/secrets/extra_mile/permissions_scope.adoc
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
==== Reducing the permission scope per secret
|
||||||
|
|
||||||
|
By reducing the permission scope, the token is granted only the minimum set of permissions required to perform its intended tasks. This follows the principle of least privilege, which states that a user or token should have only the necessary privileges to carry out its specific functions. By adhering to this principle, the potential attack surface is minimized, reducing the risk of unauthorized access or misuse of sensitive resources.
|
||||||
|
|
||||||
|
Additionally, if a token is compromised, the reduced permissions scope limits the potential damage that can be done. With fewer permissions, the attacker's ability to access or modify critical resources is restricted, reducing the impact of the compromise.
|
@ -0,0 +1,5 @@
|
|||||||
|
==== Compromise of sensitive source code
|
||||||
|
|
||||||
|
The affected service is used to store private packages and repositories. If a token is leaked, it can be used by unauthorized individuals to gain access to your sensitive code, proprietary libraries, and other confidential resources. This can lead to intellectual property theft, unauthorized modifications, or even sabotage of your software.
|
||||||
|
|
||||||
|
If these private packages contain other secrets, it might even lead to further breaches in the organization's services.
|
5
shared_content/secrets/impact/supply_chain_attack.adoc
Normal file
5
shared_content/secrets/impact/supply_chain_attack.adoc
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
==== Supply chain attacks
|
||||||
|
|
||||||
|
If the leaked secret gives an attacker the ability to publish code to private packages or repositories under the name of the organization, then there may exist grave consequences beyond the compromise of source code. The attacker may inject malware, backdoors, or other harmful code into these private repositories.
|
||||||
|
|
||||||
|
This can cause further security breaches inside the organization, but will also affect clients if the malicious code gets added to any products. Distributing code that (unintentionally) contains backdoors or malware can lead to widespread security vulnerabilities, reputational damage, and potential legal liabilities.
|
Loading…
x
Reference in New Issue
Block a user