Skip to main content

Lack of data validation - Type confusion

Description

A field is interpreted on the server-side, although it indicates that it only accepts numbers, it allows values in the form 0xff.

Impact

  • Get internal information about the operation of the system.
  • Inject code and get it interpreted by the server.

Recommendation

Validate on the server-side the data types that are entered but prevent them from being interpreted.

Threat

Authorized user from intranet.

Expected Remediation Time

⌚ 30 minutes.

Score

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

Base

  • Attack vector: A
  • Attack complexity: L
  • Privileges required: L
  • 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:A/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N/E:X/RL:X/RC:X
  • Score:
    • Base: 3.5
    • Temporal: 3.5
  • Severity:
    • Base: Low
    • Temporal: Low

Code Examples

Compliant code

Verify types of user inputs to avoid problems on the server side

import (
"dabatase/sql"
"db"
"math"
"strconv"
)

func SafeFloat(request *http.Request) {
amount := strconv.ParseFloat(request.Amount)
if math.IsNaN(amount) || math.IsInf(amount, 0) {
return "Not a valid value"
}
sql.QueryRow(`INSERT INTO tbl $1`, amount)
}

Non compliant code

The application includes functions that could be penetrated because of type confusion

import (
"dabatase/sql"
"db"
"math"
"strconv"
)

func DangerousFloat(request *http.Request) {
amount := strconv.ParseFloat(request.Amount)
sql.QueryRow(`INSERT INTO tbl $1`, amount)
}

Requirements