Rule Definition
Hardcoded passwords in source code should be avoided because they can potentially be retrieved through code inspection and inverse engineering by attackers. Such an attack is difficult to be discovered, and eventually the problem can only be solved at software level thus compromising the usability of the application in the meantime.
Remediation
This rule identifies variable assignments and function calls and interfaces that include a hardcoded password. This identification is based on password-related semantics.
Violation Code Sample
const password = "WinterIsComing";
// OR
let mypwd;
mypwd = "WinterIsComing";
// OR
login({"password":"WinterIsComing"})
Fixed Code Sample
const password = SafeAccessToPasswordNotReturningAConstValue();
// OR
let mypwd;
mypwd = SafeAccessToPasswordNotReturningAConstValue();
// OR
login({"password":SafeAccessToPasswordNotReturningAConstValue()})
Reference
https://cwe.mitre.org/data/definitions/259.html
Related Technologies
Technical Criterion
CWE-798 - Use of Hard-coded Credentials
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.