Comparison of Classes by Name |
Weakness ID: 486 (Weakness Variant) | Status: Draft |
Description Summary
The program compares classes by name, which can cause it to use the wrong class when multiple classes can have the same name.
Extended Description
If the decision to trust the methods and data of an object is based on the name of a class, it is possible for malicious users to send objects of the same name as trusted classes and thereby gain the trust afforded to known classes and types.
Scope | Effect |
---|---|
Authorization | If a program relies solely on the name of an object to determine identity, it may execute the incorrect or unintended code. |
Example 1
(Bad Code)
Example Language: Java
if (inputClass.getClass().getName().equals("TrustedClassName")) {
// Do something assuming you trust inputClass
// ...
}
Phase: Implementation Use class equivalency to determine type. Rather than use the class name to determine if an object is of a given type, use the getClass() method, and == operator. |
Nature | Type | ID | Name | View(s) this relationship pertains to![]() |
---|---|---|---|---|
ChildOf | ![]() | 171 | Cleansing, Canonicalization, and Comparison Errors | Development Concepts699 |
ChildOf | ![]() | 485 | Insufficient Encapsulation | Development Concepts (primary)699 Seven Pernicious Kingdoms (primary)700 Research Concepts1000 |
ChildOf | ![]() | 697 | Insufficient Comparison | Research Concepts (primary)1000 |
PeerOf | ![]() | 386 | Symbolic Name not Mapping to Correct Object | Research Concepts1000 |
Mapped Taxonomy Name | Node ID | Fit | Mapped Node Name |
---|---|---|---|
7 Pernicious Kingdoms | Comparing Classes by Name | ||
CLASP | Comparing classes by name |
Submissions | ||||
---|---|---|---|---|
Submission Date | Submitter | Organization | Source | |
7 Pernicious Kingdoms | Externally Mined | |||
Modifications | ||||
Modification Date | Modifier | Organization | Source | |
2008-07-01 | Eric Dalci | Cigital | External | |
updated Time of Introduction | ||||
2008-09-08 | CWE Content Team | MITRE | Internal | |
updated Common Consequences, Description, Relationships, Other Notes, Relevant Properties, Taxonomy Mappings | ||||
2009-03-10 | CWE Content Team | MITRE | Internal | |
updated Other Notes | ||||
2009-07-27 | CWE Content Team | MITRE | Internal | |
updated Demonstrative Examples | ||||
Previous Entry Names | ||||
Change Date | Previous Entry Name | |||
2008-04-11 | Comparing Classes by Name | |||