Last tested: 19 Feb, 2018

jsonwebtoken vulnerabilities

JSON Web Token implementation (symmetric and asymmetric)

View on npm

jsonwebtoken (latest)

Published 17 Feb, 2018

Known vulnerabilities0
Vulnerable paths0
Dependencies16

No known vulnerabilities in jsonwebtoken

Security wise, jsonwebtoken seems to be a safe package to use.
Over time, new vulnerabilities may be disclosed on jsonwebtoken and other packages. To easily find, fix and prevent such vulnerabilties, protect your repos with Snyk!

Vulnerable versions of jsonwebtoken

Fixed in 8.0.0

Prototype Pollution

low severity

Detailed paths

  • Introduced through: jsonwebtoken@7.4.3 > joi@6.10.1 > hoek@2.16.3
  • Introduced through: jsonwebtoken@7.4.3 > joi@6.10.1 > topo@1.1.0 > hoek@2.16.3

Overview

hoek is a Utility methods for the hapi ecosystem.

Affected versions of this package are vulnerable to Prototype Pollution. The utilities function allow modification of the Object prototype. If an attacker can control part of the structure passed to this function, they could add or modify an existing property.

PoC by Olivier Arteau (HoLyVieR)

var Hoek = require('hoek');
var malicious_payload = '{"__proto__":{"oops":"It works !"}}';

var a = {};
console.log("Before : " + a.oops);
Hoek.merge({}, JSON.parse(malicious_payload));
console.log("After : " + a.oops);

Remediation

Upgrade hoek to versions 4.2.1, 5.0.3 or higher.

References

Fixed in 7.4.1

Regular Expression Denial of Service (ReDoS)

low severity
  • Vulnerable module: ms
  • Introduced through: ms@0.7.3

Detailed paths

  • Introduced through: jsonwebtoken@7.4.0 > ms@0.7.3

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

Fixed in 5.0.0

Forgeable Public/Private Tokens

high severity
  • Vulnerable module: jws
  • Introduced through: jws@2.0.0

Detailed paths

  • Introduced through: jsonwebtoken@4.2.2 > jws@2.0.0

Overview

jws is an implementation of JSON Web Signatures. Affected versions of this package are vulnerable to an Authentication Bypass attack, due to the "algorithm" not being enforced in jws.verify(). Attackers are given the opportunity to choose the algorithm sent to the server and generate signatures with arbitrary contents. The server expects an asymmetric key (RSA) but is sent a symmetric key (HMAC-SHA) with RSA's public key, so instead of going through a key validation process, the server will think the public key is actually an HMAC private key.

Remediation

Upgrade jws to version 3.0.0 or later.

References

Uninitialized Memory Exposure

medium severity

Detailed paths

  • Introduced through: browserify@4.2.2 > concat-stream@1.4.10
  • Introduced through: browserify@4.2.2 > insert-module-globals@6.0.0 > concat-stream@1.4.10
  • Introduced through: browserify@4.2.2 > module-deps@2.1.5 > concat-stream@1.4.10
  • Introduced through: jsonwebtoken@4.2.2 > jws@2.0.0 > base64url@1.0.6 > concat-stream@1.4.10

Overview

concat-stream is writable stream that concatenates strings or binary data and calls a callback with the result. Affected versions of the package are vulnerable to Uninitialized Memory Exposure.

A possible memory disclosure vulnerability exists when a value of type number is provided to the stringConcat() method and results in concatenation of uninitialized memory to the stream collection.

This is a result of unobstructed use of the Buffer constructor, whose insecure default constructor increases the odds of memory leakage.

Details

Constructing a Buffer class with integer N creates a Buffer of length N with raw (not "zero-ed") memory.

In the following example, the first call would allocate 100 bytes of memory, while the second example will allocate the memory needed for the string "100":

// uninitialized Buffer of length 100
x = new Buffer(100);
// initialized Buffer with value of '100'
x = new Buffer('100');

concat-stream's stringConcat function uses the default Buffer constructor as-is, making it easy to append uninitialized memory to an existing list. If the value of the buffer list is exposed to users, it may expose raw server side memory, potentially holding secrets, private data and code. This is a similar vulnerability to the infamous Heartbleed flaw in OpenSSL.

You can read more about the insecure Buffer behavior on our blog.

Similar vulnerabilities were discovered in request, mongoose, ws and sequelize.

Remediation

Upgrade concat-stream to version 1.5.2 or higher.

References

Fixed in 4.2.2

Authentication Bypass

high severity

Detailed paths

  • Introduced through: jsonwebtoken@4.2.1

Overview

jsonwebtoken is a JSON Web token implementation for symmetric and asymmetric keys. Affected versions of this package are vulnerable to an Authentication Bypass attack, due to the "algorithm" not being enforced. Attackers are given the opportunity to choose the algorithm sent to the server and generate signatures with arbitrary contents. The server expects an asymmetric key (RSA) but is sent a symmetric key (HMAC-SHA) with RSA's public key, so instead of going through a key validation process, the server will think the public key is actually an HMAC private key.

Remediation

Upgrade jsonwebtoken to version 4.2.2 or greater.

References

Fixed in 0.3.0

Regular Expression Denial of Service (ReDoS)

medium severity

Detailed paths

  • Introduced through: hapi@0.2.0 > emailjs@0.3.16 > moment@1.7.0
  • Introduced through: jsonwebtoken@0.2.0 > moment@2.0.0

Overview

moment is a lightweight JavaScript date library for parsing, validating, manipulating, and formatting dates.

Affected versions of the package are vulnerable to Regular Expression Denial of Service (ReDoS) attacks for any locale that has separate format and standalone options and format input can be controlled by the user.

An attacker can provide a specially crafted input to the format function, which nearly matches the pattern being matched. This will cause the regular expression matching to take a long time, all the while occupying the event loop and preventing it from processing other requests and making the server unavailable (a Denial of Service attack).

Disclosure Timeline

  • October 19th, 2016 - Reported the issue to package owner.
  • October 19th, 2016 - Issue acknowledged by package owner.
  • October 24th, 2016 - Issue fixed and version 2.15.2 released.

References

Regular Expression Denial of Service (ReDoS)

low severity

Detailed paths

  • Introduced through: hapi@0.2.0 > emailjs@0.3.16 > moment@1.7.0
  • Introduced through: jsonwebtoken@0.2.0 > moment@2.0.0

Overview

moment is a lightweight JavaScript date library for parsing, validating, manipulating, and formatting dates.

An attacker can provide a long value to the duration function, which nearly matches the pattern being matched. This will cause the regular expression matching to take a long time, all the while occupying the event loop and preventing it from processing other requests and making the server unavailable (a Denial of Service attack).

"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 moment to version 2.11.2 or greater.

References

Regular Expression Denial of Service (ReDoS)

low severity

Detailed paths

  • Introduced through: hapi@0.2.0 > emailjs@0.3.16 > moment@1.7.0
  • Introduced through: jsonwebtoken@0.2.0 > moment@2.0.0

Overview

moment is a lightweight JavaScript date library for parsing, validating, manipulating, and formatting dates.

Affected versions of this package are vulnerable to Regular expression Denial of Service (ReDoS) attacks. It used a regular expression (/[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i) in order to parse dates specified as strings. This can cause a very low impact of about 2 seconds matching time for data 50k characters long.

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.

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

Remediation

Upgrade moment to version 2.19.3 or higher.

References