Find, fix and prevent vulnerabilities in your code.
high severity
new
- Vulnerable module: qs
- Introduced through: http-server@0.6.1 and grunt-http-server@1.0.0
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › http-server@0.6.1 › union@0.3.8 › qs@0.5.6Remediation: Upgrade to http-server@0.11.2.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt-http-server@1.0.0 › http-server@0.6.1 › union@0.3.8 › qs@0.5.6
Overview
qs is a querystring parser that supports nesting and arrays, with a depth limit.
Affected versions of this package are vulnerable to Allocation of Resources Without Limits or Throttling via improper enforcement of the arrayLimit option in bracket notation parsing. An attacker can exhaust server memory and cause application unavailability by submitting a large number of bracket notation parameters - like a[]=1&a[]=2 - in a single HTTP request.
PoC
const qs = require('qs');
const attack = 'a[]=' + Array(10000).fill('x').join('&a[]=');
const result = qs.parse(attack, { arrayLimit: 100 });
console.log(result.a.length); // Output: 10000 (should be max 100)
Remediation
Upgrade qs to version 6.14.1 or higher.
References
high severity
- Vulnerable module: js-yaml
- Introduced through: grunt@0.4.5
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › js-yaml@2.0.5Remediation: Upgrade to grunt@1.0.4.
Overview
js-yaml is a human-friendly data serialization language.
Affected versions of this package are vulnerable to Arbitrary Code Execution. When an object with an executable toString() property used as a map key, it will execute that function. This happens only for load(), which should not be used with untrusted data anyway. safeLoad() is not affected because it can't parse functions.
Remediation
Upgrade js-yaml to version 3.13.1 or higher.
References
high severity
- Vulnerable module: ecstatic
- Introduced through: http-server@0.6.1 and grunt-http-server@1.0.0
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › http-server@0.6.1 › ecstatic@0.4.13Remediation: Upgrade to http-server@0.13.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt-http-server@1.0.0 › http-server@0.6.1 › ecstatic@0.4.13
Overview
ecstatic is a simple static file server middleware. Use it with a raw http server, express/connect or on the CLI.
Affected versions of this package are vulnerable to Denial of Service (DoS). It is possible to crash a server using the package due to the way URL params parsing is handled during redirect.
PoC
curl --path-as-is $(echo -e -n "http://127.0.0.1:8080/existing-dir-name?\x0cfoo")
In the PoC the library is trying to redirect /existing-dir-name?\x0cfoo to /existing-dir-name/?\x0cfoo which cause TypeError: The header content contains invalid characters error because of \x0c symbol.
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:
AThe 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.DFinally, 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:
- CCC
- CC+C
- C+CC
- 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 ecstatic to version 4.1.4 or higher.
References
high severity
- Vulnerable module: ecstatic
- Introduced through: http-server@0.6.1 and grunt-http-server@1.0.0
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › http-server@0.6.1 › ecstatic@0.4.13Remediation: Upgrade to http-server@0.9.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt-http-server@1.0.0 › http-server@0.6.1 › ecstatic@0.4.13Remediation: Upgrade to grunt-http-server@1.15.0.
Overview
ecstatic is a simple static file server middleware. Use it with a raw http server, express/connect or on the CLI.
Affected versions of this package are vulnerable to Denial of Service (DoS). The vulnerability is caused by the combination of two bugs. First, the underlying V8 engine throws an exception when processing the specially crafted date, instead of stating the date is invalid as it should. Second, the ecstatic server does not handle the exception, triggering the crash.
Upgrading Ecstatic will address the second issue and thus fix the vulnerability.
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
wspackage
Remediation
Upgrade ecstatic to version 1.4.0 or higher.
References
high severity
- Vulnerable module: getobject
- Introduced through: grunt@0.4.5
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › getobject@0.1.0Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-util@0.2.0 › getobject@0.1.0Remediation: Upgrade to grunt@1.3.0.
Overview
Affected versions of this package are vulnerable to Prototype Pollution. It allows an attacker to cause a denial of service and may lead to remote code execution.
Details
Prototype Pollution is a vulnerability affecting JavaScript. Prototype Pollution refers to the ability to inject properties into existing JavaScript language construct prototypes, such as objects. JavaScript allows all Object attributes to be altered, including their magical attributes such as __proto__, constructor and prototype. An attacker manipulates these attributes to overwrite, or pollute, a JavaScript application object prototype of the base object by injecting other values. Properties on the Object.prototype are then inherited by all the JavaScript objects through the prototype chain. When that happens, this leads to either denial of service by triggering JavaScript exceptions, or it tampers with the application source code to force the code path that the attacker injects, thereby leading to remote code execution.
There are two main ways in which the pollution of prototypes occurs:
Unsafe
Objectrecursive mergeProperty definition by path
Unsafe Object recursive merge
The logic of a vulnerable recursive merge function follows the following high-level model:
merge (target, source)
foreach property of source
if property exists and is an object on both the target and the source
merge(target[property], source[property])
else
target[property] = source[property]
When the source object contains a property named __proto__ defined with Object.defineProperty() , the condition that checks if the property exists and is an object on both the target and the source passes and the merge recurses with the target, being the prototype of Object and the source of Object as defined by the attacker. Properties are then copied on the Object prototype.
Clone operations are a special sub-class of unsafe recursive merges, which occur when a recursive merge is conducted on an empty object: merge({},source).
lodash and Hoek are examples of libraries susceptible to recursive merge attacks.
Property definition by path
There are a few JavaScript libraries that use an API to define property values on an object based on a given path. The function that is generally affected contains this signature: theFunction(object, path, value)
If the attacker can control the value of “path”, they can set this value to __proto__.myValue. myValue is then assigned to the prototype of the class of the object.
Types of attacks
There are a few methods by which Prototype Pollution can be manipulated:
| Type | Origin | Short description |
|---|---|---|
| Denial of service (DoS) | Client | This is the most likely attack. DoS occurs when Object holds generic functions that are implicitly called for various operations (for example, toString and valueOf). The attacker pollutes Object.prototype.someattr and alters its state to an unexpected value such as Int or Object. In this case, the code fails and is likely to cause a denial of service. For example: if an attacker pollutes Object.prototype.toString by defining it as an integer, if the codebase at any point was reliant on someobject.toString() it would fail. |
| Remote Code Execution | Client | Remote code execution is generally only possible in cases where the codebase evaluates a specific attribute of an object, and then executes that evaluation. For example: eval(someobject.someattr). In this case, if the attacker pollutes Object.prototype.someattr they are likely to be able to leverage this in order to execute code. |
| Property Injection | Client | The attacker pollutes properties that the codebase relies on for their informative value, including security properties such as cookies or tokens. For example: if a codebase checks privileges for someuser.isAdmin, then when the attacker pollutes Object.prototype.isAdmin and sets it to equal true, they can then achieve admin privileges. |
Affected environments
The following environments are susceptible to a Prototype Pollution attack:
Application server
Web server
Web browser
How to prevent
Freeze the prototype— use
Object.freeze (Object.prototype).Require schema validation of JSON input.
Avoid using unsafe recursive merge functions.
Consider using objects without prototypes (for example,
Object.create(null)), breaking the prototype chain and preventing pollution.As a best practice use
Mapinstead ofObject.
For more information on this vulnerability type:
Arteau, Oliver. “JavaScript prototype pollution attack in NodeJS application.” GitHub, 26 May 2018
Remediation
Upgrade getobject to version 1.0.0 or higher.
References
high severity
- Vulnerable module: lodash
- Introduced through: grunt@0.4.5 and grunt-cli@0.1.13
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › findup-sync@0.1.3 › lodash@2.4.2
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt-cli@0.1.13 › findup-sync@0.1.3 › lodash@2.4.2Remediation: Upgrade to grunt-cli@1.3.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-log@0.1.3 › lodash@2.4.2Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-log@0.1.3 › grunt-legacy-log-utils@0.1.1 › lodash@2.4.2Remediation: Upgrade to grunt@1.0.3.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › lodash@0.9.2Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-util@0.2.0 › lodash@0.9.2Remediation: Upgrade to grunt@1.0.3.
Overview
lodash is a modern JavaScript utility library delivering modularity, performance, & extras.
Affected versions of this package are vulnerable to Prototype Pollution through the zipObjectDeep function due to improper user input sanitization in the baseZipObject function.
PoC
lodash.zipobjectdeep:
const zipObjectDeep = require("lodash.zipobjectdeep");
let emptyObject = {};
console.log(`[+] Before prototype pollution : ${emptyObject.polluted}`);
//[+] Before prototype pollution : undefined
zipObjectDeep(["constructor.prototype.polluted"], [true]);
//we inject our malicious attributes in the vulnerable function
console.log(`[+] After prototype pollution : ${emptyObject.polluted}`);
//[+] After prototype pollution : true
lodash:
const test = require("lodash");
let emptyObject = {};
console.log(`[+] Before prototype pollution : ${emptyObject.polluted}`);
//[+] Before prototype pollution : undefined
test.zipObjectDeep(["constructor.prototype.polluted"], [true]);
//we inject our malicious attributes in the vulnerable function
console.log(`[+] After prototype pollution : ${emptyObject.polluted}`);
//[+] After prototype pollution : true
Details
Prototype Pollution is a vulnerability affecting JavaScript. Prototype Pollution refers to the ability to inject properties into existing JavaScript language construct prototypes, such as objects. JavaScript allows all Object attributes to be altered, including their magical attributes such as __proto__, constructor and prototype. An attacker manipulates these attributes to overwrite, or pollute, a JavaScript application object prototype of the base object by injecting other values. Properties on the Object.prototype are then inherited by all the JavaScript objects through the prototype chain. When that happens, this leads to either denial of service by triggering JavaScript exceptions, or it tampers with the application source code to force the code path that the attacker injects, thereby leading to remote code execution.
There are two main ways in which the pollution of prototypes occurs:
Unsafe
Objectrecursive mergeProperty definition by path
Unsafe Object recursive merge
The logic of a vulnerable recursive merge function follows the following high-level model:
merge (target, source)
foreach property of source
if property exists and is an object on both the target and the source
merge(target[property], source[property])
else
target[property] = source[property]
When the source object contains a property named __proto__ defined with Object.defineProperty() , the condition that checks if the property exists and is an object on both the target and the source passes and the merge recurses with the target, being the prototype of Object and the source of Object as defined by the attacker. Properties are then copied on the Object prototype.
Clone operations are a special sub-class of unsafe recursive merges, which occur when a recursive merge is conducted on an empty object: merge({},source).
lodash and Hoek are examples of libraries susceptible to recursive merge attacks.
Property definition by path
There are a few JavaScript libraries that use an API to define property values on an object based on a given path. The function that is generally affected contains this signature: theFunction(object, path, value)
If the attacker can control the value of “path”, they can set this value to __proto__.myValue. myValue is then assigned to the prototype of the class of the object.
Types of attacks
There are a few methods by which Prototype Pollution can be manipulated:
| Type | Origin | Short description |
|---|---|---|
| Denial of service (DoS) | Client | This is the most likely attack. DoS occurs when Object holds generic functions that are implicitly called for various operations (for example, toString and valueOf). The attacker pollutes Object.prototype.someattr and alters its state to an unexpected value such as Int or Object. In this case, the code fails and is likely to cause a denial of service. For example: if an attacker pollutes Object.prototype.toString by defining it as an integer, if the codebase at any point was reliant on someobject.toString() it would fail. |
| Remote Code Execution | Client | Remote code execution is generally only possible in cases where the codebase evaluates a specific attribute of an object, and then executes that evaluation. For example: eval(someobject.someattr). In this case, if the attacker pollutes Object.prototype.someattr they are likely to be able to leverage this in order to execute code. |
| Property Injection | Client | The attacker pollutes properties that the codebase relies on for their informative value, including security properties such as cookies or tokens. For example: if a codebase checks privileges for someuser.isAdmin, then when the attacker pollutes Object.prototype.isAdmin and sets it to equal true, they can then achieve admin privileges. |
Affected environments
The following environments are susceptible to a Prototype Pollution attack:
Application server
Web server
Web browser
How to prevent
Freeze the prototype— use
Object.freeze (Object.prototype).Require schema validation of JSON input.
Avoid using unsafe recursive merge functions.
Consider using objects without prototypes (for example,
Object.create(null)), breaking the prototype chain and preventing pollution.As a best practice use
Mapinstead ofObject.
For more information on this vulnerability type:
Arteau, Oliver. “JavaScript prototype pollution attack in NodeJS application.” GitHub, 26 May 2018
Remediation
Upgrade lodash to version 4.17.17 or higher.
References
high severity
- Vulnerable module: minimatch
- Introduced through: grunt@0.4.5 and grunt-cli@0.1.13
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › findup-sync@0.1.3 › glob@3.2.11 › minimatch@0.3.0Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt-cli@0.1.13 › findup-sync@0.1.3 › glob@3.2.11 › minimatch@0.3.0Remediation: Upgrade to grunt-cli@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › minimatch@0.2.14Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › glob@3.1.21 › minimatch@0.2.14Remediation: Upgrade to grunt@1.0.0.
Overview
minimatch is a minimal matching utility.
Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS) via complicated and illegal regexes.
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:
AThe 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.DFinally, 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:
- CCC
- CC+C
- C+CC
- 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 minimatch to version 3.0.2 or higher.
References
high severity
- Vulnerable module: minimatch
- Introduced through: grunt@0.4.5 and grunt-cli@0.1.13
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › findup-sync@0.1.3 › glob@3.2.11 › minimatch@0.3.0Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt-cli@0.1.13 › findup-sync@0.1.3 › glob@3.2.11 › minimatch@0.3.0Remediation: Upgrade to grunt-cli@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › minimatch@0.2.14Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › glob@3.1.21 › minimatch@0.2.14Remediation: Upgrade to grunt@1.0.0.
Overview
minimatch is a minimal matching utility.
Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS).
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:
AThe 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.DFinally, 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:
- CCC
- CC+C
- C+CC
- 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 minimatch to version 3.0.2 or higher.
References
high severity
- Vulnerable module: qs
- Introduced through: http-server@0.6.1 and grunt-http-server@1.0.0
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › http-server@0.6.1 › union@0.3.8 › qs@0.5.6Remediation: Upgrade to http-server@0.7.4.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt-http-server@1.0.0 › http-server@0.6.1 › union@0.3.8 › qs@0.5.6Remediation: Upgrade to grunt-http-server@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 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
wspackage
References
high severity
- Vulnerable module: qs
- Introduced through: http-server@0.6.1 and grunt-http-server@1.0.0
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › http-server@0.6.1 › union@0.3.8 › qs@0.5.6Remediation: Upgrade to http-server@0.11.2.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt-http-server@1.0.0 › http-server@0.6.1 › union@0.3.8 › qs@0.5.6
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.2and6.0.4
Remediation
Upgrade qs to version 6.0.4, 6.1.2, 6.2.3, 6.3.2 or higher.
References
high severity
- Vulnerable module: qs
- Introduced through: http-server@0.6.1 and grunt-http-server@1.0.0
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › http-server@0.6.1 › union@0.3.8 › qs@0.5.6Remediation: Upgrade to http-server@0.11.2.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt-http-server@1.0.0 › http-server@0.6.1 › union@0.3.8 › qs@0.5.6
Overview
qs is a querystring parser that supports nesting and arrays, with a depth limit.
Affected versions of this package are vulnerable to Prototype Poisoning which allows attackers to cause a Node process to hang, processing an Array object whose prototype has been replaced by one with an excessive length value.
Note: In many typical Express use cases, an unauthenticated remote attacker can place the attack payload in the query string of the URL that is used to visit the application, such as a[__proto__]=b&a[__proto__]&a[length]=100000000.
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
wspackage
Remediation
Upgrade qs to version 6.2.4, 6.3.3, 6.4.1, 6.5.3, 6.6.1, 6.7.3, 6.8.3, 6.9.7, 6.10.3 or higher.
References
high severity
- Vulnerable module: lodash
- Introduced through: grunt@0.4.5 and grunt-cli@0.1.13
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › findup-sync@0.1.3 › lodash@2.4.2
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt-cli@0.1.13 › findup-sync@0.1.3 › lodash@2.4.2Remediation: Upgrade to grunt-cli@1.3.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-log@0.1.3 › lodash@2.4.2Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-log@0.1.3 › grunt-legacy-log-utils@0.1.1 › lodash@2.4.2Remediation: Upgrade to grunt@1.0.3.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › lodash@0.9.2Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-util@0.2.0 › lodash@0.9.2Remediation: Upgrade to grunt@1.0.3.
Overview
lodash is a modern JavaScript utility library delivering modularity, performance, & extras.
Affected versions of this package are vulnerable to Prototype Pollution. The function defaultsDeep could be tricked into adding or modifying properties of Object.prototype using a constructor payload.
PoC by Snyk
const mergeFn = require('lodash').defaultsDeep;
const payload = '{"constructor": {"prototype": {"a0": true}}}'
function check() {
mergeFn({}, JSON.parse(payload));
if (({})[`a0`] === true) {
console.log(`Vulnerable to Prototype Pollution via ${payload}`);
}
}
check();
For more information, check out our blog post
Details
Prototype Pollution is a vulnerability affecting JavaScript. Prototype Pollution refers to the ability to inject properties into existing JavaScript language construct prototypes, such as objects. JavaScript allows all Object attributes to be altered, including their magical attributes such as __proto__, constructor and prototype. An attacker manipulates these attributes to overwrite, or pollute, a JavaScript application object prototype of the base object by injecting other values. Properties on the Object.prototype are then inherited by all the JavaScript objects through the prototype chain. When that happens, this leads to either denial of service by triggering JavaScript exceptions, or it tampers with the application source code to force the code path that the attacker injects, thereby leading to remote code execution.
There are two main ways in which the pollution of prototypes occurs:
Unsafe
Objectrecursive mergeProperty definition by path
Unsafe Object recursive merge
The logic of a vulnerable recursive merge function follows the following high-level model:
merge (target, source)
foreach property of source
if property exists and is an object on both the target and the source
merge(target[property], source[property])
else
target[property] = source[property]
When the source object contains a property named __proto__ defined with Object.defineProperty() , the condition that checks if the property exists and is an object on both the target and the source passes and the merge recurses with the target, being the prototype of Object and the source of Object as defined by the attacker. Properties are then copied on the Object prototype.
Clone operations are a special sub-class of unsafe recursive merges, which occur when a recursive merge is conducted on an empty object: merge({},source).
lodash and Hoek are examples of libraries susceptible to recursive merge attacks.
Property definition by path
There are a few JavaScript libraries that use an API to define property values on an object based on a given path. The function that is generally affected contains this signature: theFunction(object, path, value)
If the attacker can control the value of “path”, they can set this value to __proto__.myValue. myValue is then assigned to the prototype of the class of the object.
Types of attacks
There are a few methods by which Prototype Pollution can be manipulated:
| Type | Origin | Short description |
|---|---|---|
| Denial of service (DoS) | Client | This is the most likely attack. DoS occurs when Object holds generic functions that are implicitly called for various operations (for example, toString and valueOf). The attacker pollutes Object.prototype.someattr and alters its state to an unexpected value such as Int or Object. In this case, the code fails and is likely to cause a denial of service. For example: if an attacker pollutes Object.prototype.toString by defining it as an integer, if the codebase at any point was reliant on someobject.toString() it would fail. |
| Remote Code Execution | Client | Remote code execution is generally only possible in cases where the codebase evaluates a specific attribute of an object, and then executes that evaluation. For example: eval(someobject.someattr). In this case, if the attacker pollutes Object.prototype.someattr they are likely to be able to leverage this in order to execute code. |
| Property Injection | Client | The attacker pollutes properties that the codebase relies on for their informative value, including security properties such as cookies or tokens. For example: if a codebase checks privileges for someuser.isAdmin, then when the attacker pollutes Object.prototype.isAdmin and sets it to equal true, they can then achieve admin privileges. |
Affected environments
The following environments are susceptible to a Prototype Pollution attack:
Application server
Web server
Web browser
How to prevent
Freeze the prototype— use
Object.freeze (Object.prototype).Require schema validation of JSON input.
Avoid using unsafe recursive merge functions.
Consider using objects without prototypes (for example,
Object.create(null)), breaking the prototype chain and preventing pollution.As a best practice use
Mapinstead ofObject.
For more information on this vulnerability type:
Arteau, Oliver. “JavaScript prototype pollution attack in NodeJS application.” GitHub, 26 May 2018
Remediation
Upgrade lodash to version 4.17.12 or higher.
References
high severity
- Vulnerable module: lodash
- Introduced through: grunt@0.4.5 and grunt-cli@0.1.13
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › findup-sync@0.1.3 › lodash@2.4.2
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt-cli@0.1.13 › findup-sync@0.1.3 › lodash@2.4.2Remediation: Upgrade to grunt-cli@1.3.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-log@0.1.3 › lodash@2.4.2Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-log@0.1.3 › grunt-legacy-log-utils@0.1.1 › lodash@2.4.2Remediation: Upgrade to grunt@1.0.3.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › lodash@0.9.2Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-util@0.2.0 › lodash@0.9.2Remediation: Upgrade to grunt@1.0.3.
Overview
lodash is a modern JavaScript utility library delivering modularity, performance, & extras.
Affected versions of this package are vulnerable to Prototype Pollution via the set and setwith functions due to improper user input sanitization.
PoC
lod = require('lodash')
lod.set({}, "__proto__[test2]", "456")
console.log(Object.prototype)
Details
Prototype Pollution is a vulnerability affecting JavaScript. Prototype Pollution refers to the ability to inject properties into existing JavaScript language construct prototypes, such as objects. JavaScript allows all Object attributes to be altered, including their magical attributes such as __proto__, constructor and prototype. An attacker manipulates these attributes to overwrite, or pollute, a JavaScript application object prototype of the base object by injecting other values. Properties on the Object.prototype are then inherited by all the JavaScript objects through the prototype chain. When that happens, this leads to either denial of service by triggering JavaScript exceptions, or it tampers with the application source code to force the code path that the attacker injects, thereby leading to remote code execution.
There are two main ways in which the pollution of prototypes occurs:
Unsafe
Objectrecursive mergeProperty definition by path
Unsafe Object recursive merge
The logic of a vulnerable recursive merge function follows the following high-level model:
merge (target, source)
foreach property of source
if property exists and is an object on both the target and the source
merge(target[property], source[property])
else
target[property] = source[property]
When the source object contains a property named __proto__ defined with Object.defineProperty() , the condition that checks if the property exists and is an object on both the target and the source passes and the merge recurses with the target, being the prototype of Object and the source of Object as defined by the attacker. Properties are then copied on the Object prototype.
Clone operations are a special sub-class of unsafe recursive merges, which occur when a recursive merge is conducted on an empty object: merge({},source).
lodash and Hoek are examples of libraries susceptible to recursive merge attacks.
Property definition by path
There are a few JavaScript libraries that use an API to define property values on an object based on a given path. The function that is generally affected contains this signature: theFunction(object, path, value)
If the attacker can control the value of “path”, they can set this value to __proto__.myValue. myValue is then assigned to the prototype of the class of the object.
Types of attacks
There are a few methods by which Prototype Pollution can be manipulated:
| Type | Origin | Short description |
|---|---|---|
| Denial of service (DoS) | Client | This is the most likely attack. DoS occurs when Object holds generic functions that are implicitly called for various operations (for example, toString and valueOf). The attacker pollutes Object.prototype.someattr and alters its state to an unexpected value such as Int or Object. In this case, the code fails and is likely to cause a denial of service. For example: if an attacker pollutes Object.prototype.toString by defining it as an integer, if the codebase at any point was reliant on someobject.toString() it would fail. |
| Remote Code Execution | Client | Remote code execution is generally only possible in cases where the codebase evaluates a specific attribute of an object, and then executes that evaluation. For example: eval(someobject.someattr). In this case, if the attacker pollutes Object.prototype.someattr they are likely to be able to leverage this in order to execute code. |
| Property Injection | Client | The attacker pollutes properties that the codebase relies on for their informative value, including security properties such as cookies or tokens. For example: if a codebase checks privileges for someuser.isAdmin, then when the attacker pollutes Object.prototype.isAdmin and sets it to equal true, they can then achieve admin privileges. |
Affected environments
The following environments are susceptible to a Prototype Pollution attack:
Application server
Web server
Web browser
How to prevent
Freeze the prototype— use
Object.freeze (Object.prototype).Require schema validation of JSON input.
Avoid using unsafe recursive merge functions.
Consider using objects without prototypes (for example,
Object.create(null)), breaking the prototype chain and preventing pollution.As a best practice use
Mapinstead ofObject.
For more information on this vulnerability type:
Arteau, Oliver. “JavaScript prototype pollution attack in NodeJS application.” GitHub, 26 May 2018
Remediation
Upgrade lodash to version 4.17.17 or higher.
References
high severity
- Vulnerable module: lodash
- Introduced through: grunt@0.4.5 and grunt-cli@0.1.13
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › findup-sync@0.1.3 › lodash@2.4.2
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt-cli@0.1.13 › findup-sync@0.1.3 › lodash@2.4.2Remediation: Upgrade to grunt-cli@1.3.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-log@0.1.3 › lodash@2.4.2Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-log@0.1.3 › grunt-legacy-log-utils@0.1.1 › lodash@2.4.2Remediation: Upgrade to grunt@1.0.3.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › lodash@0.9.2Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-util@0.2.0 › lodash@0.9.2Remediation: Upgrade to grunt@1.0.3.
Overview
lodash is a modern JavaScript utility library delivering modularity, performance, & extras.
Affected versions of this package are vulnerable to Prototype Pollution. The functions merge, mergeWith, and defaultsDeep could be tricked into adding or modifying properties of Object.prototype. This is due to an incomplete fix to CVE-2018-3721.
Details
Prototype Pollution is a vulnerability affecting JavaScript. Prototype Pollution refers to the ability to inject properties into existing JavaScript language construct prototypes, such as objects. JavaScript allows all Object attributes to be altered, including their magical attributes such as __proto__, constructor and prototype. An attacker manipulates these attributes to overwrite, or pollute, a JavaScript application object prototype of the base object by injecting other values. Properties on the Object.prototype are then inherited by all the JavaScript objects through the prototype chain. When that happens, this leads to either denial of service by triggering JavaScript exceptions, or it tampers with the application source code to force the code path that the attacker injects, thereby leading to remote code execution.
There are two main ways in which the pollution of prototypes occurs:
Unsafe
Objectrecursive mergeProperty definition by path
Unsafe Object recursive merge
The logic of a vulnerable recursive merge function follows the following high-level model:
merge (target, source)
foreach property of source
if property exists and is an object on both the target and the source
merge(target[property], source[property])
else
target[property] = source[property]
When the source object contains a property named __proto__ defined with Object.defineProperty() , the condition that checks if the property exists and is an object on both the target and the source passes and the merge recurses with the target, being the prototype of Object and the source of Object as defined by the attacker. Properties are then copied on the Object prototype.
Clone operations are a special sub-class of unsafe recursive merges, which occur when a recursive merge is conducted on an empty object: merge({},source).
lodash and Hoek are examples of libraries susceptible to recursive merge attacks.
Property definition by path
There are a few JavaScript libraries that use an API to define property values on an object based on a given path. The function that is generally affected contains this signature: theFunction(object, path, value)
If the attacker can control the value of “path”, they can set this value to __proto__.myValue. myValue is then assigned to the prototype of the class of the object.
Types of attacks
There are a few methods by which Prototype Pollution can be manipulated:
| Type | Origin | Short description |
|---|---|---|
| Denial of service (DoS) | Client | This is the most likely attack. DoS occurs when Object holds generic functions that are implicitly called for various operations (for example, toString and valueOf). The attacker pollutes Object.prototype.someattr and alters its state to an unexpected value such as Int or Object. In this case, the code fails and is likely to cause a denial of service. For example: if an attacker pollutes Object.prototype.toString by defining it as an integer, if the codebase at any point was reliant on someobject.toString() it would fail. |
| Remote Code Execution | Client | Remote code execution is generally only possible in cases where the codebase evaluates a specific attribute of an object, and then executes that evaluation. For example: eval(someobject.someattr). In this case, if the attacker pollutes Object.prototype.someattr they are likely to be able to leverage this in order to execute code. |
| Property Injection | Client | The attacker pollutes properties that the codebase relies on for their informative value, including security properties such as cookies or tokens. For example: if a codebase checks privileges for someuser.isAdmin, then when the attacker pollutes Object.prototype.isAdmin and sets it to equal true, they can then achieve admin privileges. |
Affected environments
The following environments are susceptible to a Prototype Pollution attack:
Application server
Web server
Web browser
How to prevent
Freeze the prototype— use
Object.freeze (Object.prototype).Require schema validation of JSON input.
Avoid using unsafe recursive merge functions.
Consider using objects without prototypes (for example,
Object.create(null)), breaking the prototype chain and preventing pollution.As a best practice use
Mapinstead ofObject.
For more information on this vulnerability type:
Arteau, Oliver. “JavaScript prototype pollution attack in NodeJS application.” GitHub, 26 May 2018
Remediation
Upgrade lodash to version 4.17.11 or higher.
References
high severity
- Vulnerable module: lodash
- Introduced through: grunt@0.4.5 and grunt-cli@0.1.13
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › findup-sync@0.1.3 › lodash@2.4.2
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt-cli@0.1.13 › findup-sync@0.1.3 › lodash@2.4.2Remediation: Upgrade to grunt-cli@1.3.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-log@0.1.3 › lodash@2.4.2Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-log@0.1.3 › grunt-legacy-log-utils@0.1.1 › lodash@2.4.2Remediation: Upgrade to grunt@1.0.3.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › lodash@0.9.2Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-util@0.2.0 › lodash@0.9.2Remediation: Upgrade to grunt@1.0.3.
Overview
lodash is a modern JavaScript utility library delivering modularity, performance, & extras.
Affected versions of this package are vulnerable to Code Injection via template.
PoC
var _ = require('lodash');
_.template('', { variable: '){console.log(process.env)}; with(obj' })()
Remediation
Upgrade lodash to version 4.17.21 or higher.
References
high severity
- Vulnerable module: grunt
- Introduced through: grunt@0.4.5
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5Remediation: Upgrade to grunt@1.3.0.
Overview
grunt is a JavaScript task runner.
Affected versions of this package are vulnerable to Arbitrary Code Execution due to the default usage of the function load() instead of its secure replacement safeLoad() of the package js-yaml inside grunt.file.readYAML.
Remediation
Upgrade grunt to version 1.3.0 or higher.
References
medium severity
- Vulnerable module: js-yaml
- Introduced through: grunt@0.4.5
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › js-yaml@2.0.5Remediation: Upgrade to grunt@1.2.0.
Overview
js-yaml is a human-friendly data serialization language.
Affected versions of this package are vulnerable to Prototype Pollution via the merge function. An attacker can alter object prototypes by supplying specially crafted YAML documents containing __proto__ properties. This can lead to unexpected behavior or security issues in applications that process untrusted YAML input.
Workaround
This vulnerability can be mitigated by running the server with node --disable-proto=delete or by using Deno, which has pollution protection enabled by default.
Details
Prototype Pollution is a vulnerability affecting JavaScript. Prototype Pollution refers to the ability to inject properties into existing JavaScript language construct prototypes, such as objects. JavaScript allows all Object attributes to be altered, including their magical attributes such as __proto__, constructor and prototype. An attacker manipulates these attributes to overwrite, or pollute, a JavaScript application object prototype of the base object by injecting other values. Properties on the Object.prototype are then inherited by all the JavaScript objects through the prototype chain. When that happens, this leads to either denial of service by triggering JavaScript exceptions, or it tampers with the application source code to force the code path that the attacker injects, thereby leading to remote code execution.
There are two main ways in which the pollution of prototypes occurs:
Unsafe
Objectrecursive mergeProperty definition by path
Unsafe Object recursive merge
The logic of a vulnerable recursive merge function follows the following high-level model:
merge (target, source)
foreach property of source
if property exists and is an object on both the target and the source
merge(target[property], source[property])
else
target[property] = source[property]
When the source object contains a property named __proto__ defined with Object.defineProperty() , the condition that checks if the property exists and is an object on both the target and the source passes and the merge recurses with the target, being the prototype of Object and the source of Object as defined by the attacker. Properties are then copied on the Object prototype.
Clone operations are a special sub-class of unsafe recursive merges, which occur when a recursive merge is conducted on an empty object: merge({},source).
lodash and Hoek are examples of libraries susceptible to recursive merge attacks.
Property definition by path
There are a few JavaScript libraries that use an API to define property values on an object based on a given path. The function that is generally affected contains this signature: theFunction(object, path, value)
If the attacker can control the value of “path”, they can set this value to __proto__.myValue. myValue is then assigned to the prototype of the class of the object.
Types of attacks
There are a few methods by which Prototype Pollution can be manipulated:
| Type | Origin | Short description |
|---|---|---|
| Denial of service (DoS) | Client | This is the most likely attack. DoS occurs when Object holds generic functions that are implicitly called for various operations (for example, toString and valueOf). The attacker pollutes Object.prototype.someattr and alters its state to an unexpected value such as Int or Object. In this case, the code fails and is likely to cause a denial of service. For example: if an attacker pollutes Object.prototype.toString by defining it as an integer, if the codebase at any point was reliant on someobject.toString() it would fail. |
| Remote Code Execution | Client | Remote code execution is generally only possible in cases where the codebase evaluates a specific attribute of an object, and then executes that evaluation. For example: eval(someobject.someattr). In this case, if the attacker pollutes Object.prototype.someattr they are likely to be able to leverage this in order to execute code. |
| Property Injection | Client | The attacker pollutes properties that the codebase relies on for their informative value, including security properties such as cookies or tokens. For example: if a codebase checks privileges for someuser.isAdmin, then when the attacker pollutes Object.prototype.isAdmin and sets it to equal true, they can then achieve admin privileges. |
Affected environments
The following environments are susceptible to a Prototype Pollution attack:
Application server
Web server
Web browser
How to prevent
Freeze the prototype— use
Object.freeze (Object.prototype).Require schema validation of JSON input.
Avoid using unsafe recursive merge functions.
Consider using objects without prototypes (for example,
Object.create(null)), breaking the prototype chain and preventing pollution.As a best practice use
Mapinstead ofObject.
For more information on this vulnerability type:
Arteau, Oliver. “JavaScript prototype pollution attack in NodeJS application.” GitHub, 26 May 2018
Remediation
Upgrade js-yaml to version 3.14.2, 4.1.1 or higher.
References
medium severity
- Vulnerable module: grunt
- Introduced through: grunt@0.4.5
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5Remediation: Upgrade to grunt@1.5.3.
Overview
grunt is a JavaScript task runner.
Affected versions of this package are vulnerable to Race Condition via the file.copy operations. Exploiting this vulnerability leads to arbitrary file writing when an attacker can create a symlink just after deletion of the destination symlink, but right before the symlink is being written.
Remediation
Upgrade grunt to version 1.5.3 or higher.
References
medium severity
- Vulnerable module: qs
- Introduced through: http-server@0.6.1 and grunt-http-server@1.0.0
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › http-server@0.6.1 › union@0.3.8 › qs@0.5.6Remediation: Upgrade to http-server@0.7.4.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt-http-server@1.0.0 › http-server@0.6.1 › union@0.3.8 › qs@0.5.6Remediation: Upgrade to grunt-http-server@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 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:
AThe 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.DFinally, 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:
- CCC
- CC+C
- C+CC
- 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
- Vulnerable module: grunt
- Introduced through: grunt@0.4.5
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5Remediation: Upgrade to grunt@1.5.0.
Overview
grunt is a JavaScript task runner.
Affected versions of this package are vulnerable to Directory Traversal via creation of a symlink to a restricted file, if a local attacker has write access to the source directory of file.copy
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 grunt to version 1.5.0 or higher.
References
medium severity
- Vulnerable module: lodash
- Introduced through: grunt@0.4.5 and grunt-cli@0.1.13
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › findup-sync@0.1.3 › lodash@2.4.2
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt-cli@0.1.13 › findup-sync@0.1.3 › lodash@2.4.2Remediation: Upgrade to grunt-cli@1.3.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-log@0.1.3 › lodash@2.4.2Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-log@0.1.3 › grunt-legacy-log-utils@0.1.1 › lodash@2.4.2Remediation: Upgrade to grunt@1.0.3.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › lodash@0.9.2Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-util@0.2.0 › lodash@0.9.2Remediation: Upgrade to grunt@1.0.3.
Overview
lodash is a modern 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);
Details
Prototype Pollution is a vulnerability affecting JavaScript. Prototype Pollution refers to the ability to inject properties into existing JavaScript language construct prototypes, such as objects. JavaScript allows all Object attributes to be altered, including their magical attributes such as __proto__, constructor and prototype. An attacker manipulates these attributes to overwrite, or pollute, a JavaScript application object prototype of the base object by injecting other values. Properties on the Object.prototype are then inherited by all the JavaScript objects through the prototype chain. When that happens, this leads to either denial of service by triggering JavaScript exceptions, or it tampers with the application source code to force the code path that the attacker injects, thereby leading to remote code execution.
There are two main ways in which the pollution of prototypes occurs:
Unsafe
Objectrecursive mergeProperty definition by path
Unsafe Object recursive merge
The logic of a vulnerable recursive merge function follows the following high-level model:
merge (target, source)
foreach property of source
if property exists and is an object on both the target and the source
merge(target[property], source[property])
else
target[property] = source[property]
When the source object contains a property named __proto__ defined with Object.defineProperty() , the condition that checks if the property exists and is an object on both the target and the source passes and the merge recurses with the target, being the prototype of Object and the source of Object as defined by the attacker. Properties are then copied on the Object prototype.
Clone operations are a special sub-class of unsafe recursive merges, which occur when a recursive merge is conducted on an empty object: merge({},source).
lodash and Hoek are examples of libraries susceptible to recursive merge attacks.
Property definition by path
There are a few JavaScript libraries that use an API to define property values on an object based on a given path. The function that is generally affected contains this signature: theFunction(object, path, value)
If the attacker can control the value of “path”, they can set this value to __proto__.myValue. myValue is then assigned to the prototype of the class of the object.
Types of attacks
There are a few methods by which Prototype Pollution can be manipulated:
| Type | Origin | Short description |
|---|---|---|
| Denial of service (DoS) | Client | This is the most likely attack. DoS occurs when Object holds generic functions that are implicitly called for various operations (for example, toString and valueOf). The attacker pollutes Object.prototype.someattr and alters its state to an unexpected value such as Int or Object. In this case, the code fails and is likely to cause a denial of service. For example: if an attacker pollutes Object.prototype.toString by defining it as an integer, if the codebase at any point was reliant on someobject.toString() it would fail. |
| Remote Code Execution | Client | Remote code execution is generally only possible in cases where the codebase evaluates a specific attribute of an object, and then executes that evaluation. For example: eval(someobject.someattr). In this case, if the attacker pollutes Object.prototype.someattr they are likely to be able to leverage this in order to execute code. |
| Property Injection | Client | The attacker pollutes properties that the codebase relies on for their informative value, including security properties such as cookies or tokens. For example: if a codebase checks privileges for someuser.isAdmin, then when the attacker pollutes Object.prototype.isAdmin and sets it to equal true, they can then achieve admin privileges. |
Affected environments
The following environments are susceptible to a Prototype Pollution attack:
Application server
Web server
Web browser
How to prevent
Freeze the prototype— use
Object.freeze (Object.prototype).Require schema validation of JSON input.
Avoid using unsafe recursive merge functions.
Consider using objects without prototypes (for example,
Object.create(null)), breaking the prototype chain and preventing pollution.As a best practice use
Mapinstead ofObject.
For more information on this vulnerability type:
Arteau, Oliver. “JavaScript prototype pollution attack in NodeJS application.” GitHub, 26 May 2018
Remediation
Upgrade lodash to version 4.17.5 or higher.
References
medium severity
- Vulnerable module: underscore
- Introduced through: grunt@0.4.5
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › js-yaml@2.0.5 › argparse@0.1.16 › underscore@1.7.0
Overview
underscore is a JavaScript's functional programming helper library.
Affected versions of this package are vulnerable to Arbitrary Code Injection via the template function, particularly when the variable option is taken from _.templateSettings as it is not sanitized.
PoC
const _ = require('underscore');
_.templateSettings.variable = "a = this.process.mainModule.require('child_process').execSync('touch HELLO')";
const t = _.template("")();
Remediation
Upgrade underscore to version 1.13.0-2, 1.12.1 or higher.
References
medium severity
- Vulnerable module: ecstatic
- Introduced through: http-server@0.6.1 and grunt-http-server@1.0.0
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › http-server@0.6.1 › ecstatic@0.4.13Remediation: Upgrade to http-server@0.10.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt-http-server@1.0.0 › http-server@0.6.1 › ecstatic@0.4.13Remediation: Upgrade to grunt-http-server@2.1.0.
Overview
ecstatic is a simple static file server middleware. Use it with a raw http server, express/connect or on the CLI.
Affected versions of this package are vulnerable to Open Redirect. The package failed to validate redirects, allowing attackers to craft requests that result in an HTTP 301 redirect to any other domains.
Remediation
Upgrade ecstatic to version 2.2.2, 3.3.2, 4.1.2 or higher.
References
medium severity
- Vulnerable module: ecstatic
- Introduced through: http-server@0.6.1 and grunt-http-server@1.0.0
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › http-server@0.6.1 › ecstatic@0.4.13Remediation: Upgrade to http-server@0.10.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt-http-server@1.0.0 › http-server@0.6.1 › ecstatic@0.4.13Remediation: Upgrade to grunt-http-server@2.1.0.
Overview
ecstatic is a simple static file server middleware. Use it with a raw http server, express/connect or on the CLI.
Affected versions of this package are vulnerable to Denial of Service (DoS). The process of replacing null bytes in the url string is being done in a loop:
Find Null Bytes --> If found remove Null Byte --> Repeat
When no more Null Bytes found, the flow of the program continues.
This method would work fine with a normal URL that should be relatively short, but a malicious user may craft a very long URL with a lot of Null Bytes.
PoC by Checkmarx:
http://www.checkmarx.com/advisories/%00%00%00%00%00%00...
Slowdown:
A payload of 22kB caused a lag of 1 second, A payload of 35kB caused a lag of 3 seconds, A payload of 86kB caused the server to crash
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:
AThe 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.DFinally, 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:
- CCC
- CC+C
- C+CC
- 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 ecstatic to version 2.0.0 or higher.
References
medium severity
- Vulnerable module: lodash
- Introduced through: grunt@0.4.5 and grunt-cli@0.1.13
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › findup-sync@0.1.3 › lodash@2.4.2
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt-cli@0.1.13 › findup-sync@0.1.3 › lodash@2.4.2Remediation: Upgrade to grunt-cli@1.3.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-log@0.1.3 › lodash@2.4.2Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-log@0.1.3 › grunt-legacy-log-utils@0.1.1 › lodash@2.4.2Remediation: Upgrade to grunt@1.0.3.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › lodash@0.9.2Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-util@0.2.0 › lodash@0.9.2Remediation: Upgrade to grunt@1.0.3.
Overview
lodash is a modern JavaScript utility library delivering modularity, performance, & extras.
Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS) via the toNumber, trim and trimEnd functions.
POC
var lo = require('lodash');
function build_blank (n) {
var ret = "1"
for (var i = 0; i < n; i++) {
ret += " "
}
return ret + "1";
}
var s = build_blank(50000)
var time0 = Date.now();
lo.trim(s)
var time_cost0 = Date.now() - time0;
console.log("time_cost0: " + time_cost0)
var time1 = Date.now();
lo.toNumber(s)
var time_cost1 = Date.now() - time1;
console.log("time_cost1: " + time_cost1)
var time2 = Date.now();
lo.trimEnd(s)
var time_cost2 = Date.now() - time2;
console.log("time_cost2: " + time_cost2)
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:
AThe 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.DFinally, 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:
- CCC
- CC+C
- C+CC
- 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 lodash to version 4.17.21 or higher.
References
medium severity
- Vulnerable module: minimatch
- Introduced through: grunt@0.4.5 and grunt-cli@0.1.13
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › findup-sync@0.1.3 › glob@3.2.11 › minimatch@0.3.0Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt-cli@0.1.13 › findup-sync@0.1.3 › glob@3.2.11 › minimatch@0.3.0Remediation: Upgrade to grunt-cli@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › minimatch@0.2.14Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › glob@3.1.21 › minimatch@0.2.14Remediation: Upgrade to grunt@1.0.0.
Overview
minimatch is a minimal matching utility.
Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS) via the braceExpand function in minimatch.js.
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:
AThe 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.DFinally, 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:
- CCC
- CC+C
- C+CC
- 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 minimatch to version 3.0.5 or higher.
References
medium severity
- Vulnerable module: lodash
- Introduced through: grunt@0.4.5 and grunt-cli@0.1.13
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › findup-sync@0.1.3 › lodash@2.4.2
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt-cli@0.1.13 › findup-sync@0.1.3 › lodash@2.4.2Remediation: Upgrade to grunt-cli@1.3.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-log@0.1.3 › lodash@2.4.2Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-log@0.1.3 › grunt-legacy-log-utils@0.1.1 › lodash@2.4.2Remediation: Upgrade to grunt@1.0.3.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › lodash@0.9.2Remediation: Upgrade to grunt@1.0.0.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt@0.4.5 › grunt-legacy-util@0.2.0 › lodash@0.9.2Remediation: Upgrade to grunt@1.0.3.
Overview
lodash is a modern JavaScript utility library delivering modularity, performance, & extras.
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:
AThe 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.DFinally, 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:
- CCC
- CC+C
- C+CC
- 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 lodash to version 4.17.11 or higher.
References
low severity
- Vulnerable module: mime
- Introduced through: http-server@0.6.1 and grunt-http-server@1.0.0
Detailed paths
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › http-server@0.6.1 › ecstatic@0.4.13 › mime@1.2.11Remediation: Upgrade to http-server@0.7.2.
-
Introduced through: @jshemas/textadventure#18f89d9fdc628ac7491717d25db0860264a25ba9 › grunt-http-server@1.0.0 › http-server@0.6.1 › ecstatic@0.4.13 › mime@1.2.11Remediation: Upgrade to grunt-http-server@1.1.0.
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:
AThe 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.DFinally, 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:
- CCC
- CC+C
- C+CC
- 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.