Avoid comparing passwords against hard-coded strings | CAST Appmarq

Avoid comparing passwords against hard-coded strings

CRITICAL

Rule Definition
Comparing passwords to hard-coded strings is equivalent to having a hard-coded password in source code. 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
A non-secure starting patch would be to apply obfuscation techniques to the hardcoded password to prevent reverse-engineering of the generated Python (byte)code. This could be done by hashing the password or constructing the password string in many different places by non-trivial methods. Sensitive data such as passwords should be in principle encrypted and saved in separate files or in a database with restricted user access. Finally one should consider removing backdoors and delegate the password ownership to the end-user.

Violation Code Sample
password == "WinterIsComing"
...
String.Equals(password,"WinterIsComing")
...
String.Compare(password,"WinterIsComing")
...
password.CompareTo("WinterIsComing")
...
const string passwd = "WinterIsComing";
if (password == passwd)
...
Fixed Code Sample
password == getpwdsafe()
...
String.Equals(password,getpwdsafe())
...
String.compare(password,getpwdsafe())
...
password.CompareTo(getpwdsafe())
...
const string passwd = getpwdsafe();
if (password == passwd)
...

Reference
https://cwe.mitre.org/data/definitions/259.html

Related Technologies

Health Factor

  Security


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.

Benchmark Statistics

Global Compliance

nan%

Total Violations
0
Total Opportunities
0
Average Violations / App.
nan
The compliance score represents 1 minus the ratio between the number of times a rule has been violated compared to the number of opportunities in a set of applications that the rule could have been violated.

Industry Insights

Select from drop-down

100.00%

Software ISV

100.00%

Telecommunications

100.00%