![github-actions[bot]](/assets/img/avatar_default.png)
You can preview this rule [here](https://sonarsource.github.io/rspec/#/rspec/S4790/go) (updated a few minutes after each push). ## Review A dedicated reviewer checked the rule description successfully for: - [x] logical errors and incorrect information - [x] information gaps and missing content - [x] text style and tone - [x] PR summary and labels follow [the guidelines](https://github.com/SonarSource/rspec/#to-modify-an-existing-rule)
87 lines
1.4 KiB
Plaintext
87 lines
1.4 KiB
Plaintext
include::../description.adoc[]
|
|
|
|
include::../ask-yourself.adoc[]
|
|
|
|
include::../recommended.adoc[]
|
|
|
|
== Sensitive Code Example
|
|
|
|
[source,go,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
import (
|
|
"crypto"
|
|
"fmt"
|
|
)
|
|
|
|
func calculateHash(data []byte) string {
|
|
hashInstance := crypto.Hash.New(crypto.MD5) // Sensitive
|
|
hashInstance.Write(data)
|
|
hash := hashInstance.Sum(nil)
|
|
return fmt.Sprintf("%x", hash)
|
|
}
|
|
----
|
|
|
|
[source,go,diff-id=2,diff-type=noncompliant]
|
|
----
|
|
import (
|
|
"crypto/sha1"
|
|
"fmt"
|
|
)
|
|
|
|
func calculateHash(data []byte) string {
|
|
hash := sha1.Sum(data) // Sensitive
|
|
return fmt.Sprintf("%x", hash)
|
|
}
|
|
----
|
|
|
|
== Compliant Solution
|
|
|
|
[source,go,diff-id=1,diff-type=compliant]
|
|
----
|
|
import (
|
|
"crypto"
|
|
"fmt"
|
|
)
|
|
|
|
func calculateHash(data []byte) string {
|
|
hashInstance := crypto.Hash.New(crypto.SHA256) // Compliant
|
|
hashInstance.Write(data)
|
|
hash := hashInstance.Sum(nil)
|
|
return fmt.Sprintf("%x", hash)
|
|
}
|
|
----
|
|
|
|
[source,go,diff-id=2,diff-type=compliant]
|
|
----
|
|
import (
|
|
"crypto/sha512"
|
|
"fmt"
|
|
)
|
|
|
|
func calculateHash(data []byte) string {
|
|
hash := sha512.Sum512(data) // Compliant
|
|
return fmt.Sprintf("%x", hash)
|
|
}
|
|
----
|
|
|
|
|
|
include::../see.adoc[]
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::../message.adoc[]
|
|
|
|
include::../highlighting.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::../comments-and-links.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|