CWE-597: Use of Wrong Operator in String Comparison
The product uses the wrong operator when comparing a string, such as using "==" when the .equals() method should be used instead.
How it's found
Use of Wrong Operator in String Comparison is a specific, narrowly defined instance of a broader pattern. Testers confirm it with targeted code review and a proof-of-concept input that exercises the exact code path this weakness describes.
In Java, using == or != to compare two strings for equality actually compares two objects for equality rather than their string values for equality. Chances are good that the two references will never be equal. While this weakness often only affects program correctness, if the equality is used for a security decision, the unintended comparison result could be leveraged to affect program security.
Vulnerable vs. safe
System.out.println("str1 == str2");String str1 = new String("Hello");String str2 = new String("Hello");if (str1 == str2) {}System.out.println("str1 equals str2");if (str1.equals(str2)) {}Consequences
- Other
Mitigations
- Implementation: Within Java, use .equals() to compare string values.Within JavaScript, use == to compare string values.Within PHP, use == to compare a numeric value to a string value. (PHP converts the string to a number.)
Where this fits in a TurboPentest engagement
TurboPentest's agentic pentest is powerful and covers a broad range of issues automatically. This particular class is best confirmed in a manual IntegSec engagement, where human pentesters apply deeper methodology and a larger context window than any automated pass.
Frequently asked questions
What is CWE-597?
The product uses the wrong operator when comparing a string, such as using "==" when the .equals() method should be used instead.
How do you find Use of Wrong Operator in String Comparison?
Use of Wrong Operator in String Comparison is a specific, narrowly defined instance of a broader pattern. Testers confirm it with targeted code review and a proof-of-concept input that exercises the exact code path this weakness describes.
What is the impact of CWE-597?
Other
Does TurboPentest test for Use of Wrong Operator in String Comparison?
TurboPentest's agentic pentest is powerful and covers a broad range of issues automatically. This particular class is best confirmed in a manual IntegSec engagement, where human pentesters apply deeper methodology and a larger context window than any automated pass.
Related CWEs
Find these issues before an attacker does
TurboPentest runs an agentic AI pentest against your target and reports findings with proof, from $99 per target.
Start a $99 pentest