Skip to main content

Improper type assignation

Description

There are variant variables in the source code, i.e., no specific type is declared for them. This can be inefficient, as it becomes necessary to identify the variable's data type and cast it every time it is used.

Impact

Result in modification of that resource by unintended parties.

Recommendation

Check to see if the resource has insecure permissions (such as being modifiable by any regular user), and generate an error or even exit the software if there is a possibility that the resource could have been modified by an unauthorized party.

Threat

Authenticated external attacker.

Expected Remediation Time

⌚ 15 minutes.

Score

Default score using CVSS 3.1. It may change depending on the context of the vulnerability.

Base

  • Attack vector: L
  • Attack complexity: L
  • Privileges required: N
  • User interaction: N
  • Scope: U
  • Confidentiality: N
  • Integrity: L
  • Availability: N

Temporal

  • Exploit code madurity: X
  • Remediation level: X
  • Report confidence: X

Result

  • Vector string: CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N/E:X/RL:X/RC:X
  • Score:
    • Base: 4.0
    • Temporal: 4.0
  • Severity:
    • Base: Medium
    • Temporal: Medium

Code Examples

Compliant code

The app defines the type of all variables declared in the code

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String username = input.next();
String password = input.next();

try {
if(username.equals(username) && password.equals(password)){
ScheduledExecutorService executor = Executors.newScheduledThreadPool(2);
users check = new users(username, password);
signIn(user, check);
}
} catch (InterruptedException e) {
//Code to catch the exception
}
}

Non compliant code

The app does not correctly define the type of some variables

public static void main(String[] args) {
input = new Scanner(System.in);
//username and password could be assigned to unsafe values
username = input.next();
password = input.next();

try {
if(username.equals(username) && password.equals(password)){
ScheduledExecutorService executor = Executors.newScheduledThreadPool(2);
users check = new users(username, password);
signIn(user, check);
}
} catch (InterruptedException e) {
//Code to catch the exception
}
}

Requirements