Compare commits

..

2 Commits

Author SHA1 Message Date
yassin-kammoun-sonarsource
2260648cc8 Update RSPEC 2025-03-25 13:49:04 +01:00
yassin-kammoun-sonarsource
2e607bb4cb Add rust to rule S2185 2025-03-25 12:45:51 +00:00
44 changed files with 248 additions and 854 deletions

View File

@ -44,7 +44,6 @@
* Java JWT * Java JWT
* Java SE * Java SE
* Java JDBC API * Java JDBC API
* Java I/O API
* Jdom2 * Jdom2
* JSP * JSP
* Legacy Mongo Java API * Legacy Mongo Java API

View File

@ -587,8 +587,7 @@
"S6330": "sonar-iac-enterprise 1.1.0.861", "S6330": "sonar-iac-enterprise 1.1.0.861",
"S6332": "sonar-iac-enterprise 1.1.0.861", "S6332": "sonar-iac-enterprise 1.1.0.861",
"S6333": "sonar-iac-enterprise 1.2.0.976", "S6333": "sonar-iac-enterprise 1.2.0.976",
"S6364": "sonar-iac-enterprise 1.4.0.1288", "S6364": "sonar-iac-enterprise 1.4.0.1288"
"S7452": "sonar-iac-enterprise master"
}, },
"COBOL": { "COBOL": {
"S105": "sonar-cobol 4.0.1.2609", "S105": "sonar-cobol 4.0.1.2609",
@ -5191,7 +5190,6 @@
"S1940": "sonar-kotlin 2.0.0.29", "S1940": "sonar-kotlin 2.0.0.29",
"S2053": "sonar-kotlin 2.3.0.609", "S2053": "sonar-kotlin 2.3.0.609",
"S2068": "sonar-kotlin 2.0.0.29", "S2068": "sonar-kotlin 2.0.0.29",
"S2083": "sonar-security master",
"S2097": "sonar-kotlin 2.12.0.1956", "S2097": "sonar-kotlin 2.12.0.1956",
"S2114": "sonar-kotlin 2.12.0.1956", "S2114": "sonar-kotlin 2.12.0.1956",
"S2116": "sonar-kotlin 2.12.0.1956", "S2116": "sonar-kotlin 2.12.0.1956",
@ -5223,7 +5221,6 @@
"S5322": "sonar-kotlin 2.3.0.609", "S5322": "sonar-kotlin 2.3.0.609",
"S5324": "sonar-kotlin 2.2.0.499", "S5324": "sonar-kotlin 2.2.0.499",
"S5332": "sonar-kotlin 2.0.0.29", "S5332": "sonar-kotlin 2.0.0.29",
"S5344": "sonar-kotlin master",
"S5527": "sonar-kotlin 2.0.0.29", "S5527": "sonar-kotlin 2.0.0.29",
"S5542": "sonar-kotlin 2.0.0.29", "S5542": "sonar-kotlin 2.0.0.29",
"S5547": "sonar-kotlin 2.0.0.29", "S5547": "sonar-kotlin 2.0.0.29",
@ -5237,7 +5234,6 @@
"S5867": "sonar-kotlin 2.6.0.862", "S5867": "sonar-kotlin 2.6.0.862",
"S5868": "sonar-kotlin 2.6.0.862", "S5868": "sonar-kotlin 2.6.0.862",
"S5869": "sonar-kotlin 2.6.0.862", "S5869": "sonar-kotlin 2.6.0.862",
"S6096": "sonar-security master",
"S6202": "sonar-kotlin 2.4.0.703", "S6202": "sonar-kotlin 2.4.0.703",
"S6207": "sonar-kotlin 2.15.0.2579", "S6207": "sonar-kotlin 2.15.0.2579",
"S6218": "sonar-kotlin 2.4.0.703", "S6218": "sonar-kotlin 2.4.0.703",
@ -5260,7 +5256,6 @@
"S6318": "sonar-kotlin 2.1.0.344", "S6318": "sonar-kotlin 2.1.0.344",
"S6362": "sonar-kotlin 2.5.0.754", "S6362": "sonar-kotlin 2.5.0.754",
"S6363": "sonar-kotlin 2.5.0.754", "S6363": "sonar-kotlin 2.5.0.754",
"S6384": "sonar-security master",
"S6432": "sonar-kotlin 2.11.0.1828", "S6432": "sonar-kotlin 2.11.0.1828",
"S6474": "sonar-kotlin master", "S6474": "sonar-kotlin master",
"S6508": "sonar-kotlin 2.14.0.2352", "S6508": "sonar-kotlin 2.14.0.2352",
@ -5294,9 +5289,7 @@
"S6634": "sonar-kotlin 2.16.0.2832", "S6634": "sonar-kotlin 2.16.0.2832",
"S7204": "sonar-kotlin master", "S7204": "sonar-kotlin master",
"S7409": "sonar-kotlin master", "S7409": "sonar-kotlin master",
"S7410": "sonar-kotlin master",
"S7416": "sonar-kotlin master", "S7416": "sonar-kotlin master",
"S7435": "sonar-kotlin master",
"S899": "sonar-kotlin 2.12.0.1956" "S899": "sonar-kotlin 2.12.0.1956"
}, },
"KUBERNETES": { "KUBERNETES": {
@ -6822,138 +6815,138 @@
"S7171": "sonar-text-enterprise 2.18.0.4866", "S7171": "sonar-text-enterprise 2.18.0.4866",
"S7174": "sonar-text-enterprise 2.21.0.5225", "S7174": "sonar-text-enterprise 2.21.0.5225",
"S7175": "sonar-text-enterprise 2.21.0.5225", "S7175": "sonar-text-enterprise 2.21.0.5225",
"S7199": "sonar-text-enterprise 2.22.0.5855", "S7199": "sonar-text-enterprise master",
"S7209": "sonar-text-enterprise 2.22.0.5855", "S7209": "sonar-text-enterprise master",
"S7210": "sonar-text-enterprise 2.22.0.5855", "S7210": "sonar-text-enterprise master",
"S7211": "sonar-text-enterprise 2.22.0.5855", "S7211": "sonar-text-enterprise master",
"S7212": "sonar-text-enterprise 2.22.0.5855", "S7212": "sonar-text-enterprise master",
"S7213": "sonar-text-enterprise 2.22.0.5855", "S7213": "sonar-text-enterprise master",
"S7214": "sonar-text-enterprise 2.22.0.5855", "S7214": "sonar-text-enterprise master",
"S7216": "sonar-text-enterprise 2.22.0.5855", "S7216": "sonar-text-enterprise master",
"S7217": "sonar-text-enterprise 2.22.0.5855", "S7217": "sonar-text-enterprise master",
"S7218": "sonar-text-enterprise 2.22.0.5855", "S7218": "sonar-text-enterprise master",
"S7219": "sonar-text-enterprise 2.22.0.5855", "S7219": "sonar-text-enterprise master",
"S7220": "sonar-text-enterprise 2.22.0.5855", "S7220": "sonar-text-enterprise master",
"S7221": "sonar-text-enterprise 2.22.0.5855", "S7221": "sonar-text-enterprise master",
"S7222": "sonar-text-enterprise 2.22.0.5855", "S7222": "sonar-text-enterprise master",
"S7223": "sonar-text-enterprise 2.22.0.5855", "S7223": "sonar-text-enterprise master",
"S7225": "sonar-text-enterprise 2.22.0.5855", "S7225": "sonar-text-enterprise master",
"S7226": "sonar-text-enterprise 2.22.0.5855", "S7226": "sonar-text-enterprise master",
"S7227": "sonar-text-enterprise 2.22.0.5855", "S7227": "sonar-text-enterprise master",
"S7228": "sonar-text-enterprise 2.22.0.5855", "S7228": "sonar-text-enterprise master",
"S7229": "sonar-text-enterprise 2.22.0.5855", "S7229": "sonar-text-enterprise master",
"S7231": "sonar-text-enterprise 2.22.0.5855", "S7231": "sonar-text-enterprise master",
"S7232": "sonar-text-enterprise 2.22.0.5855", "S7232": "sonar-text-enterprise master",
"S7235": "sonar-text-enterprise 2.22.0.5855", "S7235": "sonar-text-enterprise master",
"S7236": "sonar-text-enterprise 2.22.0.5855", "S7236": "sonar-text-enterprise master",
"S7237": "sonar-text-enterprise 2.22.0.5855", "S7237": "sonar-text-enterprise master",
"S7238": "sonar-text-enterprise 2.22.0.5855", "S7238": "sonar-text-enterprise master",
"S7240": "sonar-text-enterprise 2.22.0.5855", "S7240": "sonar-text-enterprise master",
"S7243": "sonar-text-enterprise 2.22.0.5855", "S7243": "sonar-text-enterprise master",
"S7246": "sonar-text-enterprise 2.22.0.5855", "S7246": "sonar-text-enterprise master",
"S7248": "sonar-text-enterprise 2.22.0.5855", "S7248": "sonar-text-enterprise master",
"S7249": "sonar-text-enterprise 2.22.0.5855", "S7249": "sonar-text-enterprise master",
"S7250": "sonar-text-enterprise 2.22.0.5855", "S7250": "sonar-text-enterprise master",
"S7251": "sonar-text-enterprise 2.22.0.5855", "S7251": "sonar-text-enterprise master",
"S7252": "sonar-text-enterprise 2.22.0.5855", "S7252": "sonar-text-enterprise master",
"S7256": "sonar-text-enterprise 2.22.0.5855", "S7256": "sonar-text-enterprise master",
"S7258": "sonar-text-enterprise 2.22.0.5855", "S7258": "sonar-text-enterprise master",
"S7259": "sonar-text-enterprise 2.22.0.5855", "S7259": "sonar-text-enterprise master",
"S7260": "sonar-text-enterprise 2.22.0.5855", "S7260": "sonar-text-enterprise master",
"S7261": "sonar-text-enterprise 2.22.0.5855", "S7261": "sonar-text-enterprise master",
"S7262": "sonar-text-enterprise 2.22.0.5855", "S7262": "sonar-text-enterprise master",
"S7263": "sonar-text-enterprise 2.22.0.5855", "S7263": "sonar-text-enterprise master",
"S7264": "sonar-text-enterprise 2.22.0.5855", "S7264": "sonar-text-enterprise master",
"S7268": "sonar-text-enterprise 2.22.0.5855", "S7268": "sonar-text-enterprise master",
"S7269": "sonar-text-enterprise 2.22.0.5855", "S7269": "sonar-text-enterprise master",
"S7270": "sonar-text-enterprise 2.22.0.5855", "S7270": "sonar-text-enterprise master",
"S7271": "sonar-text-enterprise 2.22.0.5855", "S7271": "sonar-text-enterprise master",
"S7272": "sonar-text-enterprise 2.22.0.5855", "S7272": "sonar-text-enterprise master",
"S7273": "sonar-text-enterprise 2.22.0.5855", "S7273": "sonar-text-enterprise master",
"S7275": "sonar-text-enterprise 2.22.0.5855", "S7275": "sonar-text-enterprise master",
"S7276": "sonar-text-enterprise 2.22.0.5855", "S7276": "sonar-text-enterprise master",
"S7277": "sonar-text-enterprise 2.22.0.5855", "S7277": "sonar-text-enterprise master",
"S7278": "sonar-text-enterprise 2.22.0.5855", "S7278": "sonar-text-enterprise master",
"S7279": "sonar-text-enterprise 2.22.0.5855", "S7279": "sonar-text-enterprise master",
"S7280": "sonar-text-enterprise 2.22.0.5855", "S7280": "sonar-text-enterprise master",
"S7282": "sonar-text-enterprise 2.22.0.5855", "S7282": "sonar-text-enterprise master",
"S7283": "sonar-text-enterprise 2.22.0.5855", "S7283": "sonar-text-enterprise master",
"S7285": "sonar-text-enterprise 2.22.0.5855", "S7285": "sonar-text-enterprise master",
"S7286": "sonar-text-enterprise 2.22.0.5855", "S7286": "sonar-text-enterprise master",
"S7287": "sonar-text-enterprise 2.22.0.5855", "S7287": "sonar-text-enterprise master",
"S7288": "sonar-text-enterprise 2.22.0.5855", "S7288": "sonar-text-enterprise master",
"S7289": "sonar-text-enterprise 2.22.0.5855", "S7289": "sonar-text-enterprise master",
"S7291": "sonar-text-enterprise 2.22.0.5855", "S7291": "sonar-text-enterprise master",
"S7292": "sonar-text-enterprise 2.22.0.5855", "S7292": "sonar-text-enterprise master",
"S7294": "sonar-text-enterprise 2.22.0.5855", "S7294": "sonar-text-enterprise master",
"S7295": "sonar-text-enterprise 2.22.0.5855", "S7295": "sonar-text-enterprise master",
"S7296": "sonar-text-enterprise 2.22.0.5855", "S7296": "sonar-text-enterprise master",
"S7301": "sonar-text-enterprise 2.22.0.5855", "S7301": "sonar-text-enterprise master",
"S7302": "sonar-text-enterprise 2.22.0.5855", "S7302": "sonar-text-enterprise master",
"S7306": "sonar-text-enterprise 2.22.0.5855", "S7306": "sonar-text-enterprise master",
"S7307": "sonar-text-enterprise 2.22.0.5855", "S7307": "sonar-text-enterprise master",
"S7308": "sonar-text-enterprise 2.22.0.5855", "S7308": "sonar-text-enterprise master",
"S7309": "sonar-text-enterprise 2.22.0.5855", "S7309": "sonar-text-enterprise master",
"S7312": "sonar-text-enterprise 2.22.0.5855", "S7312": "sonar-text-enterprise master",
"S7317": "sonar-text-enterprise 2.22.0.5855", "S7317": "sonar-text-enterprise master",
"S7319": "sonar-text-enterprise 2.22.0.5855", "S7319": "sonar-text-enterprise master",
"S7322": "sonar-text-enterprise 2.22.0.5855", "S7322": "sonar-text-enterprise master",
"S7323": "sonar-text-enterprise 2.22.0.5855", "S7323": "sonar-text-enterprise master",
"S7324": "sonar-text-enterprise 2.22.0.5855", "S7324": "sonar-text-enterprise master",
"S7325": "sonar-text-enterprise 2.22.0.5855", "S7325": "sonar-text-enterprise master",
"S7327": "sonar-text-enterprise 2.22.0.5855", "S7327": "sonar-text-enterprise master",
"S7328": "sonar-text-enterprise 2.22.0.5855", "S7328": "sonar-text-enterprise master",
"S7329": "sonar-text-enterprise 2.22.0.5855", "S7329": "sonar-text-enterprise master",
"S7330": "sonar-text-enterprise 2.22.0.5855", "S7330": "sonar-text-enterprise master",
"S7331": "sonar-text-enterprise 2.22.0.5855", "S7331": "sonar-text-enterprise master",
"S7332": "sonar-text-enterprise 2.22.0.5855", "S7332": "sonar-text-enterprise master",
"S7333": "sonar-text-enterprise 2.22.0.5855", "S7333": "sonar-text-enterprise master",
"S7334": "sonar-text-enterprise 2.22.0.5855", "S7334": "sonar-text-enterprise master",
"S7335": "sonar-text-enterprise 2.22.0.5855", "S7335": "sonar-text-enterprise master",
"S7338": "sonar-text-enterprise 2.22.0.5855", "S7338": "sonar-text-enterprise master",
"S7340": "sonar-text-enterprise 2.22.0.5855", "S7340": "sonar-text-enterprise master",
"S7343": "sonar-text-enterprise 2.22.0.5855", "S7343": "sonar-text-enterprise master",
"S7344": "sonar-text-enterprise 2.22.0.5855", "S7344": "sonar-text-enterprise master",
"S7346": "sonar-text-enterprise 2.22.0.5855", "S7346": "sonar-text-enterprise master",
"S7348": "sonar-text-enterprise 2.22.0.5855", "S7348": "sonar-text-enterprise master",
"S7349": "sonar-text-enterprise 2.22.0.5855", "S7349": "sonar-text-enterprise master",
"S7350": "sonar-text-enterprise 2.22.0.5855", "S7350": "sonar-text-enterprise master",
"S7351": "sonar-text-enterprise 2.22.0.5855", "S7351": "sonar-text-enterprise master",
"S7352": "sonar-text-enterprise 2.22.0.5855", "S7352": "sonar-text-enterprise master",
"S7353": "sonar-text-enterprise 2.22.0.5855", "S7353": "sonar-text-enterprise master",
"S7354": "sonar-text-enterprise 2.22.0.5855", "S7354": "sonar-text-enterprise master",
"S7355": "sonar-text-enterprise 2.22.0.5855", "S7355": "sonar-text-enterprise master",
"S7356": "sonar-text-enterprise 2.22.0.5855", "S7356": "sonar-text-enterprise master",
"S7357": "sonar-text-enterprise 2.22.0.5855", "S7357": "sonar-text-enterprise master",
"S7360": "sonar-text-enterprise 2.22.0.5855", "S7360": "sonar-text-enterprise master",
"S7361": "sonar-text-enterprise 2.22.0.5855", "S7361": "sonar-text-enterprise master",
"S7362": "sonar-text-enterprise 2.22.0.5855", "S7362": "sonar-text-enterprise master",
"S7364": "sonar-text-enterprise 2.22.0.5855", "S7364": "sonar-text-enterprise master",
"S7365": "sonar-text-enterprise 2.22.0.5855", "S7365": "sonar-text-enterprise master",
"S7366": "sonar-text-enterprise 2.22.0.5855", "S7366": "sonar-text-enterprise master",
"S7367": "sonar-text-enterprise 2.22.0.5855", "S7367": "sonar-text-enterprise master",
"S7368": "sonar-text-enterprise 2.22.0.5855", "S7368": "sonar-text-enterprise master",
"S7369": "sonar-text-enterprise 2.22.0.5855", "S7369": "sonar-text-enterprise master",
"S7374": "sonar-text-enterprise 2.22.0.5855", "S7374": "sonar-text-enterprise master",
"S7375": "sonar-text-enterprise 2.22.0.5855", "S7375": "sonar-text-enterprise master",
"S7376": "sonar-text-enterprise 2.22.0.5855", "S7376": "sonar-text-enterprise master",
"S7378": "sonar-text-enterprise 2.22.0.5855", "S7378": "sonar-text-enterprise master",
"S7383": "sonar-text-enterprise 2.22.0.5855", "S7383": "sonar-text-enterprise master",
"S7386": "sonar-text-enterprise 2.22.0.5855", "S7386": "sonar-text-enterprise master",
"S7387": "sonar-text-enterprise 2.22.0.5855", "S7387": "sonar-text-enterprise master",
"S7389": "sonar-text-enterprise 2.22.0.5855", "S7389": "sonar-text-enterprise master",
"S7390": "sonar-text-enterprise 2.22.0.5855", "S7390": "sonar-text-enterprise master",
"S7391": "sonar-text-enterprise 2.22.0.5855", "S7391": "sonar-text-enterprise master",
"S7392": "sonar-text-enterprise 2.22.0.5855", "S7392": "sonar-text-enterprise master",
"S7393": "sonar-text-enterprise 2.22.0.5855", "S7393": "sonar-text-enterprise master",
"S7394": "sonar-text-enterprise 2.22.0.5855", "S7394": "sonar-text-enterprise master",
"S7395": "sonar-text-enterprise 2.22.0.5855", "S7395": "sonar-text-enterprise master",
"S7396": "sonar-text-enterprise 2.22.0.5855", "S7396": "sonar-text-enterprise master",
"S7397": "sonar-text-enterprise 2.22.0.5855", "S7397": "sonar-text-enterprise master",
"S7398": "sonar-text-enterprise 2.22.0.5855", "S7398": "sonar-text-enterprise master",
"S7400": "sonar-text-enterprise 2.22.0.5855", "S7400": "sonar-text-enterprise master",
"S7401": "sonar-text-enterprise 2.22.0.5855", "S7401": "sonar-text-enterprise master",
"S7402": "sonar-text-enterprise 2.22.0.5855" "S7402": "sonar-text-enterprise master"
}, },
"SWIFT": { "SWIFT": {
"S100": "sonar-swift 3.1.0.2067", "S100": "sonar-swift 3.1.0.2067",
@ -7127,8 +7120,7 @@
"S6410": "sonar-iac-enterprise 1.6.0.1852", "S6410": "sonar-iac-enterprise 1.6.0.1852",
"S6412": "sonar-iac-enterprise 1.7.0.2012", "S6412": "sonar-iac-enterprise 1.7.0.2012",
"S6413": "sonar-iac-enterprise 1.7.0.2012", "S6413": "sonar-iac-enterprise 1.7.0.2012",
"S6414": "sonar-iac-enterprise 1.7.0.2012", "S6414": "sonar-iac-enterprise 1.7.0.2012"
"S7452": "sonar-iac-enterprise master"
}, },
"TEXT": { "TEXT": {
"S6389": "sonar-text-enterprise 2.6.1.1316", "S6389": "sonar-text-enterprise 2.6.1.1316",

View File

@ -4,10 +4,6 @@ include::../ask-yourself.adoc[]
include::../recommended.adoc[] include::../recommended.adoc[]
=== Exceptions
* The rule ignores string literals that are used directly in Regexp methods.
== Sensitive Code Example == Sensitive Code Example
---- ----

View File

@ -1,4 +1,4 @@
== How to fix it in Java I/O API == How to fix it in Java SE
=== Code examples === Code examples
@ -67,7 +67,7 @@ that the string `targetDirectory` does not end with a path separator:
static private String targetDirectory = "/Users/John"; static private String targetDirectory = "/Users/John";
@GetMapping(value = "/endpoint") @GetMapping(value = "/endpoint")
public void endpoint(@RequestParam("folder") File fileName) throws IOException { public void endpoint(@RequestParam("folder") fileName) throws IOException {
String canonicalizedFileName = fileName.getCanonicalPath(); String canonicalizedFileName = fileName.getCanonicalPath();

View File

@ -6,7 +6,7 @@ include::../impact.adoc[]
// How to fix it section // How to fix it section
include::how-to-fix-it/java-io-api.adoc[] include::how-to-fix-it/java-se.adoc[]
== Resources == Resources

View File

@ -1,94 +0,0 @@
== How to fix it in Java I/O API
=== Code examples
:code_impact: delete
include::../../common/fix/code-rationale.adoc[]
==== Noncompliant code example
[source,kotlin,diff-id=1,diff-type=noncompliant]
----
@Controller
class ExampleController {
companion object {
private const val TARGET_DIRECTORY = "/path/to/target/directory/"
}
@GetMapping("/delete")
fun delete(@RequestParam("filename") filename: String) {
val file = File(TARGET_DIRECTORY + filename)
file.delete()
}
}
----
==== Compliant solution
[source,kotlin,diff-id=1,diff-type=compliant]
----
@Controller
class ExampleController {
companion object {
private const val TARGET_DIRECTORY = "/path/to/target/directory/"
private val TARGET_PATH = File(TARGET_DIRECTORY).toPath().normalize()
}
@GetMapping("/delete")
fun delete(@RequestParam("filename") filename: String) {
val file = File(TARGET_PATH.toString() + filename)
if (!file.toPath().normalize().startsWith(TARGET_PATH)) {
throw IOException("Entry is outside of the target directory")
}
file.delete()
}
}
----
=== How does this work?
:canonicalization_function: java.io.File.getCanonicalPath
include::../../common/fix/self-validation.adoc[]
=== Pitfalls
include::../../common/pitfalls/partial-path-traversal.adoc[]
For example, the following code is vulnerable to partial path injection. Note
that the string `targetDirectory` does not end with a path separator:
[source, kotlin]
----
companion object {
private val targetDirectory: String = "/Users/John"
}
@GetMapping("/endpoint")
fun endpoint(@RequestParam("folder") file: File) {
val canonicalizedFileName = file.getCanonicalPath()
if (!canonicalizedFileName .startsWith(targetDirectory)) {
throw IOException("Entry is outside of the target directory");
}
file.delete()
}
----
This check can be bypassed because `"/Users/Johnny".startsWith("/Users/John")`
returns `true`. Thus, for validation, `"/Users/John"` should actually be
`"/Users/John/"`.
**Warning**: Some functions, such as `.getCanonicalPath`, remove the
terminating path separator in their return value. +
The validation code should be tested to ensure that it cannot be impacted by this
issue.
https://github.com/aws/aws-sdk-java/security/advisories/GHSA-c28r-hw5m-5gv3[Here is a real-life example of this vulnerability.]
:joining_docs: https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html
:joining_func: java.nio.file.Path.resolve
include::../../common/pitfalls/oob-specific-path-joining.adoc[]

View File

@ -1,33 +0,0 @@
{
"securityStandards": {
"CWE": [
20,
22
],
"OWASP": [
"A5",
"A1"
],
"OWASP Top 10 2021": [
"A1",
"A3"
],
"OWASP Mobile Top 10 2024": [
"M4"
],
"PCI DSS 3.2": [
"6.5.8"
],
"PCI DSS 4.0": [
"6.2.4"
],
"ASVS 4.0": [
"12.3.1",
"5.1.3",
"5.1.4"
],
"STIG ASD_V5R3": [
"V-222609"
]
}
}

View File

@ -1,29 +0,0 @@
== Why is this an issue?
include::../rationale.adoc[]
include::../impact.adoc[]
// How to fix it section
include::how-to-fix-it/java-io-api.adoc[]
== Resources
include::../common/resources/standards-mobile.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]

View File

@ -1,30 +1,2 @@
{ {
"title": "Do not perform unnecessary mathematical operations",
"type": "CODE_SMELL",
"code": {
"impacts": {
"MAINTAINABILITY": "MEDIUM"
},
"attribute": "LOGICAL"
},
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "15min"
},
"tags": [
"clumsy"
],
"extra": {
"replacementRules": [],
"legacyKeys": []
},
"defaultSeverity": "Major",
"ruleSpecification": "RSPEC-2185",
"sqKey": "S2185",
"scope": "All",
"defaultQualityProfiles": [
"Sonar way"
],
"quickfix": "unknown"
} }

View File

@ -1,2 +1,30 @@
{ {
"title": "Do not perform unnecessary mathematical operations",
"type": "CODE_SMELL",
"code": {
"impacts": {
"MAINTAINABILITY": "MEDIUM"
},
"attribute": "LOGICAL"
},
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "15min"
},
"tags": [
"clumsy"
],
"extra": {
"replacementRules": [],
"legacyKeys": []
},
"defaultSeverity": "Major",
"ruleSpecification": "RSPEC-2185",
"sqKey": "S2185",
"scope": "All",
"defaultQualityProfiles": [
"Sonar way"
],
"quickfix": "unknown"
} }

View File

@ -0,0 +1,7 @@
{
"title": "Erasing mathematical operations should not be performed",
"tags": [
"clumsy",
"clippy"
]
}

View File

@ -0,0 +1,26 @@
== Why is this an issue?
Erasing operations (e.g., any operation involving multiplying by zero, dividing zero by a value, or bitwise AND with zero) always result in zero regardless of the operands, which makes the expression unnecessary and can be replaced directly with zero. This simplifies the code and avoids potential confusion about the intent of the expression.
=== Code examples
==== Noncompliant code example
[source,rust,diff-id=1,diff-type=noncompliant]
----
let x = 1;
let result = 0 * x; // Noncompliant: Result is always zero.
----
==== Compliant solution
[source,rust,diff-id=1,diff-type=compliant]
----
let x = 1;
let result = 0; // Compliant: Simplified expression.
----
== Resources
=== Documentation
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#erasing_op

View File

@ -1,2 +0,0 @@
{
}

View File

@ -1,13 +0,0 @@
include::../intro.adoc[]
== Why is this an issue?
include::../why.adoc[]
=== What is the potential impact?
include::../impact.adoc[]
include::../resources.adoc[]
include::../rspecator.adoc[]

View File

@ -1,6 +0,0 @@
=== Highlighting
* Main location: The `iteration` argument of the PBEKeySpec constructor call
* Secondary location
** The location where the `iteration` argument value is assigned
** The location where the `algorithm` argument value of SecretKeyFactory.getInstance is assigned

View File

@ -1,6 +0,0 @@
=== Message
* For PBKDF2: "Use at least ``+{min_iterations}+`` PBKDF2 iterations"
** If `algorithm` is `"PBKDF2withHmacSHA1"`, then min_iterations is 1,300,000
** If `algorithm` is `"PBKDF2withHmacSHA256"`, then min_iterations is 600,000
** If `algorithm` is `"PBKDF2withHmacSHA512"`, then min_iterations is 210,000

View File

@ -1,35 +0,0 @@
{
"securityStandards": {
"CWE": [
256,
916
],
"OWASP": [
"A3"
],
"OWASP Top 10 2021": [
"A2",
"A4"
],
"OWASP Mobile Top 10 2024": [
"M10"
],
"PCI DSS 3.2": [
"6.5.3"
],
"PCI DSS 4.0": [
"6.2.4"
],
"ASVS 4.0": [
"2.10.3",
"2.4.1",
"2.4.2",
"2.4.3",
"2.4.4",
"2.4.5"
],
"STIG ASD_V5R3": [
"V-222542"
]
}
}

View File

@ -1,65 +0,0 @@
include::../summary.adoc[]
== Why is this an issue?
include::../rationale.adoc[]
include::../impact.adoc[]
== How to fix it in Java Cryptography Extension
=== Code examples
==== Noncompliant code example
The derived key is vulnerable because the cost factor (rounds) is too low for the chosen algorithm.
[source,kotlin,diff-id=1,diff-type=noncompliant]
----
private fun deriveKey(password: String, salt: ByteArray): SecretKey? {
val keySpec = PBEKeySpec(password.toCharArray(), salt, 120000, 256) // Noncompliant
val secretKeyFactory = SecretKeyFactory.getInstance("PBKDF2withHmacSHA512")
return secretKeyFactory.generateSecret(keySpec)
}
----
==== Compliant solution
[source,kotlin,diff-id=1,diff-type=compliant]
----
private fun deriveKey(password: String, salt: ByteArray): SecretKey? {
val keySpec = PBEKeySpec(password.toCharArray(), salt, 210000, 256)
val secretKeyFactory = SecretKeyFactory.getInstance("PBKDF2withHmacSHA512")
return secretKeyFactory.generateSecret(keySpec)
}
----
=== How does this work?
include::../common/fix/pbkdf2-parameters.adoc[]
=== Going the extra mile
include::../common/extra-mile/peppering.adoc[]
== Resources
=== Documentation
* OWASP CheatSheet - https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html[Password Storage Cheat Sheet]
include::../common/resources/standards-mobile.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::highlighting.adoc[]
endif::env-github,rspecator-view[]

View File

@ -6,7 +6,6 @@ include::../recommended.adoc[]
== Sensitive Code Example == Sensitive Code Example
[source,cpp]
---- ----
#include <cstdio> #include <cstdio>
// ... // ...
@ -16,7 +15,6 @@ void f() {
} }
---- ----
[source,cpp]
---- ----
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>

View File

@ -1,4 +1,4 @@
== How to fix it in Java I/O API == How to fix it in Java SE
=== Code examples === Code examples

View File

@ -4,7 +4,7 @@ include::../rationale.adoc[]
include::../impact.adoc[] include::../impact.adoc[]
include::how-to-fix-it/java-io-api.adoc[] include::how-to-fix-it/java-se.adoc[]
== Resources == Resources

View File

@ -1,90 +0,0 @@
== How to fix it in Java I/O API
=== Code examples
:canonicalization_function1: java.io.File.getCanonicalFile
:canonicalization_function2: java.io.File.getCanonicalPath
include::../../common/fix/code-rationale.adoc[]
==== Noncompliant code example
[source,kotlin,diff-id=1,diff-type=noncompliant]
----
class Example {
companion object {
private const val TARGET_DIRECTORY = "/example/directory/"
}
fun extractEntry(zipFile: ZipFile) {
val entries = zipFile.entries()
val entry = entries.nextElement()
val inputStream = zipFile.getInputStream(entry)
val file = File(TARGET_DIRECTORY + entry.name)
inputStream.copyTo(file.outputStream())
}
}
----
==== Compliant solution
[source,kotlin,diff-id=1,diff-type=compliant]
----
class Example {
companion object {
private const val TARGET_DIRECTORY = "/example/directory/"
}
fun extractEntry(zipFile: ZipFile) {
val entries = zipFile.entries()
val entry = entries.nextElement()
val inputStream = zipFile.getInputStream(entry)
val file = File(TARGET_DIRECTORY + entry.name)
val canonicalDestinationPath = file.canonicalPath
if (canonicalDestinationPath.startsWith(TARGET_DIRECTORY)) {
inputStream.copyTo(file.outputStream())
}
}
}
----
=== How does this work?
include::../../common/fix/how-does-this-work.adoc[]
=== Pitfalls
include::../../common/pitfalls/partial-path-traversal.adoc[]
For example, the following code is vulnerable to partial path injection. Note
that the string `targetDirectory` does not end with a path separator:
[source, kotlin]
----
companion object {
private const val targetDirectory = "/Users/John"
}
fun ExtractEntry(zipFile: ZipFile) {
val entries = zipFile.entries()
val entry = entries.nextElement()
val inputStream = zipFile.getInputStream(entry)
val file = File(entry.name)
val canonicalDestinationPath = file.canonicalPath
if (canonicalDestinationPath.startsWith(targetDirectory)) {
Files.copy(inputStream, file.toPath(), StandardCopyOption.REPLACE_EXISTING, LinkOption.NOFOLLOW_LINKS)
}
}
----
This check can be bypassed because `"/Users/Johnny".startsWith("/Users/John")`
returns `true`. Thus, for validation, `"/Users/John"` should actually be
`"/Users/John/"`.
**Warning**: Some functions, such as `.getCanonicalPath`, remove the
terminating path separator in their return value. +
The validation code should be tested to ensure that it cannot be impacted by this
issue.
https://github.com/aws/aws-sdk-java/security/advisories/GHSA-c28r-hw5m-5gv3[Here is a real-life example of this vulnerability.]

View File

@ -1,34 +0,0 @@
{
"securityStandards": {
"CWE": [
20,
22
],
"OWASP": [
"A5",
"A1"
],
"OWASP Top 10 2021": [
"A1",
"A3"
],
"OWASP Mobile Top 10 2024": [
"M4"
],
"PCI DSS 3.2": [
"6.5.1",
"6.5.8"
],
"PCI DSS 4.0": [
"6.2.4"
],
"ASVS 4.0": [
"12.3.4",
"5.1.3",
"5.1.4"
],
"STIG ASD_V5R3": [
"V-222609"
]
}
}

View File

@ -1,23 +0,0 @@
== Why is this an issue?
include::../rationale.adoc[]
include::../impact.adoc[]
include::how-to-fix-it/java-io-api.adoc[]
== Resources
include::../common/resources/articles.adoc[]
include::../common/resources/standards-mobile.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
endif::env-github,rspecator-view[]

View File

@ -28,6 +28,8 @@
"ruleSpecification": "RSPEC-6273", "ruleSpecification": "RSPEC-6273",
"sqKey": "S6273", "sqKey": "S6273",
"scope": "Main", "scope": "Main",
"defaultQualityProfiles": [], "defaultQualityProfiles": [
"Sonar way"
],
"quickfix": "unknown" "quickfix": "unknown"
} }

View File

@ -5,6 +5,3 @@
* OWASP - https://owasp.org/www-project-top-ten/2017/A7_2017-Cross-Site_Scripting_(XSS)[Top 10 2017 Category A7 - Cross-Site Scripting (XSS)] * OWASP - https://owasp.org/www-project-top-ten/2017/A7_2017-Cross-Site_Scripting_(XSS)[Top 10 2017 Category A7 - Cross-Site Scripting (XSS)]
* OWASP - https://owasp.org/www-project-mobile-top-10/2023-risks/m8-security-misconfiguration[Mobile Top 10 2024 Category M8 - Security Misconfiguration] * OWASP - https://owasp.org/www-project-mobile-top-10/2023-risks/m8-security-misconfiguration[Mobile Top 10 2024 Category M8 - Security Misconfiguration]
* CWE - https://cwe.mitre.org/data/definitions/79[CWE-79 - Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')] * CWE - https://cwe.mitre.org/data/definitions/79[CWE-79 - Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')]
=== Related rules
* S7409 - Exposing Java objects through JavaScript interfaces is security-sensitive

View File

@ -1,6 +1,6 @@
== Ask Yourself Whether == Ask Yourself Whether
* You open files that may be created or altered by external sources. * No local files have to be accessed by the Webview.
* You open arbitrary URLs from external sources. * The WebView contains untrusted data that could cause harm when rendered.
There is a risk if you answered yes to any of these questions. There is a risk if you answered yes to any of those questions.

View File

@ -1,7 +1,7 @@
Exposing the Android file system to WebViews is security-sensitive. WebViews can be used to display web content as part of a mobile application. A
browser engine is used to render and display the content. Like a web
application, a mobile application that uses WebViews can be vulnerable to
Cross-Site Scripting if untrusted code is rendered.
Granting file access to WebViews, particularly through the `file://` scheme, introduces a risk of local file inclusion If malicious JavaScript code in a WebView is executed this can leak the contents
vulnerabilities. The severity of this risk depends heavily on the specific `WebSettings` configured. Overly permissive of sensitive files when access to local files is enabled.
settings can allow malicious scripts to access a wide range of local files, potentially exposing sensitive data such as
Personally Identifiable Information (PII) or private application data, leading to data breaches and other security
compromises.

View File

@ -8,67 +8,27 @@ include::../recommended.adoc[]
[source,kotlin] [source,kotlin]
---- ----
AndroidView( import android.webkit.WebView
factory = { context ->
WebView(context).apply { val webView: WebView = findViewById(R.id.webview)
webViewClient = WebViewClient() webView.getSettings().setAllowContentAccess(true) // Sensitive
settings.apply { webView.getSettings().setAllowFileAccess(true) // Sensitive
allowFileAccess = true // Sensitive
allowFileAccessFromFileURLs = true // Sensitive
allowUniversalAccessFromFileURLs = true // Sensitive
allowContentAccess = true // Sensitive
}
loadUrl("file:///android_asset/example.html")
}
}
)
---- ----
== Compliant Solution == Compliant Solution
[source,kotlin] [source,kotlin]
---- ----
AndroidView( import android.webkit.WebView
factory = { context ->
val webView = WebView(context)
val assetLoader = WebViewAssetLoader.Builder()
.addPathHandler("/assets/", WebViewAssetLoader.AssetsPathHandler(context))
.build()
webView.webViewClient = object : WebViewClient() { val webView: WebView = findViewById(R.id.webview)
@RequiresApi(Build.VERSION_CODES.LOLLIPOP) webView.getSettings().setAllowContentAccess(false)
override fun shouldInterceptRequest(view: WebView?, request: WebResourceRequest): WebResourceResponse? { webView.getSettings().setAllowFileAccess(false)
return assetLoader.shouldInterceptRequest(request.url)
}
@Suppress("deprecation")
override fun shouldInterceptRequest(view: WebView?, url: String?): WebResourceResponse? {
return assetLoader.shouldInterceptRequest(Uri.parse(url))
}
}
webView.settings.apply {
allowFileAccess = false
allowFileAccessFromFileURLs = false
allowUniversalAccessFromFileURLs = false
allowContentAccess = false
}
webView.loadUrl("https://appassets.androidplatform.net/assets/example.html")
webView
}
)
---- ----
The compliant solution uses `WebViewAssetLoader` to load local files instead of directly accessing them via `file://`
URLs. This approach serves assets over a secure `https://appassets.androidplatform.net` URL, effectively isolating the
WebView from the local file system.
The file access settings are disabled by default in modern Android versions. To prevent possible security issues in
`Build.VERSION_CODES.Q` and earlier, it is still recommended to explicitly set those values to false.
include::../see.adoc[] include::../see.adoc[]
ifdef::env-github,rspecator-view[] ifdef::env-github,rspecator-view[]
''' '''

View File

@ -26,8 +26,8 @@
79 79
], ],
"OWASP": [ "OWASP": [
"A3", "A6",
"A6" "A7"
], ],
"MASVS": [ "MASVS": [
"MSTG-PLATFORM-2" "MSTG-PLATFORM-2"
@ -36,7 +36,7 @@
"M8" "M8"
], ],
"OWASP Top 10 2021": [ "OWASP Top 10 2021": [
"A1" "A3"
], ],
"PCI DSS 3.2": [ "PCI DSS 3.2": [
"6.5.1", "6.5.1",

View File

@ -1,7 +1,6 @@
== Recommended Secure Coding Practices == Recommended Secure Coding Practices
Avoid opening `file://` URLs from external sources in WebView components. If your application accepts arbitrary URLs It is recommended to disable access to local files for WebViews unless it is
from external sources, do not enable this functionality. Instead, utilize `androidx.webkit.WebViewAssetLoader` to access necessary. In the case of a successful attack through a Cross-Site Scripting
files, including assets and resources, via `http(s)://` schemes. vulnerability the attackers attack surface decreases drastically if no files
can be read out.
For enhanced security, ensure that the options to load `file://` URLs are explicitly set to false.

View File

@ -1,9 +1,7 @@
== See == See
* OWASP - https://owasp.org/Top10/A01_2021-Broken_Access_Control/[Top 10 2021 Category A1 - Broken Access Control] * OWASP - https://owasp.org/Top10/A03_2021-Injection/[Top 10 2021 Category A3 - Injection]
* OWASP - https://owasp.org/www-project-top-ten/2017/A3_2017-Sensitive_Data_Exposure[Top 10 2017 Category A3 - Sensitive Data Exposure]
* OWASP - https://owasp.org/www-project-top-ten/2017/A6_2017-Security_Misconfiguration[Top 10 2017 Category A6 - Security Misconfiguration] * OWASP - https://owasp.org/www-project-top-ten/2017/A6_2017-Security_Misconfiguration[Top 10 2017 Category A6 - Security Misconfiguration]
* OWASP - https://owasp.org/www-project-top-ten/2017/A7_2017-Cross-Site_Scripting_(XSS)[Top 10 2017 Category A7 - Cross-Site Scripting (XSS)]
* OWASP - https://owasp.org/www-project-mobile-top-10/2023-risks/m8-security-misconfiguration[Mobile Top 10 2024 Category M8 - Security Misconfiguration] * OWASP - https://owasp.org/www-project-mobile-top-10/2023-risks/m8-security-misconfiguration[Mobile Top 10 2024 Category M8 - Security Misconfiguration]
* OWASP - https://mas.owasp.org/checklists/MASVS-PLATFORM/[Mobile AppSec Verification Standard - Platform Interaction Requirements]
* CWE - https://cwe.mitre.org/data/definitions/79[CWE-79 - Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')] * CWE - https://cwe.mitre.org/data/definitions/79[CWE-79 - Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')]
* Android Documentation - https://developer.android.com/privacy-and-security/risks/webview-unsafe-file-inclusion[WebViews - Unsafe File Inclusion]

View File

@ -7,7 +7,7 @@
}, },
"attribute": "COMPLETE" "attribute": "COMPLETE"
}, },
"status": "closed", "status": "ready",
"remediation": { "remediation": {
"func": "Constant\/Issue", "func": "Constant\/Issue",
"constantCost": "30min" "constantCost": "30min"

View File

@ -1,3 +1,2 @@
{ {
"status": "closed"
} }

View File

@ -1,5 +1,5 @@
{ {
"title": "Exposing Java objects through JavaScript interfaces is security-sensitive", "title": "Exposing Java interfaces in WebViews is security-sensitive",
"type": "SECURITY_HOTSPOT", "type": "SECURITY_HOTSPOT",
"status": "ready", "status": "ready",
"remediation": { "remediation": {

View File

@ -1,15 +1,15 @@
Using JavaScript interfaces in WebViews to expose Java objects is unsafe. Doing so allows JavaScript Using Javascript interfaces in WebViews is unsafe as it allows JavaScript to invoke Java methods,
to invoke Java methods, potentially giving attackers access to data or sensitive app functionality. potentially giving attackers access to data or sensitive app functionality. WebViews might include
WebViews might include untrusted sources such as third-party iframes, making this functionality untrusted sources such as third-party iframes, making this functionality particularly risky. As
particularly risky. As JavaScript interfaces are passed to every frame in the WebView, those iframes Javascript interfaces are passed to every frame in the WebView, those iframes are also able to
are also able to access the exposed Java object. access the exposed Java methods.
== Ask Yourself Whether == Ask Yourself Whether
* The content in the WebView is fully trusted and secure. * The content in the WebView is fully trusted and secure.
* Potentially untrusted iframes could be loaded in the WebView. * Potentially untrusted iframes could be loaded in the WebView.
* The JavaScript interface has to be exposed for the entire lifecycle of the WebView. * The Javascript interface has to be exposed for the entire lifecycle of the WebView.
* The exposed Java object might be called by untrusted sources. * The exposed Java methods will accept input from potentially untrusted sources.
There is a risk if you answered yes to any of these questions. There is a risk if you answered yes to any of these questions.
@ -18,9 +18,9 @@ There is a risk if you answered yes to any of these questions.
=== Disable JavaScript === Disable JavaScript
If it is possible to disable JavaScript in the WebView, this is the most secure option. By default, If it is possible to disable JavaScript in the WebView, this is the most secure option. By default,
JavaScript is disabled in a WebView, so ``webSettings.setJavaScriptEnabled(false)`` does not need to JavaScript is disabled in a WebView, so you do not need to explicitly call
be explicitly called. Of course, sometimes it is necessary to enable JavaScript, in which case the ``webSettings.setJavaScriptEnabled(true)`` in your ``WebSettings`` configuration. Of course, sometimes
following recommendations should be considered. it is necessary to enable JavaScript, in which case the following recommendations should be considered.
=== Remove JavaScript interface when loading untrusted content === Remove JavaScript interface when loading untrusted content
@ -63,8 +63,7 @@ class ExampleActivity : AppCompatActivity() {
== Compliant Solution == Compliant Solution
The most secure option is to disable JavaScript entirely. S6362 further explains why it should not be enabled The most secure option is to disable JavaScript entirely.
unless absolutely necessary.
[source,kotlin] [source,kotlin]
---- ----
@ -97,8 +96,7 @@ class ExampleActivity : AppCompatActivity() {
} }
---- ----
If a JavaScript bridge must be used, consider using ``WebViewCompat.addWebMessageListener`` instead. This allows you to restrict If a JavaScript bridge must be used, consider using ``WebViewCompat.addWebMessageListener`` instead. This allows you to restrict the origins that can send messages to the JavaScript bridge.
the origins that can send messages to the JavaScript bridge.
[source,kotlin] [source,kotlin]
---- ----
@ -137,6 +135,3 @@ class ExampleActivity : AppCompatActivity() {
* OWASP - https://owasp.org/www-project-mobile-top-10/2023-risks/m4-insufficient-input-output-validation.html[Mobile Top 10 2024 Category M4 - Insufficient Input/Output Validation] * OWASP - https://owasp.org/www-project-mobile-top-10/2023-risks/m4-insufficient-input-output-validation.html[Mobile Top 10 2024 Category M4 - Insufficient Input/Output Validation]
* OWASP - https://owasp.org/www-project-mobile-top-10/2023-risks/m8-security-misconfiguration.html[Mobile Top 10 2024 Category M8 - Security Misconfiguration] * OWASP - https://owasp.org/www-project-mobile-top-10/2023-risks/m8-security-misconfiguration.html[Mobile Top 10 2024 Category M8 - Security Misconfiguration]
* CWE - https://cwe.mitre.org/data/definitions/79[CWE-79 - Improper Neutralization of Input During Web Page Generation] * CWE - https://cwe.mitre.org/data/definitions/79[CWE-79 - Improper Neutralization of Input During Web Page Generation]
=== Related rules
* S6362 - Enabling JavaScript support for WebViews is security-sensitive

View File

@ -1,2 +0,0 @@
{
}

View File

@ -1,51 +0,0 @@
include::../description.adoc[]
== How to fix it
=== Code examples
==== Noncompliant code example
[source,yaml,diff-id=1,diff-type=noncompliant]
----
AWSTemplateFormatVersion: 2010-09-09
Resources:
S3Bucket:
Type: 'AWS::S3::Bucket'
Properties:
BucketName: "mybucketname"
Tags:
- Key: "anycompany;cost-center" # Noncompliant, semicolon is not allowed
Value: "Accounting"
- Key: "anycompany:~EnvironmentType~" # Noncompliant, tilde is not allowed
Value: "PROD"
----
==== Compliant solution
[source,yaml,diff-id=1,diff-type=compliant]
----
AWSTemplateFormatVersion: 2010-09-09
Resources:
S3Bucket:
Type: 'AWS::S3::Bucket'
Properties:
BucketName: "mybucketname"
Tags:
- Key: "anycompany:cost-center"
Value: "Accounting"
- Key: "anycompany:EnvironmentType"
Value: "PROD"
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
endif::env-github,rspecator-view[]

View File

@ -1,11 +0,0 @@
Amazon Web Services (AWS) resources tags are metadata labels with keys and optional values used to categorize and manage resources.
== Why is this an issue?
Proper tagging enhances resource discovery, lifecycle management, and overall productivity within the AWS environment. If tags do not comply with the AWS format, it can lead to confusion and inefficiency in managing resources, as well as unexpected behavior of the system.
AWS resource tags should comply with the format stated in AWS documentation. That is, tag keys should:
* Be between 1 and 128 characters long
* Consist of Unicode letters, digits, white spaces, and the following characters: `_ . : / = + - @ "`
* Not start with `aws:`

View File

@ -1,7 +0,0 @@
=== Message
Rename tag key "XXX" to comply with required format.
=== Highlighting
Highlight the key of the tag that has incorrect format.

View File

@ -1,25 +0,0 @@
{
"title": "AWS resource tags should have valid format",
"type": "CODE_SMELL",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "5min"
},
"tags": [
],
"extra": {
},
"defaultSeverity": "Minor",
"ruleSpecification": "RSPEC-7452",
"sqKey": "S7452",
"scope": "All",
"defaultQualityProfiles": ["Sonar way"],
"quickfix": "unknown",
"code": {
"impacts": {
"MAINTAINABILITY": "MEDIUM"
},
"attribute": "FORMATTED"
}
}

View File

@ -1,3 +0,0 @@
== Resources
=== Documentation
* https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html[AWS resource tags]

View File

@ -1,2 +0,0 @@
{
}

View File

@ -1,43 +0,0 @@
include::../description.adoc[]
== How to fix it
=== Code examples
==== Noncompliant code example
[source,terraform,diff-id=1,diff-type=noncompliant]
----
resource "aws_s3_bucket" "examplebucket" {
bucket = "mybucketname"
tags = {
"anycompany:~cost-center~" = "Accounting"
}
}
----
==== Compliant solution
[source,terraform,diff-id=1,diff-type=compliant]
----
resource "aws_s3_bucket" "examplebucket" {
bucket = "mybucketname"
tags = {
"anycompany:cost-center" = "Accounting"
}
}
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
endif::env-github,rspecator-view[]