CRITICAL
Rule Definition
Attacker can easily comprise the system if the HMAC keys are hard-coded.
Remediation
Provide appropriate values for the message and keys.
Violation Code Sample
Sample code (C#)
using (HMAC hmac = HMAC.Create("HMACSHA512"))
{
string secureKey = "12345";
byte[] SecureBytes = Encoding.ASCII.GetBytes(secureKey);
hmac.Key = SecureBytes;
}
Fixed Code Sample
// Remediation Sample (C#)
using (HMAC hmac = HMAC.Create("HMACSHA512"))
{
var rngCryptoServiceProvider = new RNGCryptoServiceProvider();
byte[] randomBytes = new byte[keyLength];
rngCryptoServiceProvider.GetBytes(randomBytes);
hmac.Key = randomBytes;
}
Reference
A3-OWASP 2017
https://www.owasp.org/index.php/Top_10-2017_A3-Sensitive_Data_Exposure
A6-OWASP 2017
https://www.owasp.org/index.php/Top_10-2017_A6-Security_Misconfiguration
CWE-321
https://cwe.mitre.org/data/definitions/321.html
https://en.wikipedia.org/wiki/HMAC
Related Technologies
Technical Criterion
Secure Coding - Weak Security Features
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.