njson@0.1.4

Vulnerabilities

18 via 100 paths

Dependencies

109

Source

npm

Find, fix and prevent vulnerabilities in your code.

Severity
  • 1
  • 8
  • 6
  • 3
Status
  • 18
  • 0
  • 0

critical severity

DLL Injection

  • Vulnerable module: kerberos
  • Introduced through: connect-mongo@0.4.1 and lg@0.5.0

Detailed paths

  • Introduced through: njson@0.1.4 connect-mongo@0.4.1 mongodb@1.3.23 kerberos@0.0.3
    Remediation: Upgrade to connect-mongo@0.5.2.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect-mongo@0.4.1 mongodb@1.3.23 kerberos@0.0.3

Overview

Affected versions of this package are vulnerable to DLL Injection. An attacker can execute arbitrary code by creating a file with the same name in a folder that precedes the intended file in the DLL path search.

Remediation

Upgrade kerberos to version 1.0.0 or higher.

References

high severity

Uninitialized Memory Exposure

  • Vulnerable module: base64-url
  • Introduced through: express-session@1.7.6, connect@2.24.0 and others

Detailed paths

  • Introduced through: njson@0.1.4 express-session@1.7.6 uid-safe@1.0.1 base64-url@1.3.3
    Remediation: Upgrade to express-session@1.14.0.
  • Introduced through: njson@0.1.4 connect@2.24.0 csurf@1.3.0 csrf-tokens@2.0.0 base64-url@1.3.3
  • Introduced through: njson@0.1.4 connect@2.24.0 express-session@1.7.6 uid-safe@1.0.1 base64-url@1.3.3
    Remediation: Upgrade to connect@3.0.0.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 express-session@1.7.6 uid-safe@1.0.1 base64-url@1.3.3
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 csurf@1.3.0 csrf-tokens@2.0.0 base64-url@1.3.3
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 express-session@1.7.6 uid-safe@1.0.1 base64-url@1.3.3
  • Introduced through: njson@0.1.4 connect@2.24.0 csurf@1.3.0 csrf-tokens@2.0.0 uid-safe@1.1.0 base64-url@1.2.1
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 csurf@1.3.0 csrf-tokens@2.0.0 uid-safe@1.1.0 base64-url@1.2.1

Overview

base64-url Base64 encode, decode, escape and unescape for URL applications.

Affected versions of this package are vulnerable to Uninitialized Memory Exposure. An attacker may extract sensitive data from uninitialized memory or may cause a DoS by passing in a large number, in setups where typed user input can be passed (e.g. from JSON).

Details

The Buffer class on Node.js is a mutable array of binary data, and can be initialized with a string, array or number.

const buf1 = new Buffer([1,2,3]);
// creates a buffer containing [01, 02, 03]
const buf2 = new Buffer('test');
// creates a buffer containing ASCII bytes [74, 65, 73, 74]
const buf3 = new Buffer(10);
// creates a buffer of length 10

The first two variants simply create a binary representation of the value it received. The last one, however, pre-allocates a buffer of the specified size, making it a useful buffer, especially when reading data from a stream. When using the number constructor of Buffer, it will allocate the memory, but will not fill it with zeros. Instead, the allocated buffer will hold whatever was in memory at the time. If the buffer is not zeroed by using buf.fill(0), it may leak sensitive information like keys, source code, and system info.

Remediation

Upgrade base64-url to version 2.0.0 or higher. Note This is vulnerable only for Node <=4

References

high severity

Regular Expression Denial of Service (ReDoS)

  • Vulnerable module: fresh
  • Introduced through: connect@2.24.0 and lg@0.5.0

Detailed paths

  • Introduced through: njson@0.1.4 connect@2.24.0 fresh@0.2.2
    Remediation: Upgrade to connect@3.0.0.
  • Introduced through: njson@0.1.4 connect@2.24.0 serve-favicon@2.0.1 fresh@0.2.2
    Remediation: Upgrade to connect@3.0.0.
  • Introduced through: njson@0.1.4 connect@2.24.0 serve-static@1.4.4 send@0.7.4 fresh@0.2.2
    Remediation: Upgrade to connect@3.0.0.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 fresh@0.2.2
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 serve-favicon@2.0.1 fresh@0.2.2
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 serve-static@1.4.4 send@0.7.4 fresh@0.2.2

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.

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 fresh to version 0.5.2 or higher.

References

high severity

Directory Traversal

  • Vulnerable module: lactate
  • Introduced through: lactate@0.13.12 and lg@0.5.0

Detailed paths

  • Introduced through: njson@0.1.4 lactate@0.13.12
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 lactate@0.13.12

Overview

lactate is a static file handler.

Affected versions of this package are vulnerable to Directory Traversal.

An attacker may use a specially crafted GET request and traverse the directory structure of a host using the lactate web server package, allowing them read access to arbitrary files outside of the specified web root.

Mitigating factors: Only files that the user running lactate has permission to read will be accessible via this vulnerability.

Proof of concept by Yasin Soliman:

  • Globally install the lactate package and cd to a directory you wish to serve assets from.
  • Run lactate -p 8081 to start serving files from this location.
  • Running the following cURL request:
curl "http://127.0.0.1:8081/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd"

Details

A Directory Traversal attack (also known as path traversal) aims to access files and directories that are stored outside the intended folder. By manipulating files with "dot-dot-slash (../)" sequences and its variations, or by using absolute file paths, it may be possible to access arbitrary files and directories stored on file system, including application source code, configuration, and other critical system files.

Directory Traversal vulnerabilities can be generally divided into two types:

  • Information Disclosure: Allows the attacker to gain information about the folder structure or read the contents of sensitive files on the system.

st is a module for serving static files on web pages, and contains a vulnerability of this type. In our example, we will serve files from the public route.

If an attacker requests the following URL from our server, it will in turn leak the sensitive private key of the root user.

curl http://localhost:8080/public/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/root/.ssh/id_rsa

Note %2e is the URL encoded version of . (dot).

  • Writing arbitrary files: Allows the attacker to create or replace existing files. This type of vulnerability is also known as Zip-Slip.

One way to achieve this is by using a malicious zip archive that holds path traversal filenames. When each filename in the zip archive gets concatenated to the target extraction folder, without validation, the final path ends up outside of the target folder. If an executable or a configuration file is overwritten with a file containing malicious code, the problem can turn into an arbitrary code execution issue quite easily.

The following is an example of a zip archive with one benign file and one malicious file. Extracting the malicious file will result in traversing out of the target folder, ending up in /root/.ssh/ overwriting the authorized_keys file:

2018-04-15 22:04:29 .....           19           19  good.txt
2018-04-15 22:04:42 .....           20           20  ../../../../../../root/.ssh/authorized_keys

Remediation

There is no fix version for lactate.

References

high severity

Regular Expression Denial of Service (ReDoS)

  • Vulnerable module: method-override
  • Introduced through: connect@2.24.0 and lg@0.5.0

Detailed paths

  • Introduced through: njson@0.1.4 connect@2.24.0 method-override@2.1.3
    Remediation: Upgrade to connect@2.27.0.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 method-override@2.1.3

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.

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 method-override to version 2.3.10 or higher.

References

high severity

Denial of Service (DoS)

  • Vulnerable module: mongodb
  • Introduced through: connect-mongo@0.4.1 and lg@0.5.0

Detailed paths

  • Introduced through: njson@0.1.4 connect-mongo@0.4.1 mongodb@1.3.23
    Remediation: Upgrade to connect-mongo@3.0.0.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect-mongo@0.4.1 mongodb@1.3.23

Overview

mongodb is an official MongoDB driver for Node.js.

Affected versions of this package are vulnerable to Denial of Service (DoS). The package fails to properly catch an exception when a collection name is invalid and the DB does not exist, crashing the application.

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 mongodb to version 3.1.13 or higher.

References

high severity

Regular Expression Denial of Service (ReDoS)

  • Vulnerable module: negotiator
  • Introduced through: compression@1.0.11, connect@2.24.0 and others

Detailed paths

  • Introduced through: njson@0.1.4 compression@1.0.11 accepts@1.0.7 negotiator@0.4.7
    Remediation: Upgrade to compression@1.6.0.
  • Introduced through: njson@0.1.4 connect@2.24.0 compression@1.0.11 accepts@1.0.7 negotiator@0.4.7
    Remediation: Upgrade to connect@3.0.0.
  • Introduced through: njson@0.1.4 connect@2.24.0 errorhandler@1.1.1 accepts@1.0.7 negotiator@0.4.7
    Remediation: Upgrade to connect@2.30.0.
  • Introduced through: njson@0.1.4 connect@2.24.0 serve-index@1.1.6 accepts@1.0.7 negotiator@0.4.7
    Remediation: Upgrade to connect@3.0.0.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 compression@1.0.11 accepts@1.0.7 negotiator@0.4.7
    Remediation: Open PR to patch negotiator@0.4.7.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 compression@1.0.11 accepts@1.0.7 negotiator@0.4.7
    Remediation: Open PR to patch negotiator@0.4.7.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 errorhandler@1.1.1 accepts@1.0.7 negotiator@0.4.7
    Remediation: Open PR to patch negotiator@0.4.7.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 serve-index@1.1.6 accepts@1.0.7 negotiator@0.4.7
    Remediation: Open PR to patch negotiator@0.4.7.

Overview

negotiator is an HTTP content negotiator for Node.js.

Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS) when parsing Accept-Language http header.

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 negotiator to version 0.6.1 or higher.

References

high severity

Denial of Service (DoS)

  • Vulnerable module: qs
  • Introduced through: connect@2.24.0 and lg@0.5.0

Detailed paths

  • Introduced through: njson@0.1.4 connect@2.24.0 qs@0.6.6
    Remediation: Upgrade to connect@2.25.0.
  • Introduced through: njson@0.1.4 connect@2.24.0 body-parser@1.5.2 qs@0.6.6
    Remediation: Upgrade to connect@2.25.0.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 qs@0.6.6
    Remediation: Open PR to patch qs@0.6.6.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 body-parser@1.5.2 qs@0.6.6
    Remediation: Open PR to patch qs@0.6.6.

Overview

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

Affected versions of this package are vulnerable to Denial of Service (DoS). 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 higher.

Details

Denial of Service (DoS) describes a family of attacks, all aimed at making a system inaccessible to its intended and legitimate users.

Unlike other vulnerabilities, DoS attacks usually do not aim at breaching security. Rather, they are focused on making websites and services unavailable to genuine users resulting in downtime.

One popular Denial of Service vulnerability is DDoS (a Distributed Denial of Service), an attack that attempts to clog network pipes to the system by generating a large volume of traffic from many machines.

When it comes to open source libraries, DoS vulnerabilities allow attackers to trigger such a crash or crippling of the service by using a flaw either in the application code or from the use of open source libraries.

Two common types of DoS vulnerabilities:

  • High CPU/Memory Consumption- An attacker sending crafted requests that could cause the system to take a disproportionate amount of time to process. For example, commons-fileupload:commons-fileupload.

  • Crash - An attacker sending crafted requests that could cause the system to crash. For Example, npm ws package

References

high severity

Prototype Override Protection Bypass

  • Vulnerable module: qs
  • Introduced through: body-parser@1.6.7, lg@0.5.0 and others

Detailed paths

  • Introduced through: njson@0.1.4 body-parser@1.6.7 qs@2.2.2
    Remediation: Upgrade to body-parser@1.17.1.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 body-parser@1.6.7 qs@2.2.2
  • Introduced through: njson@0.1.4 connect@2.24.0 qs@0.6.6
    Remediation: Upgrade to connect@3.0.0.
  • Introduced through: njson@0.1.4 connect@2.24.0 body-parser@1.5.2 qs@0.6.6
    Remediation: Upgrade to connect@3.0.0.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 qs@0.6.6
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 body-parser@1.5.2 qs@0.6.6
  • Introduced through: njson@0.1.4 restler@3.4.0 qs@1.2.0
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 restler@3.4.0 qs@1.2.0

Overview

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

Affected versions of this package are vulnerable to Prototype Override Protection Bypass. 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.0.4, 6.1.2, 6.2.3, 6.3.2 or higher.

    References

  • GitHub Commit
  • GitHub Issue

medium severity

Arbitrary Code Injection

  • Vulnerable module: morgan
  • Introduced through: connect@2.24.0 and lg@0.5.0

Detailed paths

  • Introduced through: njson@0.1.4 connect@2.24.0 morgan@1.2.3
    Remediation: Upgrade to connect@3.0.0.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 morgan@1.2.3

Overview

morgan is a HTTP request logger middleware for node.js.

Affected versions of this package are vulnerable to Arbitrary Code Injection. An attacker could use the format parameter to inject arbitrary commands.

Remediation

Upgrade morgan to version 1.9.1 or higher.

References

medium severity

Regular Expression Denial of Service (ReDoS)

  • Vulnerable module: ms
  • Introduced through: compression@1.0.11, express-session@1.7.6 and others

Detailed paths

  • Introduced through: njson@0.1.4 compression@1.0.11 debug@1.0.4 ms@0.6.2
    Remediation: Upgrade to compression@1.4.4.
  • Introduced through: njson@0.1.4 express-session@1.7.6 debug@1.0.4 ms@0.6.2
    Remediation: Upgrade to express-session@1.11.2.
  • Introduced through: njson@0.1.4 connect@2.24.0 debug@1.0.4 ms@0.6.2
    Remediation: Upgrade to connect@2.29.2.
  • Introduced through: njson@0.1.4 connect@2.24.0 connect-timeout@1.2.2 ms@0.6.2
    Remediation: Upgrade to connect@2.29.0.
  • Introduced through: njson@0.1.4 connect@2.24.0 compression@1.0.11 debug@1.0.4 ms@0.6.2
    Remediation: Upgrade to connect@2.29.0.
  • Introduced through: njson@0.1.4 connect@2.24.0 connect-timeout@1.2.2 debug@1.0.4 ms@0.6.2
    Remediation: Upgrade to connect@2.29.0.
  • Introduced through: njson@0.1.4 connect@2.24.0 express-session@1.7.6 debug@1.0.4 ms@0.6.2
    Remediation: Upgrade to connect@2.30.0.
  • Introduced through: njson@0.1.4 connect@2.24.0 finalhandler@0.1.0 debug@1.0.4 ms@0.6.2
    Remediation: Upgrade to connect@2.29.2.
  • Introduced through: njson@0.1.4 connect@2.24.0 method-override@2.1.3 debug@1.0.4 ms@0.6.2
    Remediation: Upgrade to connect@2.27.0.
  • Introduced through: njson@0.1.4 connect@2.24.0 serve-static@1.4.4 send@0.7.4 ms@0.6.2
    Remediation: Upgrade to connect@2.29.0.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 compression@1.0.11 debug@1.0.4 ms@0.6.2
    Remediation: Open PR to patch ms@0.6.2.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 express-session@1.7.6 debug@1.0.4 ms@0.6.2
    Remediation: Open PR to patch ms@0.6.2.
  • Introduced through: njson@0.1.4 connect@2.24.0 serve-static@1.4.4 send@0.7.4 debug@1.0.4 ms@0.6.2
    Remediation: Upgrade to connect@2.29.0.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 debug@1.0.4 ms@0.6.2
    Remediation: Open PR to patch ms@0.6.2.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 connect-timeout@1.2.2 ms@0.6.2
    Remediation: Open PR to patch ms@0.6.2.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 compression@1.0.11 debug@1.0.4 ms@0.6.2
    Remediation: Open PR to patch ms@0.6.2.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 connect-timeout@1.2.2 debug@1.0.4 ms@0.6.2
    Remediation: Open PR to patch ms@0.6.2.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 express-session@1.7.6 debug@1.0.4 ms@0.6.2
    Remediation: Open PR to patch ms@0.6.2.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 finalhandler@0.1.0 debug@1.0.4 ms@0.6.2
    Remediation: Open PR to patch ms@0.6.2.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 method-override@2.1.3 debug@1.0.4 ms@0.6.2
    Remediation: Open PR to patch ms@0.6.2.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 serve-static@1.4.4 send@0.7.4 ms@0.6.2
    Remediation: Open PR to patch ms@0.6.2.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 serve-static@1.4.4 send@0.7.4 debug@1.0.4 ms@0.6.2
    Remediation: Open PR to patch ms@0.6.2.

Overview

ms is a tiny milisecond conversion utility.

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

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 ms to version 0.7.1 or higher.

References

medium severity

Denial of Service (DoS)

  • Vulnerable module: qs
  • Introduced through: connect@2.24.0 and lg@0.5.0

Detailed paths

  • Introduced through: njson@0.1.4 connect@2.24.0 qs@0.6.6
    Remediation: Upgrade to connect@2.25.0.
  • Introduced through: njson@0.1.4 connect@2.24.0 body-parser@1.5.2 qs@0.6.6
    Remediation: Upgrade to connect@2.25.0.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 qs@0.6.6
    Remediation: Open PR to patch qs@0.6.6.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 body-parser@1.5.2 qs@0.6.6
    Remediation: Open PR to patch qs@0.6.6.

Overview

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

Affected versions of this package are vulnerable to Denial of Service (DoS). 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.

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 qs to version 1.0.0 or higher.

References

medium severity

Directory Traversal

  • Vulnerable module: send
  • Introduced through: connect@2.24.0 and lg@0.5.0

Detailed paths

  • Introduced through: njson@0.1.4 connect@2.24.0 serve-static@1.4.4 send@0.7.4
    Remediation: Upgrade to connect@2.25.0.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 serve-static@1.4.4 send@0.7.4
    Remediation: Open PR to patch send@0.7.4.

Overview

send is a library for streaming files from the file system.

Affected versions of this package are vulnerable to Directory-Traversal attacks due to insecure comparison. When relying on the root option to restrict file access a malicious user may escape out of the restricted directory and access files in a similarly named directory. For example, a path like /my-secret is consedered fine for the root /my.

Details

A Directory Traversal attack (also known as path traversal) aims to access files and directories that are stored outside the intended folder. By manipulating files with "dot-dot-slash (../)" sequences and its variations, or by using absolute file paths, it may be possible to access arbitrary files and directories stored on file system, including application source code, configuration, and other critical system files.

Directory Traversal vulnerabilities can be generally divided into two types:

  • Information Disclosure: Allows the attacker to gain information about the folder structure or read the contents of sensitive files on the system.

st is a module for serving static files on web pages, and contains a vulnerability of this type. In our example, we will serve files from the public route.

If an attacker requests the following URL from our server, it will in turn leak the sensitive private key of the root user.

curl http://localhost:8080/public/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/root/.ssh/id_rsa

Note %2e is the URL encoded version of . (dot).

  • Writing arbitrary files: Allows the attacker to create or replace existing files. This type of vulnerability is also known as Zip-Slip.

One way to achieve this is by using a malicious zip archive that holds path traversal filenames. When each filename in the zip archive gets concatenated to the target extraction folder, without validation, the final path ends up outside of the target folder. If an executable or a configuration file is overwritten with a file containing malicious code, the problem can turn into an arbitrary code execution issue quite easily.

The following is an example of a zip archive with one benign file and one malicious file. Extracting the malicious file will result in traversing out of the target folder, ending up in /root/.ssh/ overwriting the authorized_keys file:

2018-04-15 22:04:29 .....           19           19  good.txt
2018-04-15 22:04:42 .....           20           20  ../../../../../../root/.ssh/authorized_keys

Remediation

Upgrade to a version greater than or equal to 0.8.4.

References

medium severity

Root Path Disclosure

  • Vulnerable module: send
  • Introduced through: connect@2.24.0 and lg@0.5.0

Detailed paths

  • Introduced through: njson@0.1.4 connect@2.24.0 serve-static@1.4.4 send@0.7.4
    Remediation: Upgrade to connect@2.28.0.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 serve-static@1.4.4 send@0.7.4

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.

Affected versions of this package are vulnerable to a Root Path Disclosure.

Remediation

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

References

medium severity

Cross-site Scripting (XSS)

  • Vulnerable module: serve-index
  • Introduced through: connect@2.24.0 and lg@0.5.0

Detailed paths

  • Introduced through: njson@0.1.4 connect@2.24.0 serve-index@1.1.6
    Remediation: Upgrade to connect@2.28.0.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 serve-index@1.1.6

Overview

serve-index Serves pages that contain directory listings for a given path.

Affected versions of this package are vulnerable to Cross-site Scripting (XSS) attacks. When using serve-index middleware, file and directory names are not escaped in HTML output. If a remote attcker can influence these names, it may trigger a persistent XSS attack.

Details

A cross-site scripting attack occurs when the attacker tricks a legitimate web-based application or site to accept a request as originating from a trusted source.

This is done by escaping the context of the web application; the web application then delivers that data to its users along with other trusted dynamic content, without validating it. The browser unknowingly executes malicious script on the client side (through client-side languages; usually JavaScript or HTML) in order to perform actions that are otherwise typically blocked by the browser’s Same Origin Policy.

ֿInjecting malicious code is the most prevalent manner by which XSS is exploited; for this reason, escaping characters in order to prevent this manipulation is the top method for securing code against this vulnerability.

Escaping means that the application is coded to mark key characters, and particularly key characters included in user input, to prevent those characters from being interpreted in a dangerous context. For example, in HTML, < can be coded as &lt; and > can be coded as &gt; in order to be interpreted and displayed as themselves in text, while within the code itself, they are used for HTML tags. If malicious content is injected into an application that escapes special characters and that malicious content uses < and > as HTML tags, those characters are nonetheless not interpreted as HTML tags by the browser if they’ve been correctly escaped in the application code and in this way the attempted attack is diverted.

The most prominent use of XSS is to steal cookies (source: OWASP HttpOnly) and hijack user sessions, but XSS exploits have been used to expose sensitive information, enable access to privileged services and functionality and deliver malware.

Types of attacks

There are a few methods by which XSS can be manipulated:

Type Origin Description
Stored Server The malicious code is inserted in the application (usually as a link) by the attacker. The code is activated every time a user clicks the link.
Reflected Server The attacker delivers a malicious link externally from the vulnerable web site application to a user. When clicked, malicious code is sent to the vulnerable web site, which reflects the attack back to the user’s browser.
DOM-based Client The attacker forces the user’s browser to render a malicious page. The data in the page itself delivers the cross-site scripting data.
Mutated The attacker injects code that appears safe, but is then rewritten and modified by the browser, while parsing the markup. An example is rebalancing unclosed quotation marks or even adding quotation marks to unquoted parameters.

Affected environments

The following environments are susceptible to an XSS attack:

  • Web servers
  • Application servers
  • Web application environments

How to prevent

This section describes the top best practices designed to specifically protect your code:

  • Sanitize data input in an HTTP request before reflecting it back, ensuring all data is validated, filtered or escaped before echoing anything back to the user, such as the values of query parameters during searches.
  • Convert special characters such as ?, &, /, <, > and spaces to their respective HTML or URL encoded equivalents.
  • Give users the option to disable client-side scripts.
  • Redirect invalid requests.
  • Detect simultaneous logins, including those from two separate IP addresses, and invalidate those sessions.
  • Use and enforce a Content Security Policy (source: Wikipedia) to disable any features that might be manipulated for an XSS attack.
  • Read the documentation for any of the libraries referenced in your code to understand which elements allow for embedded HTML.

Remediation

Upgrade to version 1.6.3 or greater

References

low severity

Regular Expression Denial of Service (ReDoS)

  • Vulnerable module: debug
  • Introduced through: compression@1.0.11, express-session@1.7.6 and others

Detailed paths

  • Introduced through: njson@0.1.4 compression@1.0.11 debug@1.0.4
    Remediation: Upgrade to compression@1.7.1.
  • Introduced through: njson@0.1.4 express-session@1.7.6 debug@1.0.4
    Remediation: Upgrade to express-session@1.15.6.
  • Introduced through: njson@0.1.4 connect@2.24.0 debug@1.0.4
    Remediation: Upgrade to connect@3.6.5.
  • Introduced through: njson@0.1.4 connect@2.24.0 compression@1.0.11 debug@1.0.4
    Remediation: Upgrade to connect@3.0.0.
  • Introduced through: njson@0.1.4 connect@2.24.0 connect-timeout@1.2.2 debug@1.0.4
    Remediation: Upgrade to connect@3.0.0.
  • Introduced through: njson@0.1.4 connect@2.24.0 express-session@1.7.6 debug@1.0.4
    Remediation: Upgrade to connect@3.0.0.
  • Introduced through: njson@0.1.4 connect@2.24.0 finalhandler@0.1.0 debug@1.0.4
    Remediation: Upgrade to connect@3.0.0.
  • Introduced through: njson@0.1.4 connect@2.24.0 method-override@2.1.3 debug@1.0.4
    Remediation: Upgrade to connect@2.27.0.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 compression@1.0.11 debug@1.0.4
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 express-session@1.7.6 debug@1.0.4
  • Introduced through: njson@0.1.4 connect@2.24.0 serve-static@1.4.4 send@0.7.4 debug@1.0.4
    Remediation: Upgrade to connect@3.0.0.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 debug@1.0.4
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 compression@1.0.11 debug@1.0.4
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 connect-timeout@1.2.2 debug@1.0.4
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 express-session@1.7.6 debug@1.0.4
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 finalhandler@0.1.0 debug@1.0.4
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 method-override@2.1.3 debug@1.0.4
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 serve-static@1.4.4 send@0.7.4 debug@1.0.4

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.

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 debug to version 2.6.9, 3.1.0 or higher.

References

low severity

Regular Expression Denial of Service (ReDoS)

  • Vulnerable module: mime
  • Introduced through: connect@2.24.0, lg@0.5.0 and others

Detailed paths

  • Introduced through: njson@0.1.4 connect@2.24.0 serve-static@1.4.4 send@0.7.4 mime@1.2.11
    Remediation: Upgrade to connect@3.0.0.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 serve-static@1.4.4 send@0.7.4 mime@1.2.11
    Remediation: Open PR to patch mime@1.2.11.
  • Introduced through: njson@0.1.4 lactate@0.13.12 mime@1.2.9
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 lactate@0.13.12 mime@1.2.9

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.

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 mime to version 1.4.1, 2.0.3 or higher.

References

low severity

Open Redirect

  • Vulnerable module: serve-static
  • Introduced through: connect@2.24.0 and lg@0.5.0

Detailed paths

  • Introduced through: njson@0.1.4 connect@2.24.0 serve-static@1.4.4
    Remediation: Upgrade to connect@2.26.0.
  • Introduced through: njson@0.1.4 lg@0.5.0 njson@0.3.0 connect@2.24.0 serve-static@1.4.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