CWE-595: Comparison of Object References Instead of Object Contents
The product compares object references instead of the contents of the objects themselves, preventing it from detecting equivalent objects.
How it's found
Comparison of Object References Instead of Object Contents 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.
For example, in Java, comparing objects using == usually produces deceptive results, since the == operator compares object references rather than values; often, this means that using == for strings is actually comparing the strings' references, not their values.
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
- Varies by Context: This weakness can lead to erroneous results that can cause unexpected application behaviors.
Mitigations
- Implementation: In Java, use the equals() method to compare objects instead of the == operator. If using ==, it is important for performance reasons that your objects are created by a static factory, not by a constructor.
Where this fits in a TurboPentest engagement
This weakness is not covered by the automated black-box pentest. IntegSec pentesters cover it in a manual engagement.
Frequently asked questions
What is CWE-595?
The product compares object references instead of the contents of the objects themselves, preventing it from detecting equivalent objects.
How do you find Comparison of Object References Instead of Object Contents?
Comparison of Object References Instead of Object Contents 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-595?
Varies by Context: This weakness can lead to erroneous results that can cause unexpected application behaviors.
Does TurboPentest test for Comparison of Object References Instead of Object Contents?
This weakness is not covered by the automated black-box pentest. IntegSec pentesters cover it in a manual engagement.
Related CWEs
Written and reviewed by
Michel Chamberland - Founder & CEO, IntegSec
CISSP, OSCP, OSCE, CEH, GIAC, CCSK · 20+ years in offensive security
Michel has spent 20+ years on offensive security teams including IBM X-Force Red and Trustwave SpiderLabs, leading penetration tests, red team engagements, and breach response for Fortune 500 customers. He is the founder of IntegSec and the architect of TurboPentest.
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 pentest