Logo
-

Byte Open Security

(ByteOS Network)

Log In

Sign Up

ByteOS

Security
Vulnerability Details
Registries
Custom Views
Weaknesses
Attack Patterns
Filters & Tools
CWE-696:Incorrect Behavior Order
Weakness ID:696
Version:v4.17
Weakness Name:Incorrect Behavior Order
Vulnerability Mapping:Allowed-with-Review
Abstraction:Class
Structure:Simple
Status:Incomplete
Likelihood of Exploit:
DetailsContent HistoryObserved CVE ExamplesReports
▼Description

The product performs multiple related behaviors, but the behaviors are performed in the wrong order in ways which may produce resultant weaknesses.

▼Extended Description

▼Alternate Terms
▼Relationships
Relevant to the view"Research Concepts - (1000)"
NatureMappingTypeIDName
ChildOfDiscouragedP691Insufficient Control Flow Management
ParentOfAllowedB551Incorrect Behavior Order: Authorization Before Parsing and Canonicalization
ParentOfAllowedB1190DMA Device Enabled Too Early in Boot Phase
ParentOfAllowedB1193Power-On of Untrusted Execution Core Before Enabling Fabric Access Control
ParentOfAllowedB1279Cryptographic Operations are run Before Supporting Units are Ready
ParentOfAllowedB1280Access Control Check Implemented After Asset is Accessed
ParentOfAllowedB179Incorrect Behavior Order: Early Validation
ParentOfAllowedB408Incorrect Behavior Order: Early Amplification
Nature: ChildOf
Mapping: Discouraged
Type: Pillar
ID: 691
Name: Insufficient Control Flow Management
Nature: ParentOf
Mapping: Allowed
Type: Base
ID: 551
Name: Incorrect Behavior Order: Authorization Before Parsing and Canonicalization
Nature: ParentOf
Mapping: Allowed
Type: Base
ID: 1190
Name: DMA Device Enabled Too Early in Boot Phase
Nature: ParentOf
Mapping: Allowed
Type: Base
ID: 1193
Name: Power-On of Untrusted Execution Core Before Enabling Fabric Access Control
Nature: ParentOf
Mapping: Allowed
Type: Base
ID: 1279
Name: Cryptographic Operations are run Before Supporting Units are Ready
Nature: ParentOf
Mapping: Allowed
Type: Base
ID: 1280
Name: Access Control Check Implemented After Asset is Accessed
Nature: ParentOf
Mapping: Allowed
Type: Base
ID: 179
Name: Incorrect Behavior Order: Early Validation
Nature: ParentOf
Mapping: Allowed
Type: Base
ID: 408
Name: Incorrect Behavior Order: Early Amplification
▼Memberships
NatureMappingTypeIDName
MemberOfProhibitedC748CERT C Secure Coding Standard (2008) Appendix - POSIX (POS)
MemberOfProhibitedC977SFP Secondary Cluster: Design
MemberOfProhibitedC1171SEI CERT C Coding Standard - Guidelines 50. POSIX (POS)
MemberOfProhibitedC1410Comprehensive Categorization: Insufficient Control Flow Management
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 748
Name: CERT C Secure Coding Standard (2008) Appendix - POSIX (POS)
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 977
Name: SFP Secondary Cluster: Design
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 1171
Name: SEI CERT C Coding Standard - Guidelines 50. POSIX (POS)
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 1410
Name: Comprehensive Categorization: Insufficient Control Flow Management
▼Tags
NatureMappingTypeIDName
MemberOfProhibitedBSBOSS-330Alter Execution Logic (impact)
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-330
Name: Alter Execution Logic (impact)
▼Relevant To View
Relevant to the view"Weaknesses Addressed by the SEI CERT C Coding Standard - (1154)"
NatureMappingTypeIDName
MemberOfProhibitedC1171SEI CERT C Coding Standard - Guidelines 50. POSIX (POS)
Nature: MemberOf
Mapping: Prohibited
Type: Category
ID: 1171
Name: SEI CERT C Coding Standard - Guidelines 50. POSIX (POS)
Relevant to the view"Software Fault Pattern (SFP) Clusters - (888)"
NatureMappingTypeIDName
MemberOfProhibitedC977SFP Secondary Cluster: Design
Nature: MemberOf
Mapping: Prohibited
Type: Category
ID: 977
Name: SFP Secondary Cluster: Design
▼Background Detail

▼Common Consequences
ScopeLikelihoodImpactNote
IntegrityN/AAlter Execution Logic
N/A
Scope: Integrity
Likelihood: N/A
Impact: Alter Execution Logic
Note:
N/A
▼Potential Mitigations
▼Modes Of Introduction
Phase: Architecture and Design
Note:

N/A

Phase: Implementation
Note:

N/A

▼Applicable Platforms
▼Demonstrative Examples
Example 1

The following code attempts to validate a given input path by checking it against an allowlist and then return the canonical path. In this specific case, the path is considered valid if it starts with the string "/safe_dir/".

Language: ( code)
N/A

Language: Java(Bad code)
String path = getInputPath(); if (path.startsWith("/safe_dir/")) { File f = new File(path); return f.getCanonicalPath(); }

Language: ( code)
N/A

The problem with the above code is that the validation step occurs before canonicalization occurs. An attacker could provide an input path of "/safe_dir/../" that would pass the validation step. However, the canonicalization process sees the double dot as a traversal to the parent directory and hence when canonicized the path would become just "/".

Language: ( code)
N/A

To avoid this problem, validation should occur after canonicalization takes place. In this case canonicalization occurs during the initialization of the File object. The code below fixes the issue.

Language: Java(Good code)
String path = getInputPath(); File f = new File(path); if (f.getCanonicalPath().startsWith("/safe_dir/")) { return f.getCanonicalPath(); }

Example 2

This function prints the contents of a specified file requested by a user.

Language: ( code)
N/A

Language: PHP(Bad code)
function printFile($username,$filename){ //read file into string* $file = file_get_contents($filename); if ($file && isOwnerOf($username,$filename)){ echo $file; return true; } else{ echo 'You are not authorized to view this file'; } return false; }

Language: ( code)
N/A

This code first reads a specified file into memory, then prints the file if the user is authorized to see its contents. The read of the file into memory may be resource intensive and is unnecessary if the user is not allowed to see the file anyway.

Example 3

Assume that the module foo_bar implements a protected register. The register content is the asset. Only transactions made by user id (indicated by signal usr_id) 0x4 are allowed to modify the register contents. The signal grant_access is used to provide access.

Language: ( code)
N/A

Language: Verilog(Bad code)
module foo_bar(data_out, usr_id, data_in, clk, rst_n); output reg [7:0] data_out; input wire [2:0] usr_id; input wire [7:0] data_in; input wire clk, rst_n; wire grant_access; always @ (posedge clk or negedge rst_n) begin if (!rst_n) data_out = 0; else data_out = (grant_access) ? data_in : data_out; assign grant_access = (usr_id == 3'h4) ? 1'b1 : 1'b0; end endmodule

Language: ( code)
N/A

This code uses Verilog blocking assignments for data_out and grant_access. Therefore, these assignments happen sequentially (i.e., data_out is updated to new value first, and grant_access is updated the next cycle) and not in parallel. Therefore, the asset data_out is allowed to be modified even before the access control check is complete and grant_access signal is set. Since grant_access does not have a reset value, it will be meta-stable and will randomly go to either 0 or 1.

Language: ( code)
N/A

Flipping the order of the assignment of data_out and grant_access should solve the problem. The correct snippet of code is shown below.

Language: Verilog(Good code)
always @ (posedge clk or negedge rst_n) begin if (!rst_n) data_out = 0; else assign grant_access = (usr_id == 3'h4) ? 1'b1 : 1'b0; data_out = (grant_access) ? data_in : data_out; end endmodule

▼Observed Examples
ReferenceDescription
CVE-2019-9805
Chain: Creation of the packet client occurs before initialization is complete (CWE-696) resulting in a read from uninitialized memory (CWE-908), causing memory corruption.
CVE-2007-5191
file-system management programs call the setuid and setgid functions in the wrong order and do not check the return values, allowing attackers to gain unintended privileges
CVE-2007-1588
C++ web server program calls Process::setuid before calling Process::setgid, preventing it from dropping privileges, potentially allowing CGI programs to be called with higher privileges than intended
CVE-2022-37734
Chain: lexer in Java-based GraphQL server does not enforce maximum of tokens early enough (CWE-696), allowing excessive CPU consumption (CWE-1176)
Reference: CVE-2019-9805
Description:
Chain: Creation of the packet client occurs before initialization is complete (CWE-696) resulting in a read from uninitialized memory (CWE-908), causing memory corruption.
Reference: CVE-2007-5191
Description:
file-system management programs call the setuid and setgid functions in the wrong order and do not check the return values, allowing attackers to gain unintended privileges
Reference: CVE-2007-1588
Description:
C++ web server program calls Process::setuid before calling Process::setgid, preventing it from dropping privileges, potentially allowing CGI programs to be called with higher privileges than intended
Reference: CVE-2022-37734
Description:
Chain: lexer in Java-based GraphQL server does not enforce maximum of tokens early enough (CWE-696), allowing excessive CPU consumption (CWE-1176)
▼Affected Resources
    ▼Functional Areas
      ▼Weakness Ordinalities
      OrdinalityDescription
      Primary
      N/A
      Ordinality: Primary
      Description:
      N/A
      ▼Detection Methods
      ▼Vulnerability Mapping Notes
      Usage:Allowed-with-Review
      Reason:Abstraction
      Rationale:

      This CWE entry is a Class and might have Base-level children that would be more appropriate

      Comments:

      Examine children of this entry to see if there is a better fit

      Suggestions:
      ▼Notes
      ▼Taxonomy Mappings
      Taxonomy NameEntry IDFitEntry Name
      CERT C Secure CodingPOS36-CCWE More AbstractObserve correct revocation order while relinquishing privileges
      Taxonomy Name: CERT C Secure Coding
      Entry ID: POS36-C
      Fit: CWE More Abstract
      Entry Name: Observe correct revocation order while relinquishing privileges
      ▼Related Attack Patterns
      IDName
      CAPEC-463
      Padding Oracle Crypto Attack
      ID: CAPEC-463
      Name: Padding Oracle Crypto Attack
      ▼References
      Details not found