CWEweakness
CWE-597 Use of Wrong Operator in String Comparison
- Abstraction
- Variant
- Structure
- Simple
- Status
- Draft
- Languages
- Java, JavaScript, Not Language-Specific, PHP
- CWE version
- 5.0
Description
The product uses the wrong operator when comparing a string, such as using "==" when the .equals() method should be used instead.
Common consequences
• Other: Varies by Context — 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.
Potential 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.)
Detection methods
• Automated Static Analysis: Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)
Related
Child of · CWE (2)
Referenced by CVE · weakness (3)
- CVE-2021-4259 A vulnerability was found in phpRedisAdmin up to 1.16.1. vulnerability
- CVE-2022-36072 SilverwareGames.io is a social network for users to play video games online. vulnerability
- CVE-2021-3797 hestiacp is vulnerable to Use of Wrong Operator in String Comparison vulnerability