Vulnerabilities |
14 via 38 paths |
|---|---|
Dependencies |
456 |
Source |
GitHub |
Find, fix and prevent vulnerabilities in your code.
critical severity
- Vulnerable module: flatted
- Introduced through: textlint@12.6.1
Detailed paths
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › textlint@12.6.1 › file-entry-cache@5.0.1 › flat-cache@2.0.1 › flatted@2.0.2Remediation: Upgrade to textlint@14.4.1.
Overview
Affected versions of this package are vulnerable to Prototype Pollution via the parse function. An attacker can manipulate the prototype chain by supplying a specially crafted string that causes the returned object to reference Array.prototype, allowing subsequent writes to that property to affect the global prototype and potentially lead to denial of service or code execution.
PoC
const Flatted = require('flatted');
const parsed = Flatted.parse('[{"x":"__proto__"}]');
parsed.x.polluted = 'pwned';
console.log([].polluted); // Returns 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, Olivier. “JavaScript prototype pollution attack in NodeJS application.” GitHub, 26 May 2018
Remediation
Upgrade flatted to version 3.4.2 or higher.
References
high severity
- Vulnerable module: braces
- Introduced through: hexo@6.3.0, hexo-cli@4.3.2 and others
Detailed paths
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo@6.3.0 › micromatch@4.0.8 › braces@3.0.3
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo-cli@4.3.2 › hexo-fs@4.1.3 › chokidar@3.6.0 › braces@3.0.3
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo@6.3.0 › hexo-fs@3.1.0 › chokidar@3.6.0 › braces@3.0.3
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo-deployer-git@3.0.0 › hexo-fs@3.1.0 › chokidar@3.6.0 › braces@3.0.3
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo@6.3.0 › hexo-cli@4.3.2 › hexo-fs@4.1.3 › chokidar@3.6.0 › braces@3.0.3
Overview
braces is a Bash-like brace expansion, implemented in JavaScript.
Affected versions of this package are vulnerable to Uncontrolled Recursion in the recursive AST walkers, which lack depth guards. An attacker can supply deeply nested brace patterns that stay within the character limit to exhaust the call stack and crash the Node.js process with an uncaught RangeError.
Remediation
There is no fixed version for braces.
References
high severity
- Vulnerable module: flatted
- Introduced through: textlint@12.6.1
Detailed paths
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › textlint@12.6.1 › file-entry-cache@5.0.1 › flat-cache@2.0.1 › flatted@2.0.2Remediation: Upgrade to textlint@14.4.1.
Overview
Affected versions of this package are vulnerable to Uncontrolled Recursion via the parse function due to using a recursive revive() phase to resolve circular references in deserialized JSON. An attacker can cause a stack overflow and crash the process by supplying a crafted payload with deeply nested or self-referential indices.
PoC
const flatted = require('flatted');
// Build deeply nested circular reference chain
const depth = 20000;
const arr = new Array(depth + 1);
arr[0] = '{"a":"1"}';
for (let i = 1; i <= depth; i++) {
arr[i] = `{"a":"${i + 1}"}`;
}
arr[depth] = '{"a":"leaf"}';
const payload = JSON.stringify(arr);
flatted.parse(payload); // RangeError: Maximum call stack size exceeded
Remediation
Upgrade flatted to version 3.4.0 or higher.
References
high severity
- Vulnerable module: linkify-it
- Introduced through: hexo-renderer-markdown-it@6.1.0
Detailed paths
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo-renderer-markdown-it@6.1.0 › markdown-it@12.3.2 › linkify-it@3.0.3
Overview
linkify-it is a Links recognition library with FULL unicode support
Affected versions of this package are vulnerable to Inefficient Algorithmic Complexity in the mailto: validator scan-loop on attacker-supplied text. An attacker can cause excessive CPU consumption by submitting specially crafted input that triggers repeated scanning of the remaining text.
Remediation
Upgrade linkify-it to version 5.0.2 or higher.
References
high severity
- Vulnerable module: linkify-it
- Introduced through: hexo-renderer-markdown-it@6.1.0
Detailed paths
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo-renderer-markdown-it@6.1.0 › markdown-it@12.3.2 › linkify-it@3.0.3
Overview
linkify-it is a Links recognition library with FULL unicode support
Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS) due to quadratic algorithmic complexity in the match function. An attacker can exhaust CPU resources and cause significant delays in processing by submitting specially crafted input containing a large number of email-like or link-like strings.
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 linkify-it to version 5.0.1 or higher.
References
high severity
new
- Vulnerable module: markdown-it
- Introduced through: hexo-renderer-markdown-it@6.1.0
Detailed paths
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo-renderer-markdown-it@6.1.0 › markdown-it@12.3.2
Overview
markdown-it is a modern pluggable markdown parser.
Affected versions of this package are vulnerable to Unchecked Input for Loop Condition via the process_inlines function in src/rules_core/smartquotes.ts when the typographer option is enabled. The smartquotes rule performs a linear scan of the opener stack for every closing quote token, resulting in quadratic time complexity when quote types do not match. An attacker can supply input with a large number of unmatched quote characters to cause a crash through excessive CPU consumption.
Note: This is only exploitable when the typographer: true option is explicitly set, as the default configuration (typographer: false) does not invoke the smartquotes rule.
Remediation
Upgrade markdown-it to version 15.0.2, 14.3.2 or higher.
References
high severity
new
- Vulnerable module: picomatch
- Introduced through: hexo@6.3.0, hexo-cli@4.3.2 and others
Detailed paths
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo@6.3.0 › micromatch@4.0.8 › picomatch@2.3.2
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo-cli@4.3.2 › hexo-fs@4.1.3 › chokidar@3.6.0 › anymatch@3.1.3 › picomatch@2.3.2
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo@6.3.0 › hexo-fs@3.1.0 › chokidar@3.6.0 › anymatch@3.1.3 › picomatch@2.3.2
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo-deployer-git@3.0.0 › hexo-fs@3.1.0 › chokidar@3.6.0 › anymatch@3.1.3 › picomatch@2.3.2
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo-cli@4.3.2 › hexo-fs@4.1.3 › chokidar@3.6.0 › readdirp@3.6.0 › picomatch@2.3.2
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo@6.3.0 › hexo-fs@3.1.0 › chokidar@3.6.0 › readdirp@3.6.0 › picomatch@2.3.2
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo-deployer-git@3.0.0 › hexo-fs@3.1.0 › chokidar@3.6.0 › readdirp@3.6.0 › picomatch@2.3.2
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo@6.3.0 › hexo-cli@4.3.2 › hexo-fs@4.1.3 › chokidar@3.6.0 › anymatch@3.1.3 › picomatch@2.3.2
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo@6.3.0 › hexo-cli@4.3.2 › hexo-fs@4.1.3 › chokidar@3.6.0 › readdirp@3.6.0 › picomatch@2.3.2
Overview
Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS) via analyzeRepeatedExtglob in lib/parse.js, which skips single-branch repeated extglob patterns such as +(*) or +(*a). An attacker can supply these glob patterns to trigger exponential backtracking in the underlying regular expression engine against short inputs, blocking the Node.js event loop and crashing the application.
Details
Denial of Service (DoS) describes a family of attacks, all aimed at making a system inaccessible to its original and legitimate users. There are many types of DoS attacks, ranging from trying to clog the network pipes to the system by generating a large volume of traffic from many machines (a Distributed Denial of Service - DDoS - attack) to sending crafted requests that cause a system to crash or take a disproportional amount of time to process.
The Regular expression Denial of Service (ReDoS) is a type of Denial of Service attack. Regular expressions are incredibly powerful, but they aren't very intuitive and can ultimately end up making it easy for attackers to take your site down.
Let’s take the following regular expression as an example:
regex = /A(B|C+)+D/
This regular expression accomplishes the following:
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
There is no fixed version for picomatch.
References
high severity
- Vulnerable module: hexo
- Introduced through: hexo@6.3.0
Detailed paths
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo@6.3.0Remediation: Upgrade to hexo@7.2.0.
Overview
hexo is an A fast, simple & powerful blog framework, powered by Node.js.
Affected versions of this package are vulnerable to Directory Traversal via the Hexo's file read functionality. An attacker can read arbitrary files by manipulating the file path input.
Note:
This issue is only exploitable if the attacker has the ability to control the file path input. This vulnerability was only verified successfully in the Windows environment.
PoC
{% include_code ..\..\..\..\..\..\..\..\..\..\..\test.txt %}
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 hexo to version 7.2.0 or higher.
References
high severity
- Vulnerable module: markdown-it
- Introduced through: hexo-renderer-markdown-it@6.1.0
Detailed paths
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo-renderer-markdown-it@6.1.0 › markdown-it@12.3.2Remediation: Upgrade to hexo-renderer-markdown-it@7.0.0.
Overview
markdown-it is a modern pluggable markdown parser.
Affected versions of this package are vulnerable to Infinite loop in linkify inline rule when using malformed input.
Remediation
Upgrade markdown-it to version 13.0.2 or higher.
References
medium severity
- Vulnerable module: markdown-it
- Introduced through: hexo-renderer-markdown-it@6.1.0
Detailed paths
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo-renderer-markdown-it@6.1.0 › markdown-it@12.3.2
Overview
markdown-it is a modern pluggable markdown parser.
Affected versions of this package are vulnerable to Inefficient Algorithmic Complexity through the replaceAt() function in the smartquotes rule when processing markdown input with a large number of consecutive quotation marks and the typographer option enabled. An attacker can cause excessive CPU consumption and disrupt service availability by submitting specially crafted markdown content containing many quote characters.
Remediation
Upgrade markdown-it to version 14.2.0 or higher.
References
medium severity
- Vulnerable module: deepmerge
- Introduced through: hexo-cli@4.3.2, hexo@6.3.0 and others
Detailed paths
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo-cli@4.3.2 › hexo-util@3.3.0 › deepmerge@4.3.1
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo@6.3.0 › hexo-util@2.7.0 › deepmerge@4.3.1
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo-deployer-git@3.0.0 › hexo-util@2.7.0 › deepmerge@4.3.1
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo-generator-alias@1.0.0 › hexo-util@2.7.0 › deepmerge@4.3.1
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo-generator-feed@3.0.0 › hexo-util@2.7.0 › deepmerge@4.3.1
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo-renderer-markdown-it@6.1.0 › hexo-util@2.7.0 › deepmerge@4.3.1
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo-cli@4.3.2 › hexo-fs@4.1.3 › hexo-util@3.3.0 › deepmerge@4.3.1
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo@6.3.0 › hexo-cli@4.3.2 › hexo-util@3.3.0 › deepmerge@4.3.1
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo@6.3.0 › hexo-fs@3.1.0 › hexo-util@2.7.0 › deepmerge@4.3.1
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo-deployer-git@3.0.0 › hexo-fs@3.1.0 › hexo-util@2.7.0 › deepmerge@4.3.1
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo@6.3.0 › hexo-cli@4.3.2 › hexo-fs@4.1.3 › hexo-util@3.3.0 › deepmerge@4.3.1
Overview
Affected versions of this package are vulnerable to Prototype Pollution via mergeObject(), which fails to validate keys before writing them to target objects. An attacker can supply a malicious source object containing a __proto__ key in a merge operation, injecting attacker-controlled properties into the prototype of the returned object and causing applications to inherit unintended values when accessing properties without own-property checks.
Notes:
- The proposed fix in PR #274 denies proto by name in both merge loops and adds regression tests. The PR was closed without merging and the main branch still contains the vulnerable guard.
- The maintainer closed the issue as “completed” without a technical rebuttal. Per them, they will not review the fix
- Scope: According to the tests, a plain {} target is guarded. The global Object.prototype is not modified, and Impact is limited to the object returned by merge().
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, Olivier. “JavaScript prototype pollution attack in NodeJS application.” GitHub, 26 May 2018
Remediation
There is no fixed version for deepmerge.
References
medium severity
new
- Vulnerable module: markdown-it
- Introduced through: hexo-renderer-markdown-it@6.1.0
Detailed paths
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo-renderer-markdown-it@6.1.0 › markdown-it@12.3.2
Overview
markdown-it is a modern pluggable markdown parser.
Affected versions of this package are vulnerable to Inefficient Algorithmic Complexity in the linkify rule (src/rules_core/linkify.ts) via input containing multiple fuzzy links. The arrayReplaceAt utility was called repeatedly inside the token-processing loop, causing each replacement to copy the entire token array, resulting in O(n²) time complexity as the number of links grows. An attacker can trigger excessive CPU consumption by supplying input with a large number of linkified URLs.
Remediation
Upgrade markdown-it to version 14.3.1, 15.0.1 or higher.
References
medium severity
new
- Vulnerable module: markdown-it
- Introduced through: hexo-renderer-markdown-it@6.1.0
Detailed paths
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo-renderer-markdown-it@6.1.0 › markdown-it@12.3.2
Overview
markdown-it is a modern pluggable markdown parser.
Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS) via the inline HTML parsing rule in src/rules_inline/html_inline.ts, where the HTML_TAG_RE regular expression is applied against untrusted input. An attacker can supply input containing unclosed HTML special constructs (comments, processing instructions, declarations, or CDATA sections) to trigger quadratic backtracking, causing the parser to consume excessive CPU time and crash the process.
Note: This is only exploitable when the html option is enabled, for example via the commonmark preset. The default configuration has HTML disabled and is unaffected.
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 markdown-it to version 14.3.3, 15.0.3 or higher.
References
medium severity
- Vulnerable module: inflight
- Introduced through: textlint@12.6.1 and hexo-renderer-stylus@2.1.0
Detailed paths
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › textlint@12.6.1 › glob@7.2.3 › inflight@1.0.6
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › hexo-renderer-stylus@2.1.0 › stylus@0.57.0 › glob@7.2.3 › inflight@1.0.6
-
Introduced through: nodejs-ko@nodejs/nodejs-ko › textlint@12.6.1 › file-entry-cache@5.0.1 › flat-cache@2.0.1 › rimraf@2.6.3 › glob@7.2.3 › inflight@1.0.6
Overview
Affected versions of this package are vulnerable to Missing Release of Resource after Effective Lifetime via the makeres function due to improperly deleting keys from the reqs object after execution of callbacks. This behavior causes the keys to remain in the reqs object, which leads to resource exhaustion.
Exploiting this vulnerability results in crashing the node process or in the application crash.
Note: This library is not maintained, and currently, there is no fix for this issue. To overcome this vulnerability, several dependent packages have eliminated the use of this library.
To trigger the memory leak, an attacker would need to have the ability to execute or influence the asynchronous operations that use the inflight module within the application. This typically requires access to the internal workings of the server or application, which is not commonly exposed to remote users. Therefore, “Attack vector” is marked as “Local”.
PoC
const inflight = require('inflight');
function testInflight() {
let i = 0;
function scheduleNext() {
let key = `key-${i++}`;
const callback = () => {
};
for (let j = 0; j < 1000000; j++) {
inflight(key, callback);
}
setImmediate(scheduleNext);
}
if (i % 100 === 0) {
console.log(process.memoryUsage());
}
scheduleNext();
}
testInflight();
Remediation
There is no fixed version for inflight.