Both MD5 and SHA1 hash algorithms have been found to be vulnerable to producing collisions.
This means
that two different values, when hashed, can lead to the same hash value. If the application is
trying
to use these hash methods for storing passwords, then it is recommended to switch to a
password hashing
algorithm such as Argon2id or PBKDF2. Currently there is no vetted Argon2id implementation for
C# so
it is recommended that PBKDF2 be used until one is available.
Example using PBKDF2 to generate and compare passwords:
const int SaltSize = 24;
const int HashSize = 24;
// number of pbkdf2 iterations, Rfc2898DeriveBytes uses hmac-sha1
// so set a high iteration count
const int Iterations = 1_300_000;
byte[] salt = new byte[SaltSize];
RandomNumberGenerator.Fill(salt);
Rfc2898DeriveBytes pbkdf2 = new Rfc2898DeriveBytes("some password", salt, Iterations);
byte[] hashBytes = pbkdf2.GetBytes(HashSize);
// Store salt and hashedBytes in a data store such as database for authentication
Console.WriteLine("Hash {0}", BitConverter.ToString(hashBytes).Replace("-", ""));
// Do a constant time comparison as to not leak data based on timing
if (CryptographicOperations.FixedTimeEquals(hashBytes, hashBytes)) {
Console.WriteLine("hashes are equal");
}
## medium Finding
**Scanner:** semgrep
**Severity:** medium
**Rule:** gitlab-csharp_crypto_rule-WeakHashingFunction
**CWE:** CWE-327
**CRA:** cra-ai-13 — Verschlüsselung sensibler Daten (Annex I)
### Description
Both MD5 and SHA1 hash algorithms have been found to be vulnerable to producing collisions.
This means
that two different values, when hashed, can lead to the same hash value. If the application is
trying
to use these hash methods for storing passwords, then it is recommended to switch to a
password hashing
algorithm such as Argon2id or PBKDF2. Currently there is no vetted Argon2id implementation for
C# so
it is recommended that PBKDF2 be used until one is available.
Example using PBKDF2 to generate and compare passwords:
```
const int SaltSize = 24;
const int HashSize = 24;
// number of pbkdf2 iterations, Rfc2898DeriveBytes uses hmac-sha1
// so set a high iteration count
const int Iterations = 1_300_000;
byte[] salt = new byte[SaltSize];
RandomNumberGenerator.Fill(salt);
Rfc2898DeriveBytes pbkdf2 = new Rfc2898DeriveBytes("some password", salt, Iterations);
byte[] hashBytes = pbkdf2.GetBytes(HashSize);
// Store salt and hashedBytes in a data store such as database for authentication
Console.WriteLine("Hash {0}", BitConverter.ToString(hashBytes).Replace("-", ""));
// Do a constant time comparison as to not leak data based on timing
if (CryptographicOperations.FixedTimeEquals(hashBytes, hashBytes)) {
Console.WriteLine("hashes are equal");
}
```
For more information on PBKDF2 see:
https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.rfc2898derivebytes
For more information on secure password storage see OWASP:
https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html
### Location
**File:** `compliance-agent/rules/cra_semgrep_csharp.cs` (line 190)
### Code
```
var sha1 = new SHA1CryptoServiceProvider();
```
### Remediation
None
---
*Fingerprint:* `2de88c37673848f98c96e08b5d12d52006b03d8f603b3ba0db689e2efd993886`
*Generated by compliance-scanner*
[Open in Prüfwerk / In Prüfwerk öffnen](https://pruefwerk.breakpilot.com/findings?target=6ae9aa2160f5d8045fc570a7)
Prüfwerk: Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
**Prüfwerk:** Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
medium Finding
Scanner: semgrep
Severity: medium
Rule: gitlab-csharp_crypto_rule-WeakHashingFunction
CWE: CWE-327
CRA: cra-ai-13 — Verschlüsselung sensibler Daten (Annex I)
Description
Both MD5 and SHA1 hash algorithms have been found to be vulnerable to producing collisions.
This means
that two different values, when hashed, can lead to the same hash value. If the application is
trying
to use these hash methods for storing passwords, then it is recommended to switch to a
password hashing
algorithm such as Argon2id or PBKDF2. Currently there is no vetted Argon2id implementation for
C# so
it is recommended that PBKDF2 be used until one is available.
Example using PBKDF2 to generate and compare passwords:
For more information on PBKDF2 see:
https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.rfc2898derivebytes
For more information on secure password storage see OWASP:
https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html
Location
File:
compliance-agent/rules/cra_semgrep_csharp.cs(line 190)Code
Remediation
None
Fingerprint:
2de88c37673848f98c96e08b5d12d52006b03d8f603b3ba0db689e2efd993886Generated by compliance-scanner
Open in Prüfwerk / In Prüfwerk öffnen
Prüfwerk: Die Datei liegt in Testdaten (z. B. fixtures/ oder testdata/), die von der Prüfung ausgenommen sind.
The file lies in test data (such as fixtures/ or testdata/), which is left out of the scan.