{"@ID": "697", "@Name": "Incorrect Comparison", "@Abstraction": "Pillar", "@Structure": "Simple", "@Status": "Incomplete", "@Diagram": "/data/images/CWE-697-Diagram.png", "Description": "The product compares two entities in a security-relevant context, but the comparison is incorrect.", "Extended_Description": {"xhtml:p": "This Pillar covers several possibilities:", "xhtml:ul": {"xhtml:li": ["the comparison checks one factor incorrectly;", "the comparison should consider multiple factors, but it does not check at least one of those factors at all;", "the comparison checks the wrong factor."]}}, "Weakness_Ordinalities": {"Weakness_Ordinality": {"Ordinality": "Primary"}}, "Applicable_Platforms": {"Language": {"@Class": "Not Language-Specific", "@Prevalence": "Undetermined"}, "Technology": {"@Class": "Not Technology-Specific", "@Prevalence": "Undetermined"}}, "Modes_Of_Introduction": {"Introduction": {"Phase": "Implementation"}}, "Common_Consequences": {"Consequence": {"Scope": "Other", "Impact": "Varies by Context", "Note": "When the comparison is incorrect, it may lead to resultant weaknesses."}}, "Detection_Methods": {"Detection_Method": {"@Detection_Method_ID": "DM-14", "Method": "Automated Static Analysis", "Description": "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.)"}}, "Demonstrative_Examples": {"Demonstrative_Example": [{"@Demonstrative_Example_ID": "DX-115", "Intro_Text": "Consider an application in which Truck objects are defined to be the same if they have the same make, the same model, and were manufactured in the same year.", "Example_Code": {"@Nature": "Bad", "@Language": "Java", "xhtml:div": {"xhtml:div": {"@style": "margin-left:1em;", "xhtml:div": {"xhtml:br": [null, null, null, null], "xhtml:div": {"@style": "margin-left:1em;", "xhtml:div": {"xhtml:br": [null, null, null, null, null, null], "#text": "if (o == null) return false;if (o == this) return true;if (!(o instanceof Truck)) return false;\n                                 Truck t = (Truck) o;\n                                 return (this.make.equals(t.getMake()) && this.model.equals(t.getModel()));"}}, "#text": "private String make;private String model;private int year;\n                           public boolean equals(Object o) {}"}}, "#text": "public class Truck {}"}}, "Body_Text": "Here, the equals() method only checks the make and model of the Truck objects, but the year of manufacture is not included."}, {"@Demonstrative_Example_ID": "DX-116", "Intro_Text": "This example defines a fixed username and password. The AuthenticateUser() function is intended to accept a username and a password from an untrusted user, and check to ensure that it matches the username and password. If the username and password match, AuthenticateUser() is intended to indicate that authentication succeeded.", "Example_Code": [{"@Nature": "Bad", "@Language": "C", "xhtml:div": {"xhtml:i": "/* Ignore CWE-259 (hard-coded password) and CWE-309 (use of password system for authentication) for this example. */", "xhtml:br": [null, null, null, null, null, null, null], "xhtml:div": [{"@style": "margin-left:1em;", "xhtml:div": [{"@style": "margin-left:1em;", "xhtml:br": null, "#text": "logEvent(\"Auth failure of username using strlen of inUser\");return(AUTH_FAIL);"}, {"@style": "margin-left:1em;", "xhtml:br": null, "#text": "logEvent(\"Auth success of password using strlen of inUser\");return(AUTH_SUCCESS);"}, {"@style": "margin-left:1em;", "xhtml:br": null, "#text": "logEvent(\"Auth fail of password using sizeof\");return(AUTH_FAIL);"}], "xhtml:br": [null, null], "#text": "if (strncmp(username, inUser, strlen(inUser))) {}if (! strncmp(pass, inPass, strlen(inPass))) {}else {}"}, {"@style": "margin-left:1em;", "xhtml:br": [null, null, null, null, null], "xhtml:div": [{"@style": "margin-left:1em;", "#text": "ExitError(\"Usage: Provide a username and password\");"}, {"@style": "margin-left:1em;", "#text": "DoAuthenticatedTask(argv[1]);"}, {"@style": "margin-left:1em;", "#text": "ExitError(\"Authentication failed\");"}], "#text": "int authResult;if (argc < 3) {}authResult = AuthenticateUser(argv[1], argv[2]);if (authResult == AUTH_SUCCESS) {}else {}"}], "#text": "char *username = \"admin\";char *pass = \"password\";\n                     int AuthenticateUser(char *inUser, char *inPass) {}\n                     int main (int argc, char **argv) {}"}}, {"@Nature": "Attack", "xhtml:div": {"xhtml:br": [null, null, null], "#text": "ppapaspass"}}], "Body_Text": ["In AuthenticateUser(), the strncmp() call uses the string length of an attacker-provided inPass parameter in order to determine how many characters to check in the password. So, if the attacker only provides a password of length 1, the check will only examine the first byte of the application's password before determining success.", "As a result, this partial comparison leads to improper authentication (CWE-287).", "Any of these passwords would still cause authentication to succeed for the \"admin\" user:", "This significantly reduces the search space for an attacker, making brute force attacks more feasible.", "The same problem also applies to the username, so values such as \"a\" and \"adm\" will succeed for the username.", "While this demonstrative example may not seem realistic, see the Observed Examples for CVE entries that effectively reflect this same weakness."]}]}, "Observed_Examples": {"Observed_Example": [{"Reference": "CVE-2021-3116", "Description": "Chain: Python-based HTTP Proxy server uses the wrong boolean operators (CWE-480) causing an  incorrect comparison (CWE-697) that identifies an authN failure if all three conditions are met instead of only one, allowing bypass of the proxy authentication (CWE-1390)", "Link": "https://www.cve.org/CVERecord?id=CVE-2021-3116"}, {"Reference": "CVE-2020-15811", "Description": "Chain: Proxy uses a substring search instead of parsing the Transfer-Encoding header (CWE-697), allowing request splitting (CWE-113) and cache poisoning", "Link": "https://www.cve.org/CVERecord?id=CVE-2020-15811"}, {"Reference": "CVE-2016-10003", "Description": "Proxy performs incorrect comparison of request headers, leading to infoleak", "Link": "https://www.cve.org/CVERecord?id=CVE-2016-10003"}]}, "Related_Attack_Patterns": {"Related_Attack_Pattern": [{"@CAPEC_ID": "10"}, {"@CAPEC_ID": "120"}, {"@CAPEC_ID": "14"}, {"@CAPEC_ID": "15"}, {"@CAPEC_ID": "182"}, {"@CAPEC_ID": "24"}, {"@CAPEC_ID": "267"}, {"@CAPEC_ID": "3"}, {"@CAPEC_ID": "41"}, {"@CAPEC_ID": "43"}, {"@CAPEC_ID": "44"}, {"@CAPEC_ID": "45"}, {"@CAPEC_ID": "46"}, {"@CAPEC_ID": "47"}, {"@CAPEC_ID": "52"}, {"@CAPEC_ID": "53"}, {"@CAPEC_ID": "6"}, {"@CAPEC_ID": "64"}, {"@CAPEC_ID": "67"}, {"@CAPEC_ID": "7"}, {"@CAPEC_ID": "71"}, {"@CAPEC_ID": "73"}, {"@CAPEC_ID": "78"}, {"@CAPEC_ID": "79"}, {"@CAPEC_ID": "8"}, {"@CAPEC_ID": "80"}, {"@CAPEC_ID": "88"}, {"@CAPEC_ID": "9"}, {"@CAPEC_ID": "92"}]}, "Mapping_Notes": {"Usage": "Discouraged", "Rationale": "This CWE entry is extremely high-level, a Pillar. However, sometimes this weakness is forced to be used due to the lack of in-depth weakness research. See Research Gaps.", "Comments": "Where feasible, consider children or descendants of this entry instead.", "Reasons": {"Reason": {"@Type": "Abstraction"}}}, "Notes": {"Note": [{"@Type": "Research Gap", "xhtml:p": "Weaknesses related to this Pillar appear to be under-studied, especially with respect to classification schemes. Input from academic and other communities could help identify and resolve gaps or organizational difficulties within CWE."}, {"@Type": "Maintenance", "#text": "This entry likely has some relationships with case sensitivity (CWE-178), but case sensitivity is a factor in other types of weaknesses besides comparison.  Also, in cryptography, certain attacks are possible when certain comparison operations do not take place in constant time, causing a timing-related information leak (CWE-208)."}]}, "Content_History": {"Submission": {"Submission_Name": "CWE Content Team", "Submission_Organization": "MITRE", "Submission_Date": "2008-09-09", "Submission_Version": "1.0", "Submission_ReleaseDate": "2008-09-09"}, "Modification": [{"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2008-11-24", "Modification_Version": "1.1", "Modification_ReleaseDate": "2008-11-25", "Modification_Comment": "updated Relationships, Taxonomy_Mappings"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2009-03-10", "Modification_Version": "1.3", "Modification_ReleaseDate": "2009-03-10", "Modification_Comment": "updated Related_Attack_Patterns"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2009-05-27", "Modification_Version": "1.4", "Modification_ReleaseDate": "2009-05-27", "Modification_Comment": "updated Description"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2011-03-29", "Modification_Version": "1.12", "Modification_ReleaseDate": "2011-03-30", "Modification_Comment": "updated Description"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2011-06-01", "Modification_Version": "1.13", "Modification_ReleaseDate": "2011-06-01", "Modification_Comment": "updated Common_Consequences"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2011-09-13", "Modification_Version": "2.1", "Modification_ReleaseDate": "2011-09-13", "Modification_Comment": "updated Relationships, Taxonomy_Mappings"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2012-05-11", "Modification_Version": "2.2", "Modification_ReleaseDate": "2012-05-15", "Modification_Comment": "updated Related_Attack_Patterns, Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2014-07-30", "Modification_Version": "2.8", "Modification_ReleaseDate": "2014-07-31", "Modification_Comment": "updated Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2017-05-03", "Modification_Version": "2.11", "Modification_ReleaseDate": "2017-05-05", "Modification_Comment": "updated Related_Attack_Patterns"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2017-11-08", "Modification_Version": "3.0", "Modification_ReleaseDate": "2017-11-08", "Modification_Comment": "updated Taxonomy_Mappings"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2018-03-27", "Modification_Version": "3.1", "Modification_ReleaseDate": "2018-03-27", "Modification_Comment": "updated Common_Consequences, Demonstrative_Examples, Description, Maintenance_Notes, Name, Observed_Examples, Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2019-01-03", "Modification_Version": "3.2", "Modification_ReleaseDate": "2019-01-03", "Modification_Comment": "updated Related_Attack_Patterns, Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2019-06-20", "Modification_Version": "3.3", "Modification_ReleaseDate": "2019-06-20", "Modification_Comment": "updated Related_Attack_Patterns"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2019-09-19", "Modification_Version": "3.4", "Modification_ReleaseDate": "2019-09-19", "Modification_Comment": "updated Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2020-02-24", "Modification_Version": "4.0", "Modification_ReleaseDate": "2020-02-24", "Modification_Comment": "updated Applicable_Platforms, Relationships, Type"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2020-06-25", "Modification_Version": "4.1", "Modification_ReleaseDate": "2020-06-25", "Modification_Comment": "updated Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2020-08-20", "Modification_Version": "4.2", "Modification_ReleaseDate": "2020-08-20", "Modification_Comment": "updated Related_Attack_Patterns"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2022-04-28", "Modification_Version": "4.7", "Modification_ReleaseDate": "2022-04-28", "Modification_Comment": "updated Related_Attack_Patterns"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2022-06-28", "Modification_Version": "4.8", "Modification_ReleaseDate": "2022-06-28", "Modification_Comment": "updated Observed_Examples"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-01-31", "Modification_Version": "4.10", "Modification_ReleaseDate": "2023-01-31", "Modification_Comment": "updated Description, Observed_Examples"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-04-27", "Modification_Version": "4.11", "Modification_ReleaseDate": "2023-04-27", "Modification_Comment": "updated Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-06-29", "Modification_Version": "4.12", "Modification_ReleaseDate": "2023-06-29", "Modification_Comment": "updated Mapping_Notes, Research_Gaps"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2025-12-11", "Modification_Version": "4.19", "Modification_ReleaseDate": "2025-12-11", "Modification_Comment": "updated Common_Consequences, Description, Detection_Factors, Diagram"}], "Previous_Entry_Name": {"@Date": "2018-03-27", "#text": "Insufficient Comparison"}}}
