Last tested: 31 Jul, 2018

gulp-imagemin vulnerabilities

Minify PNG, JPEG, GIF and SVG images

View on npm

gulp-imagemin (latest)

Published 21 Mar, 2018

Known vulnerabilities2
Vulnerable paths21
Dependencies435

Regular Expression Denial of Service (ReDoS)

low severity

Detailed paths

  • Introduced through: gulp-imagemin@4.1.0 > imagemin-jpegtran@5.0.2 > jpegtran-bin@3.2.0 > bin-wrapper@3.0.2 > download@4.4.3 > vinyl-fs@2.4.4 > glob-stream@5.3.5 > micromatch@2.3.11 > braces@1.8.5
  • Introduced through: gulp-imagemin@4.1.0 > imagemin-gifsicle@5.2.0 > gifsicle@3.0.4 > bin-wrapper@3.0.2 > download@4.4.3 > vinyl-fs@2.4.4 > glob-stream@5.3.5 > micromatch@2.3.11 > braces@1.8.5
  • Introduced through: gulp-imagemin@4.1.0 > imagemin-optipng@5.2.1 > optipng-bin@3.1.4 > bin-wrapper@3.0.2 > download@4.4.3 > vinyl-fs@2.4.4 > glob-stream@5.3.5 > micromatch@2.3.11 > braces@1.8.5
  • Introduced through: gulp-imagemin@4.1.0 > imagemin-jpegtran@5.0.2 > jpegtran-bin@3.2.0 > bin-build@2.2.0 > download@4.4.3 > vinyl-fs@2.4.4 > glob-stream@5.3.5 > micromatch@2.3.11 > braces@1.8.5
  • Introduced through: gulp-imagemin@4.1.0 > imagemin-gifsicle@5.2.0 > gifsicle@3.0.4 > bin-build@2.2.0 > download@4.4.3 > vinyl-fs@2.4.4 > glob-stream@5.3.5 > micromatch@2.3.11 > braces@1.8.5
  • Introduced through: gulp-imagemin@4.1.0 > imagemin-optipng@5.2.1 > optipng-bin@3.1.4 > bin-build@2.2.0 > download@4.4.3 > vinyl-fs@2.4.4 > glob-stream@5.3.5 > micromatch@2.3.11 > braces@1.8.5
  • Introduced through: gulp-imagemin@4.1.0 > imagemin-jpegtran@5.0.2 > jpegtran-bin@3.2.0 > bin-build@2.2.0 > decompress@3.0.0 > vinyl-fs@2.4.4 > glob-stream@5.3.5 > micromatch@2.3.11 > braces@1.8.5
  • Introduced through: gulp-imagemin@4.1.0 > imagemin-gifsicle@5.2.0 > gifsicle@3.0.4 > bin-build@2.2.0 > decompress@3.0.0 > vinyl-fs@2.4.4 > glob-stream@5.3.5 > micromatch@2.3.11 > braces@1.8.5
  • Introduced through: gulp-imagemin@4.1.0 > imagemin-optipng@5.2.1 > optipng-bin@3.1.4 > bin-build@2.2.0 > decompress@3.0.0 > vinyl-fs@2.4.4 > glob-stream@5.3.5 > micromatch@2.3.11 > braces@1.8.5
  • Introduced through: gulp-imagemin@4.1.0 > imagemin-jpegtran@5.0.2 > jpegtran-bin@3.2.0 > bin-wrapper@3.0.2 > download@4.4.3 > gulp-decompress@1.2.0 > decompress@3.0.0 > vinyl-fs@2.4.4 > glob-stream@5.3.5 > micromatch@2.3.11 > braces@1.8.5
  • Introduced through: gulp-imagemin@4.1.0 > imagemin-gifsicle@5.2.0 > gifsicle@3.0.4 > bin-wrapper@3.0.2 > download@4.4.3 > gulp-decompress@1.2.0 > decompress@3.0.0 > vinyl-fs@2.4.4 > glob-stream@5.3.5 > micromatch@2.3.11 > braces@1.8.5
  • Introduced through: gulp-imagemin@4.1.0 > imagemin-optipng@5.2.1 > optipng-bin@3.1.4 > bin-wrapper@3.0.2 > download@4.4.3 > gulp-decompress@1.2.0 > decompress@3.0.0 > vinyl-fs@2.4.4 > glob-stream@5.3.5 > micromatch@2.3.11 > braces@1.8.5
  • Introduced through: gulp-imagemin@4.1.0 > imagemin-jpegtran@5.0.2 > jpegtran-bin@3.2.0 > bin-build@2.2.0 > download@4.4.3 > gulp-decompress@1.2.0 > decompress@3.0.0 > vinyl-fs@2.4.4 > glob-stream@5.3.5 > micromatch@2.3.11 > braces@1.8.5
  • Introduced through: gulp-imagemin@4.1.0 > imagemin-gifsicle@5.2.0 > gifsicle@3.0.4 > bin-build@2.2.0 > download@4.4.3 > gulp-decompress@1.2.0 > decompress@3.0.0 > vinyl-fs@2.4.4 > glob-stream@5.3.5 > micromatch@2.3.11 > braces@1.8.5
  • Introduced through: gulp-imagemin@4.1.0 > imagemin-optipng@5.2.1 > optipng-bin@3.1.4 > bin-build@2.2.0 > download@4.4.3 > gulp-decompress@1.2.0 > decompress@3.0.0 > vinyl-fs@2.4.4 > glob-stream@5.3.5 > micromatch@2.3.11 > braces@1.8.5

Overview

braces is a Bash-like brace expansion, implemented in JavaScript.

Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS) attacks. It used a regular expression (^\{(,+(?:(\{,+\})*),*|,*(?:(\{,+\})*),+)\}) in order to detects empty braces. This can cause an impact of about 10 seconds matching time for data 50K characters long.

Disclosure Timeline

  • Feb 15th, 2018 - Initial Disclosure to package owner
  • Feb 16th, 2018 - Initial Response from package owner
  • Feb 18th, 2018 - Fix issued
  • Feb 19th, 2018 - Vulnerability published

Details

Denial of Service (DoS) describes a family of attacks, all aimed at making a system inaccessible to its original and legitimate users. There are many types of DoS attacks, ranging from trying to clog the network pipes to the system by generating a large volume of traffic from many machines (a Distributed Denial of Service - DDoS - attack) to sending crafted requests that cause a system to crash or take a disproportional amount of time to process.

The Regular expression Denial of Service (ReDoS) is a type of Denial of Service attack. Regular expressions are incredibly powerful, but they aren't very intuitive and can ultimately end up making it easy for attackers to take your site down.

Let’s take the following regular expression as an example:

regex = /A(B|C+)+D/

This regular expression accomplishes the following:

  • A The string must start with the letter 'A'
  • (B|C+)+ The string must then follow the letter A with either the letter 'B' or some number of occurrences of the letter 'C' (the + matches one or more times). The + at the end of this section states that we can look for one or more matches of this section.
  • D Finally, we ensure this section of the string ends with a 'D'

The expression would match inputs such as ABBD, ABCCCCD, ABCBCCCD and ACCCCCD

It most cases, it doesn't take very long for a regex engine to find a match:

$ time node -e '/A(B|C+)+D/.test("ACCCCCCCCCCCCCCCCCCCCCCCCCCCCD")'
0.04s user 0.01s system 95% cpu 0.052 total

$ time node -e '/A(B|C+)+D/.test("ACCCCCCCCCCCCCCCCCCCCCCCCCCCCX")'
1.79s user 0.02s system 99% cpu 1.812 total

The entire process of testing it against a 30 characters long string takes around ~52ms. But when given an invalid string, it takes nearly two seconds to complete the test, over ten times as long as it took to test a valid string. The dramatic difference is due to the way regular expressions get evaluated.

Most Regex engines will work very similarly (with minor differences). The engine will match the first possible way to accept the current character and proceed to the next one. If it then fails to match the next one, it will backtrack and see if there was another way to digest the previous character. If it goes too far down the rabbit hole only to find out the string doesn’t match in the end, and if many characters have multiple valid regex paths, the number of backtracking steps can become very large, resulting in what is known as catastrophic backtracking.

Let's look at how our expression runs into this problem, using a shorter string: "ACCCX". While it seems fairly straightforward, there are still four different ways that the engine could match those three C's:

  1. CCC
  2. CC+C
  3. C+CC
  4. C+C+C.

The engine has to try each of those combinations to see if any of them potentially match against the expression. When you combine that with the other steps the engine must take, we can use RegEx 101 debugger to see the engine has to take a total of 38 steps before it can determine the string doesn't match.

From there, the number of steps the engine must use to validate a string just continues to grow.

String Number of C's Number of steps
ACCCX 3 38
ACCCCX 4 71
ACCCCCX 5 136
ACCCCCCCCCCCCCCX 14 65,553

By the time the string includes 14 C's, the engine has to take over 65,000 steps just to see if the string is valid. These extreme situations can cause them to work very slowly (exponentially related to input size, as shown above), allowing an attacker to exploit this and can cause the service to excessively consume CPU, resulting in a Denial of Service.

Remediation

Upgrade braces to version 2.3.1 or higher.

References

Uninitialized Memory Exposure

medium severity

Detailed paths

  • Introduced through: gulp-imagemin@4.1.0 > imagemin-jpegtran@5.0.2 > jpegtran-bin@3.2.0 > bin-build@2.2.0 > download@4.4.3 > caw@1.2.0 > tunnel-agent@0.4.3
  • Introduced through: gulp-imagemin@4.1.0 > imagemin-gifsicle@5.2.0 > gifsicle@3.0.4 > bin-build@2.2.0 > download@4.4.3 > caw@1.2.0 > tunnel-agent@0.4.3
  • Introduced through: gulp-imagemin@4.1.0 > imagemin-optipng@5.2.1 > optipng-bin@3.1.4 > bin-build@2.2.0 > download@4.4.3 > caw@1.2.0 > tunnel-agent@0.4.3
  • Introduced through: gulp-imagemin@4.1.0 > imagemin-jpegtran@5.0.2 > jpegtran-bin@3.2.0 > bin-wrapper@3.0.2 > download@4.4.3 > caw@1.2.0 > tunnel-agent@0.4.3
  • Introduced through: gulp-imagemin@4.1.0 > imagemin-gifsicle@5.2.0 > gifsicle@3.0.4 > bin-wrapper@3.0.2 > download@4.4.3 > caw@1.2.0 > tunnel-agent@0.4.3
  • Introduced through: gulp-imagemin@4.1.0 > imagemin-optipng@5.2.1 > optipng-bin@3.1.4 > bin-wrapper@3.0.2 > download@4.4.3 > caw@1.2.0 > tunnel-agent@0.4.3

Overview

tunnel-agent is HTTP proxy tunneling agent. Affected versions of the package are vulnerable to Uninitialized Memory Exposure.

A possible memory disclosure vulnerability exists when a value of type number is used to set the proxy.auth option of a request request and results in a possible uninitialized memory exposures in the request body.

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');

tunnel-agent's request construction 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.

Proof of concept by ChALkeR

require('request')({
  method: 'GET',
  uri: 'http://www.example.com',
  tunnel: true,
  proxy:{
      protocol: 'http:',
      host:"127.0.0.1",
      port:8080,
      auth:80
  }
});

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

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

Remediation

Upgrade tunnel-agent to version 0.6.0 or higher. Note This is vulnerable only for Node <=4

References

Vulnerable versions of gulp-imagemin

Fixed in 2.4.0

Prototype Pollution

low severity

Detailed paths

  • Introduced through: gulp@2.3.0 > gaze@0.4.2 > globule@0.1.0 > lodash@1.0.2
  • Introduced through: lodash@2.3.0
  • Introduced through: browser-sync@2.3.0 > easy-extender@2.3.2 > lodash@3.10.1
  • Introduced through: browser-sync@2.3.0 > eazy-logger@2.1.3 > opt-merger@1.1.1 > lodash@3.10.1
  • Introduced through: browser-sync@2.3.0 > foxy@10.1.2 > eazy-logger@2.1.3 > opt-merger@1.1.1 > lodash@3.10.1
  • Introduced through: browser-sync@2.3.0 > lodash@3.10.1
  • Introduced through: browser-sync@2.3.0 > glob-watcher@0.0.8 > gaze@0.5.2 > globule@0.1.0 > lodash@1.0.2
  • Introduced through: gulp-imagemin@2.3.0 > imagemin@3.2.2 > vinyl-fs@1.0.0 > glob-watcher@0.0.8 > gaze@0.5.2 > globule@0.1.0 > lodash@1.0.2

Overview

lodash is a javaScript utility library delivering modularity, performance & extras.

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 _= require('lodash');
var malicious_payload = '{"__proto__":{"oops":"It works !"}}';

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

Remediation

Upgrade lodash to version 4.17.5 or higher.

References

Regular Expression Denial of Service (DoS)

high severity

Detailed paths

  • Introduced through: gulp@2.3.0 > gaze@0.4.2 > globule@0.1.0 > minimatch@0.2.14
  • Introduced through: gulp@2.3.0 > gaze@0.4.2 > globule@0.1.0 > glob@3.1.21 > minimatch@0.2.14
  • Introduced through: mocha@2.3.0 > glob@3.2.3 > minimatch@0.2.14
  • Introduced through: browser-sync@2.3.0 > foxy@10.1.2 > resp-modifier@2.1.0 > minimatch@2.0.10
  • Introduced through: browser-sync@2.3.0 > resp-modifier@2.1.0 > minimatch@2.0.10
  • Introduced through: browser-sync@2.3.0 > glob-watcher@0.0.8 > gaze@0.5.2 > globule@0.1.0 > minimatch@0.2.14
  • Introduced through: browser-sync@2.3.0 > glob-watcher@0.0.8 > gaze@0.5.2 > globule@0.1.0 > glob@3.1.21 > minimatch@0.2.14
  • Introduced through: gulp-imagemin@2.3.0 > imagemin@3.2.2 > vinyl-fs@1.0.0 > glob-stream@4.1.1 > minimatch@2.0.10
  • Introduced through: gulp-imagemin@2.3.0 > imagemin@3.2.2 > vinyl-fs@1.0.0 > glob-stream@4.1.1 > glob@4.5.3 > minimatch@2.0.10
  • Introduced through: gulp-imagemin@2.3.0 > imagemin@3.2.2 > vinyl-fs@1.0.0 > glob-watcher@0.0.8 > gaze@0.5.2 > globule@0.1.0 > minimatch@0.2.14
  • Introduced through: gulp-imagemin@2.3.0 > imagemin@3.2.2 > vinyl-fs@1.0.0 > glob-watcher@0.0.8 > gaze@0.5.2 > globule@0.1.0 > glob@3.1.21 > minimatch@0.2.14

Overview

minimatch is a minimalistic matching library used for converting glob expressions into JavaScript RegExp objects. Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS) attacks.

The Regular expression Denial of Service (ReDoS) is a type of Denial of Service attack. Many Regular Expression implementations may reach edge cases that causes 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.

An attacker can provide a long value to the minimatch 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).

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

Remediation

Upgrade minimatch to version 3.0.2 or greater.

References

Fixed in 2.0.0

Regular Expression Denial of Service (ReDoS)

high severity

Detailed paths

  • Introduced through: yo@1.2.1 > insight@0.3.1 > configstore@0.2.3 > js-yaml@3.0.2 > argparse@0.1.16 > underscore.string@2.4.0
  • Introduced through: yo@1.2.1 > yeoman-generator@0.17.7 > underscore.string@2.4.0
  • Introduced through: gulp-imagemin@1.2.1 > imagemin@2.2.1 > imagemin-svgo@3.0.3 > svgo@0.4.5 > js-yaml@2.1.3 > argparse@0.1.16 > underscore.string@2.4.0

Overview

underscore.string is a String manipulation helpers for javascript.

Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS). It parses dates using regex strings, which may cause a slowdown of 2 seconds per 50k characters.

Details

Denial of Service (DoS) describes a family of attacks, all aimed at making a system inaccessible to its original and legitimate users. There are many types of DoS attacks, ranging from trying to clog the network pipes to the system by generating a large volume of traffic from many machines (a Distributed Denial of Service - DDoS - attack) to sending crafted requests that cause a system to crash or take a disproportional amount of time to process.

The Regular expression Denial of Service (ReDoS) is a type of Denial of Service attack. Regular expressions are incredibly powerful, but they aren't very intuitive and can ultimately end up making it easy for attackers to take your site down.

Let’s take the following regular expression as an example:

regex = /A(B|C+)+D/

This regular expression accomplishes the following:

  • A The string must start with the letter 'A'
  • (B|C+)+ The string must then follow the letter A with either the letter 'B' or some number of occurrences of the letter 'C' (the + matches one or more times). The + at the end of this section states that we can look for one or more matches of this section.
  • D Finally, we ensure this section of the string ends with a 'D'

The expression would match inputs such as ABBD, ABCCCCD, ABCBCCCD and ACCCCCD

It most cases, it doesn't take very long for a regex engine to find a match:

$ time node -e '/A(B|C+)+D/.test("ACCCCCCCCCCCCCCCCCCCCCCCCCCCCD")'
0.04s user 0.01s system 95% cpu 0.052 total

$ time node -e '/A(B|C+)+D/.test("ACCCCCCCCCCCCCCCCCCCCCCCCCCCCX")'
1.79s user 0.02s system 99% cpu 1.812 total

The entire process of testing it against a 30 characters long string takes around ~52ms. But when given an invalid string, it takes nearly two seconds to complete the test, over ten times as long as it took to test a valid string. The dramatic difference is due to the way regular expressions get evaluated.

Most Regex engines will work very similarly (with minor differences). The engine will match the first possible way to accept the current character and proceed to the next one. If it then fails to match the next one, it will backtrack and see if there was another way to digest the previous character. If it goes too far down the rabbit hole only to find out the string doesn’t match in the end, and if many characters have multiple valid regex paths, the number of backtracking steps can become very large, resulting in what is known as catastrophic backtracking.

Let's look at how our expression runs into this problem, using a shorter string: "ACCCX". While it seems fairly straightforward, there are still four different ways that the engine could match those three C's:

  1. CCC
  2. CC+C
  3. C+CC
  4. C+C+C.

The engine has to try each of those combinations to see if any of them potentially match against the expression. When you combine that with the other steps the engine must take, we can use RegEx 101 debugger to see the engine has to take a total of 38 steps before it can determine the string doesn't match.

From there, the number of steps the engine must use to validate a string just continues to grow.

String Number of C's Number of steps
ACCCX 3 38
ACCCCX 4 71
ACCCCCX 5 136
ACCCCCCCCCCCCCCX 14 65,553

By the time the string includes 14 C's, the engine has to take over 65,000 steps just to see if the string is valid. These extreme situations can cause them to work very slowly (exponentially related to input size, as shown above), allowing an attacker to exploit this and can cause the service to excessively consume CPU, resulting in a Denial of Service.

Remediation

There is no fix version for underscore.string.

References

Fixed in 1.1.0

Prototype Pollution

low severity

Detailed paths

  • Introduced through: bower@1.0.1 > bower-json@0.2.0 > deep-extend@0.2.11
  • Introduced through: gulp-imagemin@1.0.1 > imagemin@1.0.5 > imagemin-gifsicle@1.0.0 > gifsicle@1.0.3 > bin-wrapper@1.0.5 > download@3.3.0 > rc@0.5.5 > deep-extend@0.2.11
  • Introduced through: gulp-imagemin@1.0.1 > imagemin@1.0.5 > imagemin-jpegtran@1.0.0 > jpegtran-bin@1.0.2 > bin-wrapper@1.0.5 > download@3.3.0 > rc@0.5.5 > deep-extend@0.2.11
  • Introduced through: gulp-imagemin@1.0.1 > imagemin@1.0.5 > imagemin-optipng@1.0.0 > optipng-bin@1.0.1 > bin-wrapper@1.0.5 > download@3.3.0 > rc@0.5.5 > deep-extend@0.2.11
  • Introduced through: gulp-imagemin@1.0.1 > imagemin@1.0.5 > imagemin-pngquant@1.0.2 > pngquant-bin@1.0.1 > bin-wrapper@1.0.5 > download@3.3.0 > rc@0.5.5 > deep-extend@0.2.11
  • Introduced through: gulp-imagemin@1.0.1 > imagemin@1.0.5 > imagemin-gifsicle@1.0.0 > gifsicle@1.0.3 > bin-build@1.1.0 > download@3.3.0 > rc@0.5.5 > deep-extend@0.2.11
  • Introduced through: gulp-imagemin@1.0.1 > imagemin@1.0.5 > imagemin-jpegtran@1.0.0 > jpegtran-bin@1.0.2 > bin-build@1.1.0 > download@3.3.0 > rc@0.5.5 > deep-extend@0.2.11
  • Introduced through: gulp-imagemin@1.0.1 > imagemin@1.0.5 > imagemin-optipng@1.0.0 > optipng-bin@1.0.1 > bin-build@1.1.0 > download@3.3.0 > rc@0.5.5 > deep-extend@0.2.11
  • Introduced through: gulp-imagemin@1.0.1 > imagemin@1.0.5 > imagemin-pngquant@1.0.2 > pngquant-bin@1.0.1 > bin-build@1.1.0 > download@3.3.0 > rc@0.5.5 > deep-extend@0.2.11

Overview

Affected versions of deep-extend are vulnerable to Prototype Pollution. Utilities function in all the listed modules can be tricked into modifying the prototype of "Object" when the attacker control part of the structure passed to these function. This can let an attacker add or modify existing property that will exist on all object.

PoC by HoLyVieR

var merge = require('deep-extend');
var malicious_payload = '{"__proto__":{"oops":"It works !"}}';

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

Remediation

Upgrade deep-extend to version 0.5.1 or higher.

References

Arbitrary Code Execution

high severity

Detailed paths

  • Introduced through: gulp-imagemin@1.0.1 > imagemin@1.0.5 > imagemin-gifsicle@1.0.0 > gifsicle@1.0.3

Overview

gifsicle manipulates GIF image files in many different ways.

Affected versions of this package are vulnerable to Arbitrary Code Execution. Use-after-free in the read_gif function may result in potential code execution.

Remediation

Upgrade gifsicle to version 1.90 or higher.

References

Regular Expression Denial of Service (ReDoS)

medium severity

Detailed paths

  • Introduced through: bower@1.0.1 > semver@2.0.11
  • Introduced through: bower@1.0.1 > update-notifier@0.1.10 > semver@2.3.2
  • Introduced through: nodemon@1.0.1 > update-notifier@0.1.10 > semver@2.3.2
  • Introduced through: hapi@1.0.1 > semver@1.1.4
  • Introduced through: gulp-imagemin@1.0.1 > imagemin@1.0.5 > imagemin-gifsicle@1.0.0 > gifsicle@1.0.3 > bin-wrapper@1.0.5 > bin-version-check@1.0.0 > semver@3.0.1
  • Introduced through: gulp-imagemin@1.0.1 > imagemin@1.0.5 > imagemin-jpegtran@1.0.0 > jpegtran-bin@1.0.2 > bin-wrapper@1.0.5 > bin-version-check@1.0.0 > semver@3.0.1
  • Introduced through: gulp-imagemin@1.0.1 > imagemin@1.0.5 > imagemin-optipng@1.0.0 > optipng-bin@1.0.1 > bin-wrapper@1.0.5 > bin-version-check@1.0.0 > semver@3.0.1
  • Introduced through: gulp-imagemin@1.0.1 > imagemin@1.0.5 > imagemin-pngquant@1.0.2 > pngquant-bin@1.0.1 > bin-wrapper@1.0.5 > bin-version-check@1.0.0 > semver@3.0.1

Overview

npm is a package manager for javascript.

Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS). The semver module uses regular expressions when parsing a version string. For a carefully crafted input, the time it takes to process these regular expressions is not linear to the length of the input. Since the semver module did not enforce a limit on the version string length, an attacker could provide a long string that would take up a large amount of resources, potentially taking a server down. This issue therefore enables a potential Denial of Service attack. This is a slightly differnt variant of a typical Regular Expression Denial of Service (ReDoS) vulnerability.

Details

Denial of Service (DoS) describes a family of attacks, all aimed at making a system inaccessible to its original and legitimate users. There are many types of DoS attacks, ranging from trying to clog the network pipes to the system by generating a large volume of traffic from many machines (a Distributed Denial of Service - DDoS - attack) to sending crafted requests that cause a system to crash or take a disproportional amount of time to process.

The Regular expression Denial of Service (ReDoS) is a type of Denial of Service attack. Regular expressions are incredibly powerful, but they aren't very intuitive and can ultimately end up making it easy for attackers to take your site down.

Let’s take the following regular expression as an example:

regex = /A(B|C+)+D/

This regular expression accomplishes the following:

  • A The string must start with the letter 'A'
  • (B|C+)+ The string must then follow the letter A with either the letter 'B' or some number of occurrences of the letter 'C' (the + matches one or more times). The + at the end of this section states that we can look for one or more matches of this section.
  • D Finally, we ensure this section of the string ends with a 'D'

The expression would match inputs such as ABBD, ABCCCCD, ABCBCCCD and ACCCCCD

It most cases, it doesn't take very long for a regex engine to find a match:

$ time node -e '/A(B|C+)+D/.test("ACCCCCCCCCCCCCCCCCCCCCCCCCCCCD")'
0.04s user 0.01s system 95% cpu 0.052 total

$ time node -e '/A(B|C+)+D/.test("ACCCCCCCCCCCCCCCCCCCCCCCCCCCCX")'
1.79s user 0.02s system 99% cpu 1.812 total

The entire process of testing it against a 30 characters long string takes around ~52ms. But when given an invalid string, it takes nearly two seconds to complete the test, over ten times as long as it took to test a valid string. The dramatic difference is due to the way regular expressions get evaluated.

Most Regex engines will work very similarly (with minor differences). The engine will match the first possible way to accept the current character and proceed to the next one. If it then fails to match the next one, it will backtrack and see if there was another way to digest the previous character. If it goes too far down the rabbit hole only to find out the string doesn’t match in the end, and if many characters have multiple valid regex paths, the number of backtracking steps can become very large, resulting in what is known as catastrophic backtracking.

Let's look at how our expression runs into this problem, using a shorter string: "ACCCX". While it seems fairly straightforward, there are still four different ways that the engine could match those three C's:

  1. CCC
  2. CC+C
  3. C+CC
  4. C+C+C.

The engine has to try each of those combinations to see if any of them potentially match against the expression. When you combine that with the other steps the engine must take, we can use RegEx 101 debugger to see the engine has to take a total of 38 steps before it can determine the string doesn't match.

From there, the number of steps the engine must use to validate a string just continues to grow.

String Number of C's Number of steps
ACCCX 3 38
ACCCCX 4 71
ACCCCCX 5 136
ACCCCCCCCCCCCCCX 14 65,553

By the time the string includes 14 C's, the engine has to take over 65,000 steps just to see if the string is valid. These extreme situations can cause them to work very slowly (exponentially related to input size, as shown above), allowing an attacker to exploit this and can cause the service to excessively consume CPU, resulting in a Denial of Service.

Remediation

Update to a version 4.3.2 or greater. From the issue description [2]: "Package version can no longer be more than 256 characters long. This prevents a situation in which parsing the version number can use exponentially more time and memory to parse, leading to a potential denial of service."

References

Fixed in 1.0.1

Symlink File Overwrite

high severity

Detailed paths

  • Introduced through: bower@1.0.0 > tar@0.1.20
  • Introduced through: gulp-imagemin@1.0.0 > imagemin@0.4.9 > imagemin-gifsicle@0.1.1 > gifsicle@0.1.7 > bin-build@0.1.1 > download@0.1.19 > decompress@0.2.5 > tar@0.1.20
  • Introduced through: gulp-imagemin@1.0.0 > imagemin@0.4.9 > imagemin-pngquant@0.1.3 > pngquant-bin@0.3.5 > bin-build@0.1.1 > download@0.1.19 > decompress@0.2.5 > tar@0.1.20
  • Introduced through: gulp-imagemin@1.0.0 > imagemin@0.4.9 > imagemin-jpegtran@0.1.0 > jpegtran-bin@0.2.8 > bin-build@0.1.1 > download@0.1.19 > decompress@0.2.5 > tar@0.1.20
  • Introduced through: gulp-imagemin@1.0.0 > imagemin@0.4.9 > imagemin-optipng@0.1.0 > optipng-bin@0.3.11 > bin-build@0.1.1 > download@0.1.19 > decompress@0.2.5 > tar@0.1.20
  • Introduced through: gulp-imagemin@1.0.0 > imagemin@0.4.9 > imagemin-gifsicle@0.1.1 > gifsicle@0.1.7 > bin-wrapper@0.3.4 > download@0.1.19 > decompress@0.2.5 > tar@0.1.20
  • Introduced through: gulp-imagemin@1.0.0 > imagemin@0.4.9 > imagemin-pngquant@0.1.3 > pngquant-bin@0.3.5 > bin-wrapper@0.3.4 > download@0.1.19 > decompress@0.2.5 > tar@0.1.20
  • Introduced through: gulp-imagemin@1.0.0 > imagemin@0.4.9 > imagemin-jpegtran@0.1.0 > jpegtran-bin@0.2.8 > bin-wrapper@0.3.4 > download@0.1.19 > decompress@0.2.5 > tar@0.1.20
  • Introduced through: gulp-imagemin@1.0.0 > imagemin@0.4.9 > imagemin-optipng@0.1.0 > optipng-bin@0.3.11 > bin-wrapper@0.3.4 > download@0.1.19 > decompress@0.2.5 > tar@0.1.20

Overview

The tar module prior to version 2.0.0 does not properly normalize symbolic links pointing to targets outside the extraction root. As a result, packages may hold symbolic links to parent and sibling directories and overwrite those files when the package is extracted.

Remediation

Upgrade to version 2.0.0 or greater. If a direct dependency update is not possible, use snyk wizard to patch this vulnerability.

References