CWE-581: Object Model Violation: Just One of Equals and Hashcode Defined

VariantDraft

The product does not maintain equal hashcodes for equal objects.

View on MITRE
Back to CWE Lookup

Extended Description

Java objects are expected to obey a number of invariants related to equality. One of these invariants is that equal objects must have equal hashcodes. In other words, if a.equals(b) == true then a.hashCode() == b.hashCode().

Technical Details

Structure
Simple

Applicable To

Languages
Java
Platforms

Frequently Asked Questions

What is CWE-581: Object Model Violation: Just One of Equals and Hashcode Defined?+

CWE-581: Object Model Violation: Just One of Equals and Hashcode Defined is a Common Weakness Enumeration (CWE) entry maintained by MITRE. The product does not maintain equal hashcodes for equal objects. Java objects are expected to obey a number of invariants related to equality. One of these invariants is that equal objects must have equal hashcodes. In other words, if a.equals(b) == true then a.hashCode() == b.hashCode().

What are the security consequences of Object Model Violation: Just One of Equals and Hashcode Defined?+

If exploited, CWE-581 (Object Model Violation: Just One of Equals and Hashcode Defined) it can compromise Integrity and Other, leading to outcomes such as Other.

How do you prevent or mitigate Object Model Violation: Just One of Equals and Hashcode Defined?+

Recommended mitigations for CWE-581 include: Both Equals() and Hashcode() should be defined.

Which programming languages are affected by Object Model Violation: Just One of Equals and Hashcode Defined?+

CWE-581 commonly affects Java. Note that weaknesses are often language-agnostic patterns, so secure coding practices apply broadly.

What is the difference between a CWE and a CVE?+

A CWE (Common Weakness Enumeration) like CWE-581 describes a category of software weakness — the underlying flaw type. A CVE (Common Vulnerabilities and Exposures) identifies a specific, real-world vulnerability in a particular product. In short, a CWE is the kind of mistake, and a CVE is an instance of that mistake being found in software.

Learn More