Skip to main content

Lack of data validation - Session Cookie

Description

The Session Cookie is generated from any value sent from the front end, allowing to modify it and set an insecure session cookie.

Impact

  • Set any value as a session cookie.
  • Consume reporting services without authorization.

Recommendation

Prevent modification of the session cookie value.

Threat

External attacker with Internet access and a valid token.

Expected Remediation Time

⌚ 60 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: R
  • Scope: U
  • Confidentiality: L
  • 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:R/S:U/C:L/I:L/A:N/E:X/RL:X/RC:X
  • Score:
    • Base: 4.1
    • Temporal: 4.1
  • Severity:
    • Base: Medium
    • Temporal: Medium

Code Examples

Compliant code

The application uses a safe method to generate unique session cookies

const signinHandler = (req, res) => {
// get users credentials from the JSON body
const { username, password } = req.body
if (!username) {
// If the username isn't present, return an HTTP unauthorized code
res.status(401).end()
return
}

// validate the password against our data
// if invalid, send an unauthorized code
const expectedPassword = users[username]
if (!expectedPassword || expectedPassword !== password) {
res.status(401).end()
return
}

// generate a random UUID as the session token
const sessionToken = uuid.v4()
const now = new Date()
const expiresAt = new Date(+now + 120 * 1000)
const session = new Session(username, expiresAt)
sessions[sessionToken] = session
res.cookie("session_token", sessionToken, { expires: expiresAt })
res.end()
}

Non compliant code

The application uses an unsafe method to generate session cookies

const signinHandler = (req, res) => {
// get users credentials from the JSON body
const { username, password } = req.body
if (!username) {
// If the username isn't present, return an HTTP unauthorized code
res.status(401).end()
return
}

// generate a random unsafe session token
const sessionToken = Math.random()*100000
res.cookie("session_token", sessionToken, { expires: expiresAt })
res.end()
}

Requirements