Last tested: 20 Feb, 2018

express vulnerabilities

Fast, unopinionated, minimalist web framework

View on npm

express (latest)

Published 20 Feb, 2018

Known vulnerabilities1
Vulnerable paths2
Dependencies50

Regular Expression Denial of Service (ReDoS)

low severity

Detailed paths

  • Introduced through: express@5.0.0-alpha.6 > send@0.15.6 > mime@1.3.4
  • Introduced through: express@5.0.0-alpha.6 > serve-static@1.12.6 > send@0.15.6 > mime@1.3.4

Overview

mime is a comprehensive, compact MIME type module.

Affected versions of this package are vulnerable to Regular expression Denial of Service (ReDoS). It uses regex the following regex /.*[\.\/\\]/ in its lookup, which can cause a slowdown of 2 seconds for 50k characters.

The Regular expression Denial of Service (ReDoS) is a type of Denial of Service attack. Many Regular Expression implementations may reach extreme situations that cause them to work very slowly (exponentially related to input size), allowing an attacker to exploit this and can cause the program to enter these extreme situations by using a specially crafted input and cause the service to excessively consume CPU, resulting in a Denial of Service.

You can read more about Regular Expression Denial of Service (ReDoS) on our blog.

Remediation

Upgrade mime to versions 1.4.1, 2.0.3 or higher.

References

Vulnerable versions of express

Fixed in 5.0.0-alpha.6

Regular Expression Denial of Service (ReDoS)

low severity

Detailed paths

  • Introduced through: express@5.0.0-alpha.5 > debug@2.6.1
  • Introduced through: express@5.0.0-alpha.5 > send@0.15.1 > debug@2.6.1
  • Introduced through: express@5.0.0-alpha.5 > serve-static@1.12.1 > send@0.15.1 > debug@2.6.1

Overview

debug is a JavaScript debugging utility modelled after Node.js core's debugging technique..

debug uses printf-style formatting. Affected versions of this package are vulnerable to Regular expression Denial of Service (ReDoS) attacks via the the %o formatter (Pretty-print an Object all on a single line). It used a regular expression (/\s*\n\s*/g) in order to strip whitespaces and replace newlines with spaces, in order to join the data into a single line. This can cause a very low impact of about 2 seconds matching time for data 50k characters long.

The Regular expression Denial of Service (ReDoS) is a type of Denial of Service attack. Many Regular Expression implementations may reach extreme situations that cause them to work very slowly (exponentially related to input size), allowing an attacker to exploit this and can cause the program to enter these extreme situations by using a specially crafted input and cause the service to excessively consume CPU, resulting in a Denial of Service.

You can read more about Regular Expression Denial of Service (ReDoS) on our blog.

Remediation

Upgrade debug to version 2.6.9, 3.1.0 or higher.

References

Regular Expression Denial of Service (ReDoS)

low severity

Detailed paths

  • Introduced through: express@5.0.0-alpha.5 > debug@2.6.1 > ms@0.7.2
  • Introduced through: express@5.0.0-alpha.5 > send@0.15.1 > debug@2.6.1 > ms@0.7.2
  • Introduced through: express@5.0.0-alpha.5 > serve-static@1.12.1 > send@0.15.1 > debug@2.6.1 > ms@0.7.2
  • Introduced through: express@5.0.0-alpha.5 > send@0.15.1 > ms@0.7.2
  • Introduced through: express@5.0.0-alpha.5 > serve-static@1.12.1 > send@0.15.1 > ms@0.7.2

Overview

ms is a tiny millisecond conversion utility.

Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS) due to an incomplete fix for previously reported vulnerability npm:ms:20151024. The fix limited the length of accepted input string to 10,000 characters, and turned to be insufficient making it possible to block the event loop for 0.3 seconds (on a typical laptop) with a specially crafted string passed to ms() function.

Proof of concept

ms = require('ms');
ms('1'.repeat(9998) + 'Q') // Takes about ~0.3s

Note: Snyk's patch for this vulnerability limits input length to 100 characters. This new limit was deemed to be a breaking change by the author. Based on user feedback, we believe the risk of breakage is very low, while the value to your security is much greater, and therefore opted to still capture this change in a patch for earlier versions as well. Whenever patching security issues, we always suggest to run tests on your code to validate that nothing has been broken.

For more information on Regular Expression Denial of Service (ReDoS) attacks, go to our blog.

Disclosure Timeline

  • Feb 9th, 2017 - Reported the issue to package owner.
  • Feb 11th, 2017 - Issue acknowledged by package owner.
  • April 12th, 2017 - Fix PR opened by Snyk Security Team.
  • May 15th, 2017 - Vulnerability published.
  • May 16th, 2017 - Issue fixed and version 2.0.0 released.
  • May 21th, 2017 - Patches released for versions >=0.7.1, <=1.0.0.

Remediation

Upgrade ms to version 2.0.0 or higher.

References

Regular Expression Denial of Service (ReDoS)

high severity

Detailed paths

  • Introduced through: express@5.0.0-alpha.5 > fresh@0.5.0
  • Introduced through: express@5.0.0-alpha.5 > send@0.15.1 > fresh@0.5.0
  • Introduced through: express@5.0.0-alpha.5 > serve-static@1.12.1 > send@0.15.1 > fresh@0.5.0

Overview

fresh is HTTP response freshness testing.

Affected versions of this package are vulnerable to Regular expression Denial of Service (ReDoS) attacks. A Regular Expression (/ *, */) was used for parsing HTTP headers and take about 2 seconds matching time for 50k characters.

The Regular expression Denial of Service (ReDoS) is a type of Denial of Service attack. Many Regular Expression implementations may reach extreme situations that cause them to work very slowly (exponentially related to input size), allowing an attacker to exploit this and can cause the program to enter these extreme situations by using a specially crafted input and cause the service to excessively consume CPU, resulting in a Denial of Service.

You can read more about Regular Expression Denial of Service (ReDoS) on our blog.

Remediation

Upgrade fresh to version 0.5.2 or higher.

References

Fixed in 5.0.0-alpha.5

Prototype Override Protection Bypass

high severity
  • Vulnerable module: qs
  • Introduced through: qs@6.3.1

Detailed paths

  • Introduced through: express@5.0.0-alpha.4 > qs@6.3.1

Overview

qs is a querystring parser that supports nesting and arrays, with a depth limit.

By default qs protects against attacks that attempt to overwrite an object's existing prototype properties, such as toString(), hasOwnProperty(),etc.

From qs documentation:

By default parameters that would overwrite properties on the object prototype are ignored, if you wish to keep the data from those fields either use plainObjects as mentioned above, or set allowPrototypes to true which will allow user input to overwrite those properties. WARNING It is generally a bad idea to enable this option as it can cause problems when attempting to use the properties that have been overwritten. Always be careful with this option.

Overwriting these properties can impact application logic, potentially allowing attackers to work around security controls, modify data, make the application unstable and more.

In versions of the package affected by this vulnerability, it is possible to circumvent this protection and overwrite prototype properties and functions by prefixing the name of the parameter with [ or ]. e.g. qs.parse("]=toString") will return {toString = true}, as a result, calling toString() on the object will throw an exception.

Example:

qs.parse('toString=foo', { allowPrototypes: false })
// {}

qs.parse("]=toString", { allowPrototypes: false })
// {toString = true} <== prototype overwritten

For more information, you can check out our blog.

Disclosure Timeline

  • February 13th, 2017 - Reported the issue to package owner.
  • February 13th, 2017 - Issue acknowledged by package owner.
  • February 16th, 2017 - Partial fix released in versions 6.0.3, 6.1.1, 6.2.2, 6.3.1.
  • March 6th, 2017 - Final fix released in versions 6.4.0,6.3.2, 6.2.3, 6.1.2 and 6.0.4

Remediation

Upgrade qs to version 6.4.0 or higher. Note: The fix was backported to the following versions 6.3.2, 6.2.3, 6.1.2, 6.0.4.

References

Fixed in 5.0.0-alpha.3

Regular Expression Denial of Service (DoS)

high severity

Detailed paths

  • Introduced through: express@5.0.0-alpha.2 > accepts@1.2.13 > negotiator@0.5.3

Overview

negotiator is an HTTP content negotiator for Node.js. Versions prior to 0.6.1 are vulnerable to Regular expression Denial of Service (ReDoS) attack when parsing "Accept-Language" http header.

An attacker can provide a long value in the Accept-Language header, which nearly matches the pattern being matched. This will cause the regular expression matching to take a long time, all the while occupying the thread and preventing it from processing other requests. By repeatedly sending multiple such requests, the attacker can make the server unavailable (a Denial of Service attack).

Details

The Regular expression Denial of Service (ReDoS) is a Denial of Service attack, that exploits the fact that most Regular Expression implementations may reach extreme situations that cause them to work very slowly (exponentially related to input size). An attacker can then cause a program using a Regular Expression to enter these extreme situations and then hang for a very long time. [1]

Remediation

Upgrade negotiator to to version 0.6.1 or greater.

References

Fixed in 5.0.0-alpha.2

Root Path Disclosure

medium severity

Detailed paths

  • Introduced through: express@5.0.0-alpha.1 > send@0.10.1
  • Introduced through: express@5.0.0-alpha.1 > serve-static@1.7.2 > send@0.10.1

Overview

Send is a library for streaming files from the file system as an http response. It supports partial responses (Ranges), conditional-GET negotiation, high test coverage, and granular events which may be leveraged to take appropriate actions in your application or framework.

A root path disclosure vulnerability exists in send versions prior to 0.11.1.

Remediation

Upgrade send to version 0.11.1. or greater.

If a direct dependency update is not possible, use snyk wizard to patch this vulnerability.

References

Regular Expression Denial of Service (DoS)

medium severity

Detailed paths

  • Introduced through: express@5.0.0-alpha.1 > debug@2.1.3 > ms@0.7.0
  • Introduced through: express@5.0.0-alpha.1 > finalhandler@0.3.2 > debug@2.1.3 > ms@0.7.0
  • Introduced through: express@5.0.0-alpha.1 > send@0.10.1 > debug@2.1.3 > ms@0.7.0
  • Introduced through: express@5.0.0-alpha.1 > serve-static@1.7.2 > send@0.10.1 > debug@2.1.3 > ms@0.7.0
  • Introduced through: express@5.0.0-alpha.1 > send@0.10.1 > ms@0.6.2
  • Introduced through: express@5.0.0-alpha.1 > serve-static@1.7.2 > send@0.10.1 > ms@0.6.2

Overview

ms is a tiny milisecond conversion utility.

Affected versions of this package are vulnerable to a Regular expression Denial of Service (ReDoS) attack when converting a time period string (i.e. "2 days", "1h") into milliseconds integer. A malicious user could pas extremely long strings to ms(), causing the server take a long time to process, subsequently blocking the event loop for that extended period.

Details

The Regular expression Denial of Service (ReDoS) is a type of Denial of Service attack. Many Regular Expression implementations may reach extreme situations that cause them to work very slowly (exponentially related to input size), allowing an attacker to exploit this and can cause the program to enter these extreme situations by using a specially crafted input and cause the service to excessively consume CPU, resulting in a Denial of Service.

Remediation

Upgrade ms to version 0.7.1.

If direct dependency upgrade is not possible, use snyk wizard to patch this vulnerability.

References

Root Path Disclosure

low severity

Detailed paths

  • Introduced through: express@5.0.0-alpha.1 > serve-static@1.7.2

Overview:

root path disclosure vulnerability in express.static, res.sendfile, and res.sendFile

Original description taken from the Node Security Project

Recommendations:

  • Update to version 1.8.1 or greater.

References:

Fixed in 4.9.0

Open Redirect

low severity

Detailed paths

  • Introduced through: express@4.8.8 > serve-static@1.5.4

Overview

When using serve-static middleware version < 1.7.2 and it's configured to mount at the root, it creates an open redirect on the site.

Source: Node Security Project

Details

For example:

If a user visits http://example.com//www.google.com/%2e%2e they will be redirected to //www.google.com/%2e%2e, which some browsers interpret as http://www.google.com/%2e%2e.

Remediation

  • Update to version 1.7.2 or greater (or 1.6.5 if sticking to the 1.6.x line).
  • Disable redirects if not using the feature with 'redirect: false' option and cannot upgrade.

References

Fixed in 4.8.8

Directory Traversal

medium severity
  • Vulnerable module: send
  • Introduced through: send@0.8.3

Detailed paths

  • Introduced through: express@4.8.7 > send@0.8.3

Overview

When relying on the root option to restrict file access it may be possible for an application consumer to escape out of the restricted directory and access files in a similarly named directory. For example, static(_dirname + '/public') would allow access to _dirname + '/public-restricted'.

Source: Node Security Project

Remediation

Upgrade to a version greater than or equal to 0.8.4.

References

Fixed in 4.8.0

Denial of Service (Memory Exhaustion)

high severity
  • Vulnerable module: qs
  • Introduced through: qs@0.6.6

Detailed paths

  • Introduced through: express@4.7.4 > qs@0.6.6

Overview

qs is a querystring parser that supports nesting and arrays, with a depth limit.

During parsing, the qs module may create a sparse area (an array where no elements are filled), and grow that array to the necessary size based on the indices used on it. An attacker can specify a high index value in a query string, thus making the server allocate a respectively big array. Truly large values can cause the server to run out of memory and cause it to crash - thus enabling a Denial-of-Service attack.

Remediation

Upgrade qs to version 1.0.0 or greater. In these versions, qs introduced a low limit on the index value, preventing such an attack

References

Denial of Service (Event Loop Blocking)

medium severity
  • Vulnerable module: qs
  • Introduced through: qs@0.6.6

Detailed paths

  • Introduced through: express@4.7.4 > qs@0.6.6

Overview

qs is a querystring parser that supports nesting and arrays, with a depth limit.

When parsing a string representing a deeply nested object, qs will block the event loop for long periods of time. Such a delay may hold up the server's resources, keeping it from processing other requests in the meantime, thus enabling a Denial-of-Service attack.

Remediation

Update qs to version 1.0.0 or higher. In these versions, qs enforces a max object depth (along with other limits), limiting the event loop length and thus preventing such an attack.

References

Fixed in 4.5.0

Cross-site Scripting (XSS)

medium severity

Detailed paths

  • Introduced through: express@4.4.5

Overview

express is a minimalist web framework.

Affected versions of this package do not enforce the user's browser to set a specific charset in the content-type header while displaying 400 level response messages. This could be used by remote attackers to perform a cross-site scripting attack, by using non-standard encodings like UTF-7.

Recommendations

Update express to 3.11.0, 4.5.0 or higher.

References

Fixed in 4.4.5

Non-Constant Time String Comparison

medium severity

Detailed paths

  • Introduced through: express@4.4.4 > cookie-signature@1.0.3

Overview

'cookie-signature' is a library for signing cookies.

Versions before 1.0.4 of the library use the built-in string comparison mechanism, ===, and not a time constant string comparison. As a result, the comparison will fail faster when the first characters in the token are incorrect. An attacker can use this difference to perform a timing attack, essentially allowing them to guess the secret one character at a time.

You can read more about timing attacks in Node.js on the Snyk blog: https://snyk.io/blog/node-js-timing-attack-ccc-ctf/

Remediation

Upgrade to 1.0.4 or greater.

References

Fixed in 3.19.0

Cross-site Scripting due to improper file and directory names escaping

medium severity

Detailed paths

  • Introduced through: express@3.18.6 > connect@2.27.6 > serve-index@1.5.3

Overview

When using serve-index middleware version < 1.6.3 file and directory names are not escaped in HTML output. If remote users can influence file or directory names, this can trigger a persistent XSS attack.

Source: Node Security Project

Remediation

Upgrade to version 1.6.3 or greater

References

Fixed in 3.18.0

Regular Expression Denial of Service (ReDoS)

high severity
  • Vulnerable module: method-override
  • Introduced through: connect@2.26.6

Detailed paths

  • Introduced through: express@3.17.8 > connect@2.26.6 > method-override@2.2.0

Overview

method-override is a module to override HTTP verbs.

Affected versions of this package are vulnerable to Regular expression Denial of Service (ReDoS). It uses regex the following regex / *, */ in order to split HTTP headers. An attacker may send specially crafted input in the X-HTTP-Method-Override header and cause a significant slowdown.

The Regular expression Denial of Service (ReDoS) is a type of Denial of Service attack. Many Regular Expression implementations may reach extreme situations that cause them to work very slowly (exponentially related to input size), allowing an attacker to exploit this and can cause the program to enter these extreme situations by using a specially crafted input and cause the service to excessively consume CPU, resulting in a Denial of Service.

You can read more about Regular Expression Denial of Service (ReDoS) on our blog.

Remediation

Upgrade method-override to version 2.3.10 or higher.

References

Fixed in 3.3.1

methodOverride Middleware Reflected Cross-site Scripting (XSS)

medium severity

Detailed paths

  • Introduced through: express@3.3.0 > connect@2.8.0

Overview

Connect is a stack of middleware that is executed in order in each request.

The "methodOverride" middleware allows the http post to override the method of the request with the value of the _method post key or with the header "x-http-method-override".

Because the user post input was not checked, req.method could contain any kind of value. Because the req.method did not match any common method VERB, connect answered with a 404 page containing the "Cannot [method] [url]" content. The method was not properly encoded for output in the browser.

Source: Node Security Project

Details

Example

~ curl "localhost:3000" -d "_method=<script src=http://nodesecurity.io/xss.js></script>"
Cannot <SCRIPT SRC=HTTP://NODESECURITY.IO/XSS.JS></SCRIPT> /

Mitigation factors

Update to the newest version of Connect or disable methodOverride. It is not possible to avoid the vulnerability if you have enabled this middleware in the top of your stack.

History

Fixed in 3.0.0

Denial of Service (DoS)

medium severity

Detailed paths

  • Introduced through: express@2.5.11 > connect@1.9.2

Overview

connect is a high performance middleware framework.

Affected versions of the package are vulnerable to Denial of Service (DoS) attacks. It is possible to crash the node server by requesting a url with a trailing backslash in the end.

Remediation

Upgrade connect to version 2.0.0 or higher.

References