Vulnerabilities

34 via 80 paths

Dependencies

838

Source

GitHub

Commit

671fda81

Find, fix and prevent vulnerabilities in your code.

Issue type
  • 34
  • 2
Severity
  • 4
  • 16
  • 14
  • 2
Status
  • 36
  • 0
  • 0

critical severity

Heap-based Buffer Overflow

  • Vulnerable module: sharp
  • Introduced through: sharp@0.30.7

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de sharp@0.30.7
    Remediation: Upgrade to sharp@0.32.6.

Overview

sharp is a High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images

Affected versions of this package are vulnerable to Heap-based Buffer Overflow when the ReadHuffmanCodes() function is used. An attacker can craft a special WebP lossless file that triggers the ReadHuffmanCodes() function to allocate the HuffmanCode buffer with a size that comes from an array of precomputed sizes: kTableSize. The color_cache_bits value defines which size to use. The kTableSize array only takes into account sizes for 8-bit first-level table lookups but not second-level table lookups. libwebp allows codes that are up to 15-bit (MAX_ALLOWED_CODE_LENGTH). When BuildHuffmanTable() attempts to fill the second-level tables it may write data out-of-bounds. The OOB write to the undersized array happens in ReplicateValue.

Notes:

This is only exploitable if the color_cache_bits value defines which size to use.

This vulnerability was also published on libwebp CVE-2023-5129

Changelog:

2023-09-12: Initial advisory publication

2023-09-27: Advisory details updated, including CVSS, references

2023-09-27: CVE-2023-5129 rejected as a duplicate of CVE-2023-4863

2023-09-28: Research and addition of additional affected libraries

2024-01-28: Additional fix information

Remediation

Upgrade sharp to version 0.32.6 or higher.

References

critical severity

Improper Verification of Cryptographic Signature

  • Vulnerable module: elliptic
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13 and particl-bitcore-lib@0.16.0

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 @zasmilingidiot/omp-lib@0.2.0 particl-bitcore-lib@https://github.com/kewde/particl-bitcore-lib.git elliptic@3.0.3
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de particl-bitcore-lib@0.16.0 elliptic@6.4.0
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 particl-bitcore-lib@0.16.0 elliptic@6.4.0

Overview

elliptic is a fast elliptic-curve cryptography implementation in plain javascript.

Affected versions of this package are vulnerable to Improper Verification of Cryptographic Signature due to a missing signature length check in the EDDSA signature process. An attacker can manipulate the signature by appending or removing zero-valued bytes.

PoC

var elliptic = require('elliptic'); // tested with version 6.5.6
var eddsa = elliptic.eddsa;

var ed25519 = new eddsa('ed25519');
var key = ed25519.keyFromPublic('7d4d0e7f6153a69b6242b522abbee685fda4420f8834b108c3bdae369ef549fa', 'hex');

// [tcId 37] appending 0 byte to signature
var msg = '54657374';
var sig =  '7c38e026f29e14aabd059a0f2db8b0cd783040609a8be684db12f82a27774ab07a9155711ecfaf7f99f277bad0c6ae7e39d4eef676573336a5c51eb6f946b30d00';
console.log(key.verify(msg, sig));

// [tcId 38] removing 0 byte from signature
msg = '546573743137';
sig =  '93de3ca252426c95f735cb9edd92e83321ac62372d5aa5b379786bae111ab6b17251330e8f9a7c30d6993137c596007d7b001409287535ac4804e662bc58a3';
console.log(key.verify(msg, sig));

Remediation

Upgrade elliptic to version 6.5.7 or higher.

References

critical severity

Improper Verification of Cryptographic Signature

  • Vulnerable module: elliptic
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13 and particl-bitcore-lib@0.16.0

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 @zasmilingidiot/omp-lib@0.2.0 particl-bitcore-lib@https://github.com/kewde/particl-bitcore-lib.git elliptic@3.0.3
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de particl-bitcore-lib@0.16.0 elliptic@6.4.0
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 particl-bitcore-lib@0.16.0 elliptic@6.4.0

Overview

elliptic is a fast elliptic-curve cryptography implementation in plain javascript.

Affected versions of this package are vulnerable to Improper Verification of Cryptographic Signature due to the allowance of BER-encoded signatures. An attacker can manipulate the ECDSA signatures by exploiting the signature malleability.

PoC

var elliptic = require('elliptic'); // tested with version 6.5.6
var hash = require('hash.js');
var toArray = elliptic.utils.toArray;

var ec = new elliptic.ec('p521');

// [tcId 7] length of sequence [r, s] contains a leading 0
var msg = '313233343030';
var sig = '3082008602414e4223ee43e8cb89de3b1339ffc279e582f82c7ab0f71bbde43dbe374ac75ffbef29acdf8e70750b9a04f66fda48351de7bbfd515720b0ec5cd736f9b73bdf8645024128b5d0926a4172b349b0fd2e929487a5edb94b142df923a697e7446acdacdba0a029e43d69111174dba2fe747122709a69ce69d5285e174a01a93022fea8318ac1';
var pk = '04005c6457ec088d532f482093965ae53ccd07e556ed59e2af945cd8c7a95c1c644f8a56a8a8a3cd77392ddd861e8a924dac99c69069093bd52a52fa6c56004a074508007878d6d42e4b4dd1e9c0696cb3e19f63033c3db4e60d473259b3ebe079aaf0a986ee6177f8217a78c68b813f7e149a4e56fd9562c07fed3d895942d7d101cb83f6';

var hashMsg = hash.sha512().update(toArray(msg, 'hex')).digest();
var pubKey = ec.keyFromPublic(pk, 'hex');
console.log('Valid signature: ' + pubKey.verify(hashMsg, sig));

Remediation

Upgrade elliptic to version 6.5.7 or higher.

References

critical severity

Improper Verification of Cryptographic Signature

  • Vulnerable module: elliptic
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13 and particl-bitcore-lib@0.16.0

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 @zasmilingidiot/omp-lib@0.2.0 particl-bitcore-lib@https://github.com/kewde/particl-bitcore-lib.git elliptic@3.0.3
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de particl-bitcore-lib@0.16.0 elliptic@6.4.0
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 particl-bitcore-lib@0.16.0 elliptic@6.4.0

Overview

elliptic is a fast elliptic-curve cryptography implementation in plain javascript.

Affected versions of this package are vulnerable to Improper Verification of Cryptographic Signature due to a missing check for whether the leading bit of r and s is zero. An attacker can manipulate the ECDSA signature by exploiting this oversight.

PoC

var elliptic = require('elliptic'); // tested with version 6.5.6
var hash = require('hash.js');
var toArray = elliptic.utils.toArray;

var ec = new elliptic.ec('secp256k1');

// [tcId 6] Legacy: ASN encoding of r misses leading 0
var msg = '313233343030';
var sig = '30440220813ef79ccefa9a56f7ba805f0e478584fe5f0dd5f567bc09b5123ccbc983236502206ff18a52dcc0336f7af62400a6dd9b810732baf1ff758000d6f613a556eb31ba';
var pk = '04b838ff44e5bc177bf21189d0766082fc9d843226887fc9760371100b7ee20a6ff0c9d75bfba7b31a6bca1974496eeb56de357071955d83c4b1badaa0b21832e9';

var hashMsg = hash.sha256().update(toArray(msg, 'hex')).digest();
var pubKey = ec.keyFromPublic(pk, 'hex');
console.log('Valid signature: ' + pubKey.verify(hashMsg, sig));

Remediation

Upgrade elliptic to version 6.5.7 or higher.

References

high severity
new

Regular Expression Denial of Service (ReDoS)

  • Vulnerable module: cross-spawn
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13 and buffered-spawn@3.3.2

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 @zasmilingidiot/omp-lib@0.2.0 patch-package@6.5.1 cross-spawn@6.0.5
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de buffered-spawn@3.3.2 cross-spawn@4.0.2

Overview

Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS) due to improper input sanitization. An attacker can increase the CPU usage and crash the program by crafting a very large and well crafted string.

PoC

const { argument } = require('cross-spawn/lib/util/escape');
var str = "";
for (var i = 0; i < 1000000; i++) {
  str += "\\";
}
str += "◎";

console.log("start")
argument(str)
console.log("end")

// run `npm install cross-spawn` and `node attack.js` 
// then the program will stuck forever with high CPU usage

Details

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

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

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

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

This regular expression accomplishes the following:

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

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

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

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

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

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

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

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

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

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

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

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

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

Remediation

Upgrade cross-spawn to version 7.0.5 or higher.

References

high severity

Improper Verification of Cryptographic Signature

  • Vulnerable module: elliptic
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13 and particl-bitcore-lib@0.16.0

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 @zasmilingidiot/omp-lib@0.2.0 particl-bitcore-lib@https://github.com/kewde/particl-bitcore-lib.git elliptic@3.0.3
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de particl-bitcore-lib@0.16.0 elliptic@6.4.0
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 particl-bitcore-lib@0.16.0 elliptic@6.4.0

Overview

elliptic is a fast elliptic-curve cryptography implementation in plain javascript.

Affected versions of this package are vulnerable to Improper Verification of Cryptographic Signature due to an anomaly in the _truncateToN function. An attacker can cause legitimate transactions or communications to be incorrectly flagged as invalid by exploiting the signature verification process when the hash contains at least four leading 0 bytes and the order of the elliptic curve's base point is smaller than the hash.

PoC

var elliptic = require('elliptic'); // tested with version 6.5.7
var hash = require('hash.js');
var BN = require('bn.js');
var toArray = elliptic.utils.toArray;

var ec = new elliptic.ec('p192');
var msg = '343236343739373234';
var sig = '303502186f20676c0d04fc40ea55d5702f798355787363a91e97a7e50219009d1c8c171b2b02e7d791c204c17cea4cf556a2034288885b';
// Same public key just in different formats
var pk = '04cd35a0b18eeb8fcd87ff019780012828745f046e785deba28150de1be6cb4376523006beff30ff09b4049125ced29723';
var pkPem = '-----BEGIN PUBLIC KEY-----\nMEkwEwYHKoZIzj0CAQYIKoZIzj0DAQEDMgAEzTWgsY7rj82H/wGXgAEoKHRfBG54\nXeuigVDeG+bLQ3ZSMAa+/zD/CbQEkSXO0pcj\n-----END PUBLIC KEY-----\n';

// Create hash
var hashArray = hash.sha256().update(toArray(msg, 'hex')).digest();
// Convert array to string (just for showcase of the leading zeros)
var hashStr = Array.from(hashArray, function(byte) {
  return ('0' + (byte & 0xFF).toString(16)).slice(-2);
}).join('');
var hMsg = new BN(hashArray, 'hex');
// Hashed message contains 4 leading zeros bytes
console.log('sha256 hash(str): ' + hashStr);
// Due to using BN bitLength lib it does not calculate the bit length correctly (should be 32 since it is a sha256 hash)
console.log('Byte len of sha256 hash: ' + hMsg.byteLength());
console.log('sha256 hash(BN): ' + hMsg.toString(16));

// Due to the shift of the message to be within the order of the curve the delta computation is invalid
var pubKey = ec.keyFromPublic(toArray(pk, 'hex'));
console.log('Valid signature: ' + pubKey.verify(hashStr, sig));

// You can check that this hash should validate by consolidating openssl
const fs = require('fs');
fs.writeFile('msg.bin', new BN(msg, 16).toBuffer(), (err) => {
  if (err) throw err;
});
fs.writeFile('sig.bin', new BN(sig, 16).toBuffer(), (err) => {
  if (err) throw err;
});
fs.writeFile('cert.pem', pkPem, (err) => {
  if (err) throw err;
});

// To verify the correctness of the message signature and key one can run:
// openssl dgst -sha256 -verify cert.pem -signature sig.bin msg.bin
// Or run this python script
/*
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import ec


msg = '343236343739373234'
sig = '303502186f20676c0d04fc40ea55d5702f798355787363a91e97a7e50219009d1c8c171b2b02e7d791c204c17cea4cf556a2034288885b'
pk = '04cd35a0b18eeb8fcd87ff019780012828745f046e785deba28150de1be6cb4376523006beff30ff09b4049125ced29723'

p192 = ec.SECP192R1()
pk = ec.EllipticCurvePublicKey.from_encoded_point(p192, bytes.fromhex(pk))
pk.verify(bytes.fromhex(sig), bytes.fromhex(msg), ec.ECDSA(hashes.SHA256()))
*/

Remediation

Upgrade elliptic to version 6.6.0 or higher.

References

high severity

SQL Injection

  • Vulnerable module: knex
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 knex@0.21.19

Overview

knex is a query builder for PostgreSQL, MySQL and SQLite3

Affected versions of this package are vulnerable to SQL Injection due to missing escape of field objects, which allows ignoring the WHERE clause of a SQL query.

Note: Exploiting this vulnerability is possible when using MySQL DB.

PoC

const knex = require('knex')({
    client: 'mysql2',
    connection: {
        host: '127.0.0.1',
        user: 'root',
        password: 'supersecurepassword',
        database: 'poc',
        charset: 'utf8'
    }
})

knex.schema.hasTable('users').then((exists) => {
    if (!exists) {
        knex.schema.createTable('users', (table) => {
            table.increments('id').primary()
            table.string('name').notNullable()
            table.string('secret').notNullable()
        }).then()
        knex('users').insert({
            name: "admin",
            secret: "you should not be able to return this!"
        }).then()
        knex('users').insert({
            name: "guest",
            secret: "hello world"
        }).then()
    }
})

attackerControlled = {
    "name": "admin"
}

knex('users')
    .select()
    .where({secret: attackerControlled})
    .then((userSecret) => console.log(userSecret))

Remediation

Upgrade knex to version 2.4.0 or higher.

References

high severity

Improper Verification of Cryptographic Signature

  • Vulnerable module: elliptic
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13 and particl-bitcore-lib@0.16.0

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 @zasmilingidiot/omp-lib@0.2.0 particl-bitcore-lib@https://github.com/kewde/particl-bitcore-lib.git elliptic@3.0.3
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de particl-bitcore-lib@0.16.0 elliptic@6.4.0
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 particl-bitcore-lib@0.16.0 elliptic@6.4.0

Overview

elliptic is a fast elliptic-curve cryptography implementation in plain javascript.

Affected versions of this package are vulnerable to Improper Verification of Cryptographic Signature due to improper range validation of the S value in the verify function, allowing the usage of an invalid signature.

Note:

This vulnerability could have a security-relevant impact if an application relies on the uniqueness of a signature.

Remediation

Upgrade elliptic to version 6.5.6 or higher.

References

high severity

Prototype Pollution

  • Vulnerable module: lodash
  • Introduced through: particl-bitcore-lib@0.16.0 and @zasmilingidiot/particl-marketplace@0.3.13

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de particl-bitcore-lib@0.16.0 lodash@4.17.11
    Remediation: Open PR to patch lodash@4.17.11.
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 particl-bitcore-lib@0.16.0 lodash@4.17.11
    Remediation: Open PR to patch lodash@4.17.11.

Overview

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

Affected versions of this package are vulnerable to Prototype Pollution. The function zipObjectDeep can be tricked into adding or modifying properties of the Object prototype. These properties will be present on all objects.

PoC

const _ = require('lodash');

_.zipObjectDeep(['__proto__.z'],[123]);

console.log(z); // 123

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 Object recursive merge

  • Property 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

  1. Freeze the prototype— use Object.freeze (Object.prototype).

  2. Require schema validation of JSON input.

  3. Avoid using unsafe recursive merge functions.

  4. Consider using objects without prototypes (for example, Object.create(null)), breaking the prototype chain and preventing pollution.

  5. As a best practice use Map instead of Object.

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.20 or higher.

References

high severity

Cryptographic Issues

  • Vulnerable module: elliptic
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13 and particl-bitcore-lib@0.16.0

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 @zasmilingidiot/omp-lib@0.2.0 particl-bitcore-lib@https://github.com/kewde/particl-bitcore-lib.git elliptic@3.0.3
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de particl-bitcore-lib@0.16.0 elliptic@6.4.0
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 particl-bitcore-lib@0.16.0 elliptic@6.4.0

Overview

elliptic is a fast elliptic-curve cryptography implementation in plain javascript.

Affected versions of this package are vulnerable to Cryptographic Issues. Elliptic allows ECDSA signature malleability via variations in encoding, leading \0 bytes, or integer overflows. This could conceivably have a security-relevant impact if an application relied on a single canonical signature.

PoC

var crypto = require('crypto')
var EC = require('elliptic').ec;
var ec = new EC('secp256k1');

var obj = require("./poc_ecdsa_secp256k1_sha256_test.json");

for (let testGroup of obj.testGroups) {

    var key = ec.keyFromPublic(testGroup.key.uncompressed, 'hex');
    
    for(let test of testGroup.tests) {
     console.log("[*] Test " + test.tcId + " result: " + test.result)

     msgHash = crypto.createHash('sha256').update(Buffer.from(test.msg, 'hex')).digest();
     
     try {
      result = key.verify(msgHash, Buffer.from(test.sig, 'hex'));

     if (result == true) {
      if (test.result == "valid" || test.result == "acceptable")
       console.log("Result: PASS");
      else
       console.log("Result: FAIL")     
     }

     if (result == false) {
      if (test.result == "valid" || test.result == "acceptable")
       console.log("Result: FAIL");
      else
       console.log("Result: PASS")     
     }



     } catch (e) {
      console.log("ERROR - VERIFY: " + e)

      if (test.result == "valid" || test.result == "acceptable")
       console.log("Result: FAIL");
      else
       console.log("Result: PASS")     



     }


    }

}

Remediation

Upgrade elliptic to version 6.5.3 or higher.

References

high severity

Uncontrolled resource consumption

  • Vulnerable module: braces
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 knex@0.21.19 liftoff@3.1.0 findup-sync@3.0.0 micromatch@3.1.10 braces@2.3.2

Overview

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

Affected versions of this package are vulnerable to Uncontrolled resource consumption due improper limitation of the number of characters it can handle, through the parse function. An attacker can cause the application to allocate excessive memory and potentially crash by sending imbalanced braces as input.

PoC

const { braces } = require('micromatch');

console.log("Executing payloads...");

const maxRepeats = 10;

for (let repeats = 1; repeats <= maxRepeats; repeats += 1) {
  const payload = '{'.repeat(repeats*90000);

  console.log(`Testing with ${repeats} repeats...`);
  const startTime = Date.now();
  braces(payload);
  const endTime = Date.now();
  const executionTime = endTime - startTime;
  console.log(`Regex executed in ${executionTime / 1000}s.\n`);
} 

Remediation

Upgrade braces to version 3.0.3 or higher.

References

high severity

Prototype Pollution

  • Vulnerable module: lodash
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13 and particl-bitcore-lib@0.16.0

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 @zasmilingidiot/omp-lib@0.2.0 particl-bitcore-lib@https://github.com/kewde/particl-bitcore-lib.git lodash@3.10.1
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de particl-bitcore-lib@0.16.0 lodash@4.17.11
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 particl-bitcore-lib@0.16.0 lodash@4.17.11

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 Object recursive merge

  • Property 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

  1. Freeze the prototype— use Object.freeze (Object.prototype).

  2. Require schema validation of JSON input.

  3. Avoid using unsafe recursive merge functions.

  4. Consider using objects without prototypes (for example, Object.create(null)), breaking the prototype chain and preventing pollution.

  5. As a best practice use Map instead of Object.

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

Inefficient Regular Expression Complexity

  • Vulnerable module: micromatch
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 knex@0.21.19 liftoff@3.1.0 findup-sync@3.0.0 micromatch@3.1.10

Overview

Affected versions of this package are vulnerable to Inefficient Regular Expression Complexity due to the use of unsafe pattern configurations that allow greedy matching through the micromatch.braces() function. An attacker can cause the application to hang or slow down by passing a malicious payload that triggers extensive backtracking in regular expression processing.

Remediation

Upgrade micromatch to version 4.0.8 or higher.

References

high severity

Prototype Pollution

  • Vulnerable module: unset-value
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 knex@0.21.19 liftoff@3.1.0 findup-sync@3.0.0 micromatch@3.1.10 snapdragon@0.8.2 base@0.11.2 cache-base@1.0.1 unset-value@1.0.0
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 knex@0.21.19 liftoff@3.1.0 findup-sync@3.0.0 micromatch@3.1.10 braces@2.3.2 snapdragon@0.8.2 base@0.11.2 cache-base@1.0.1 unset-value@1.0.0
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 knex@0.21.19 liftoff@3.1.0 findup-sync@3.0.0 micromatch@3.1.10 extglob@2.0.4 snapdragon@0.8.2 base@0.11.2 cache-base@1.0.1 unset-value@1.0.0
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 knex@0.21.19 liftoff@3.1.0 findup-sync@3.0.0 micromatch@3.1.10 nanomatch@1.2.13 snapdragon@0.8.2 base@0.11.2 cache-base@1.0.1 unset-value@1.0.0
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 knex@0.21.19 liftoff@3.1.0 findup-sync@3.0.0 micromatch@3.1.10 extglob@2.0.4 expand-brackets@2.1.4 snapdragon@0.8.2 base@0.11.2 cache-base@1.0.1 unset-value@1.0.0

Overview

Affected versions of this package are vulnerable to Prototype Pollution via the unset function in index.js, because it allows access to object prototype properties.

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 Object recursive merge

  • Property 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

  1. Freeze the prototype— use Object.freeze (Object.prototype).

  2. Require schema validation of JSON input.

  3. Avoid using unsafe recursive merge functions.

  4. Consider using objects without prototypes (for example, Object.create(null)), breaking the prototype chain and preventing pollution.

  5. As a best practice use Map instead of Object.

For more information on this vulnerability type:

Arteau, Oliver. “JavaScript prototype pollution attack in NodeJS application.” GitHub, 26 May 2018

Remediation

Upgrade unset-value to version 2.0.1 or higher.

References

high severity

Prototype Pollution

  • Vulnerable module: lodash
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13 and particl-bitcore-lib@0.16.0

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 @zasmilingidiot/omp-lib@0.2.0 particl-bitcore-lib@https://github.com/kewde/particl-bitcore-lib.git lodash@3.10.1
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de particl-bitcore-lib@0.16.0 lodash@4.17.11
    Remediation: Open PR to patch lodash@4.17.11.
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 particl-bitcore-lib@0.16.0 lodash@4.17.11
    Remediation: Open PR to patch lodash@4.17.11.

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 Object recursive merge

  • Property 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

  1. Freeze the prototype— use Object.freeze (Object.prototype).

  2. Require schema validation of JSON input.

  3. Avoid using unsafe recursive merge functions.

  4. Consider using objects without prototypes (for example, Object.create(null)), breaking the prototype chain and preventing pollution.

  5. As a best practice use Map instead of Object.

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

Prototype Pollution

  • Vulnerable module: lodash
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13 and particl-bitcore-lib@0.16.0

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 @zasmilingidiot/omp-lib@0.2.0 particl-bitcore-lib@https://github.com/kewde/particl-bitcore-lib.git lodash@3.10.1
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de particl-bitcore-lib@0.16.0 lodash@4.17.11
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 particl-bitcore-lib@0.16.0 lodash@4.17.11

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 Object recursive merge

  • Property 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

  1. Freeze the prototype— use Object.freeze (Object.prototype).

  2. Require schema validation of JSON input.

  3. Avoid using unsafe recursive merge functions.

  4. Consider using objects without prototypes (for example, Object.create(null)), breaking the prototype chain and preventing pollution.

  5. As a best practice use Map instead of Object.

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

Prototype Pollution

  • Vulnerable module: lodash
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 @zasmilingidiot/omp-lib@0.2.0 particl-bitcore-lib@https://github.com/kewde/particl-bitcore-lib.git lodash@3.10.1

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 Object recursive merge

  • Property 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

  1. Freeze the prototype— use Object.freeze (Object.prototype).

  2. Require schema validation of JSON input.

  3. Avoid using unsafe recursive merge functions.

  4. Consider using objects without prototypes (for example, Object.create(null)), breaking the prototype chain and preventing pollution.

  5. As a best practice use Map instead of Object.

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

Use of Weak Hash

  • Vulnerable module: crypto-js
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 crypto-js@3.3.0

Overview

crypto-js is a library of crypto standards.

Affected versions of this package are vulnerable to Use of Weak Hash due to inadequate security settings in the PBKDF2 configuration, which uses insecure SHA1 and has a low iteration count of 1. These insecure settings allow attackers to perform brute-force attacks when PBKDF2 is used with the default parameters.

No information is directly exposed when a hash is generated, regardless of whether the PBKDF2 function is in the vulnerable configuration or not. However, it may be possible to recover the original data, more or less easily depending on the configured parameters, using a brute force attack. This is a low impact on the confidentiality of the protected data, which are in a different scope than the vulnerable package.

The attacker similarly may be able to modify some data which is meant to be protected by the vulnerable package - most commonly when it is used for signature verification. This would require a subsequent exploitation, such as forcing a hash collision via length extension attack. The integrity of the data is therefore compromised, but the quantity and targeting of that data is not fully in the attacker's control, yielding a low integrity impact.

Notes

  • This vulnerability is related to https://security.snyk.io/vuln/SNYK-JS-CRYPTOES-6032390 in crypto-es.

  • According to the crypto-js maintainer: "Active development of CryptoJS has been discontinued. This library is no longer maintained." It is recommended to use the Node.js native crypto module.

Workaround

This vulnerability can be avoided by setting PBKDF2 to use SHA-256 instead of SHA-1 and increasing the number of iterations to a sufficiently high value depending on the intended use. See, for example, the OWASP PBKDF2 Cheat Sheet for recommendations.

Changelog:

2023-10-24 - Initial publication

2023-10-25 - Added fixed version, updated references, separated crypto-es, description changes, updated CVSS, added CVE ID

2023-11-07 - Re-assessed CVSS following a CVSS publication on NVD. No changes made to CVSS.

2024-01-11 - Revised CVSS and description after additional deeper investigation, to reflect the details of the severity assessment

Remediation

Upgrade crypto-js to version 4.2.0 or higher.

References

high severity

Code Injection

  • Vulnerable module: lodash
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13 and particl-bitcore-lib@0.16.0

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 @zasmilingidiot/omp-lib@0.2.0 particl-bitcore-lib@https://github.com/kewde/particl-bitcore-lib.git lodash@3.10.1
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de particl-bitcore-lib@0.16.0 lodash@4.17.11
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 particl-bitcore-lib@0.16.0 lodash@4.17.11

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

GPL-2.0 license

  • Module: @zasmilingidiot/particl-marketplace
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13

GPL-2.0 license

medium severity

Cryptographic Issues

  • Vulnerable module: elliptic
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13 and particl-bitcore-lib@0.16.0

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 @zasmilingidiot/omp-lib@0.2.0 particl-bitcore-lib@https://github.com/kewde/particl-bitcore-lib.git elliptic@3.0.3
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de particl-bitcore-lib@0.16.0 elliptic@6.4.0
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 particl-bitcore-lib@0.16.0 elliptic@6.4.0

Overview

elliptic is a fast elliptic-curve cryptography implementation in plain javascript.

Affected versions of this package are vulnerable to Cryptographic Issues via the secp256k1 implementation in elliptic/ec/key.js. There is no check to confirm that the public key point passed into the derive function actually exists on the secp256k1 curve. This results in the potential for the private key used in this implementation to be revealed after a number of ECDH operations are performed.

Remediation

Upgrade elliptic to version 6.5.4 or higher.

References

medium severity

Use of a Broken or Risky Cryptographic Algorithm

  • Vulnerable module: jsonwebtoken
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 jsonwebtoken@8.5.1

Overview

jsonwebtoken is a JSON Web Token implementation (symmetric and asymmetric)

Affected versions of this package are vulnerable to Use of a Broken or Risky Cryptographic Algorithm such that the library can be misconfigured to use legacy, insecure key types for signature verification. For example, DSA keys could be used with the RS256 algorithm.

Exploitability

Users are affected when using an algorithm and a key type other than the combinations mentioned below:

EC: ES256, ES384, ES512

RSA: RS256, RS384, RS512, PS256, PS384, PS512

RSA-PSS: PS256, PS384, PS512

And for Elliptic Curve algorithms:

ES256: prime256v1

ES384: secp384r1

ES512: secp521r1

Workaround

Users who are unable to upgrade to the fixed version can use the allowInvalidAsymmetricKeyTypes option to true in the sign() and verify() functions to continue usage of invalid key type/algorithm combination in 9.0.0 for legacy compatibility.

Remediation

Upgrade jsonwebtoken to version 9.0.0 or higher.

References

medium severity

Improper Restriction of Security Token Assignment

  • Vulnerable module: jsonwebtoken
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 jsonwebtoken@8.5.1

Overview

jsonwebtoken is a JSON Web Token implementation (symmetric and asymmetric)

Affected versions of this package are vulnerable to Improper Restriction of Security Token Assignment via the secretOrPublicKey argument due to misconfigurations of the key retrieval function jwt.verify(). Exploiting this vulnerability might result in incorrect verification of forged tokens when tokens signed with an asymmetric public key could be verified with a symmetric HS256 algorithm.

Note: This vulnerability affects your application if it supports the usage of both symmetric and asymmetric keys in jwt.verify() implementation with the same key retrieval function.

Remediation

Upgrade jsonwebtoken to version 9.0.0 or higher.

References

medium severity

Server-side Request Forgery (SSRF)

  • Vulnerable module: request
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 request@2.88.2
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 web-request@1.0.7 request@2.88.2
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 @zasmilingidiot/omp-lib@0.2.0 web-request@1.0.7 request@2.88.2

Overview

request is a simplified http request client.

Affected versions of this package are vulnerable to Server-side Request Forgery (SSRF) due to insufficient checks in the lib/redirect.js file by allowing insecure redirects in the default configuration, via an attacker-controller server that does a cross-protocol redirect (HTTP to HTTPS, or HTTPS to HTTP).

NOTE: request package has been deprecated, so a fix is not expected. See https://github.com/request/request/issues/3142.

Remediation

A fix was pushed into the master branch but not yet published.

References

medium severity

Prototype Pollution

  • Vulnerable module: tough-cookie
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 request@2.88.2 tough-cookie@2.5.0
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 request-promise@4.2.6 tough-cookie@2.5.0
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 web-request@1.0.7 request@2.88.2 tough-cookie@2.5.0
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 @zasmilingidiot/omp-lib@0.2.0 web-request@1.0.7 request@2.88.2 tough-cookie@2.5.0

Overview

tough-cookie is a RFC6265 Cookies and CookieJar module for Node.js.

Affected versions of this package are vulnerable to Prototype Pollution due to improper handling of Cookies when using CookieJar in rejectPublicSuffixes=false mode. Due to an issue with the manner in which the objects are initialized, an attacker can expose or modify a limited amount of property information on those objects. There is no impact to availability.

PoC

// PoC.js
async function main(){
var tough = require("tough-cookie");
var cookiejar = new tough.CookieJar(undefined,{rejectPublicSuffixes:false});
// Exploit cookie
await cookiejar.setCookie(
  "Slonser=polluted; Domain=__proto__; Path=/notauth",
  "https://__proto__/admin"
);
// normal cookie
var cookie = await cookiejar.setCookie(
  "Auth=Lol; Domain=google.com; Path=/notauth",
  "https://google.com/"
);

//Exploit cookie
var a = {};
console.log(a["/notauth"]["Slonser"])
}
main();

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 Object recursive merge

  • Property 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

  1. Freeze the prototype— use Object.freeze (Object.prototype).

  2. Require schema validation of JSON input.

  3. Avoid using unsafe recursive merge functions.

  4. Consider using objects without prototypes (for example, Object.create(null)), breaking the prototype chain and preventing pollution.

  5. As a best practice use Map instead of Object.

For more information on this vulnerability type:

Arteau, Oliver. “JavaScript prototype pollution attack in NodeJS application.” GitHub, 26 May 2018

Remediation

Upgrade tough-cookie to version 4.1.3 or higher.

References

medium severity

Improper Authentication

  • Vulnerable module: jsonwebtoken
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 jsonwebtoken@8.5.1

Overview

jsonwebtoken is a JSON Web Token implementation (symmetric and asymmetric)

Affected versions of this package are vulnerable to Improper Authentication such that the lack of algorithm definition in the jwt.verify() function can lead to signature validation bypass due to defaulting to the none algorithm for signature verification.

Exploitability

Users are affected only if all of the following conditions are true for the jwt.verify() function:

  1. A token with no signature is received.

  2. No algorithms are specified.

  3. A falsy (e.g., null, false, undefined) secret or key is passed.

Remediation

Upgrade jsonwebtoken to version 9.0.0 or higher.

References

medium severity

  • Vulnerable module: cookie
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 socket.io@2.5.1 engine.io@3.6.2 cookie@0.4.2

Overview

Affected versions of this package are vulnerable to Cross-site Scripting (XSS) via the cookie name, path, or domain, which can be used to set unexpected values to other cookie fields.

Workaround

Users who are not able to upgrade to the fixed version should avoid passing untrusted or arbitrary values for the cookie fields and ensure they are set by the application instead of user input.

Details

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

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

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

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

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

Types of attacks

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

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

Affected environments

The following environments are susceptible to an XSS attack:

  • Web servers
  • Application servers
  • Web application environments

How to prevent

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

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

Remediation

Upgrade cookie to version 0.7.0 or higher.

References

medium severity

Prototype Pollution

  • Vulnerable module: lodash
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 @zasmilingidiot/omp-lib@0.2.0 particl-bitcore-lib@https://github.com/kewde/particl-bitcore-lib.git lodash@3.10.1
    Remediation: Open PR to patch lodash@3.10.1.

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 Object recursive merge

  • Property 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

  1. Freeze the prototype— use Object.freeze (Object.prototype).

  2. Require schema validation of JSON input.

  3. Avoid using unsafe recursive merge functions.

  4. Consider using objects without prototypes (for example, Object.create(null)), breaking the prototype chain and preventing pollution.

  5. As a best practice use Map instead of Object.

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

Missing Release of Resource after Effective Lifetime

  • Vulnerable module: inflight
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13, del@5.1.0 and others

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 glob@7.2.3 inflight@1.0.6
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de del@5.1.0 globby@10.0.2 glob@7.2.3 inflight@1.0.6
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de del@5.1.0 rimraf@3.0.2 glob@7.2.3 inflight@1.0.6
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 del@3.0.0 rimraf@2.7.1 glob@7.2.3 inflight@1.0.6
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 fstream@1.0.12 rimraf@2.7.1 glob@7.2.3 inflight@1.0.6
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de node-unzip-2@0.2.8 fstream@1.0.12 rimraf@2.7.1 glob@7.2.3 inflight@1.0.6
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 del@3.0.0 globby@6.1.0 glob@7.2.3 inflight@1.0.6
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 @zasmilingidiot/omp-lib@0.2.0 patch-package@6.5.1 rimraf@2.7.1 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.

References

medium severity

Timing Attack

  • Vulnerable module: elliptic
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13 and particl-bitcore-lib@0.16.0

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 @zasmilingidiot/omp-lib@0.2.0 particl-bitcore-lib@https://github.com/kewde/particl-bitcore-lib.git elliptic@3.0.3
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de particl-bitcore-lib@0.16.0 elliptic@6.4.0
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 particl-bitcore-lib@0.16.0 elliptic@6.4.0

Overview

elliptic is a fast elliptic-curve cryptography implementation in plain javascript.

Affected versions of this package are vulnerable to Timing Attack. Practical recovery of the long-term private key generated by the library is possible under certain conditions. Leakage of bit-length of a scalar during scalar multiplication is possible on an elliptic curve which might allow practical recovery of the long-term private key.

Remediation

Upgrade elliptic to version 6.5.2 or higher.

References

medium severity

Regular Expression Denial of Service (ReDoS)

  • Vulnerable module: lodash
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13 and particl-bitcore-lib@0.16.0

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 @zasmilingidiot/omp-lib@0.2.0 particl-bitcore-lib@https://github.com/kewde/particl-bitcore-lib.git lodash@3.10.1
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de particl-bitcore-lib@0.16.0 lodash@4.17.11
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 particl-bitcore-lib@0.16.0 lodash@4.17.11

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:

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

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

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

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

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

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

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

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

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

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

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

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

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

Remediation

Upgrade lodash to version 4.17.21 or higher.

References

medium severity

Regular Expression Denial of Service (ReDoS)

  • Vulnerable module: lodash
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 @zasmilingidiot/omp-lib@0.2.0 particl-bitcore-lib@https://github.com/kewde/particl-bitcore-lib.git lodash@3.10.1

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:

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

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

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

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

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

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

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

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

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

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

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

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

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

Remediation

Upgrade lodash to version 4.17.11 or higher.

References

medium severity

Exposure of Sensitive Information to an Unauthorized Actor

  • Vulnerable module: phin
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 jimp@0.16.13 @jimp/custom@0.16.13 @jimp/core@0.16.13 phin@2.9.3

Overview

phin is a The ultra-lightweight Node.js HTTP client

Affected versions of this package are vulnerable to Exposure of Sensitive Information to an Unauthorized Actor due to the handling of HTTP headers during redirects when followRedirects is enabled. An attacker can potentially intercept sensitive information by exploiting how headers are included in outgoing requests after a redirect.

Remediation

Upgrade phin to version 3.7.1 or higher.

References

medium severity

LGPL-2.1 license

  • Module: jschardet
  • Introduced through: autodetect-decoder-stream@1.0.3

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de autodetect-decoder-stream@1.0.3 jschardet@1.6.0

LGPL-2.1 license

low severity

Improper Input Validation

  • Vulnerable module: class-validator
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 class-validator@0.13.2

Overview

class-validator is a decorator-based property validation for classes.

Affected versions of this package are vulnerable to Improper Input Validation via bypassing the input validation in validate(), as certain internal attributes can be overwritten via a conflicting name.

NOTE: There is an optional forbidUnknownValues parameter that can be used to reduce the risk of this bypass.

Details

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

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

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

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

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

Types of attacks

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

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

Affected environments

The following environments are susceptible to an XSS attack:

  • Web servers
  • Application servers
  • Web application environments

How to prevent

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

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

Remediation

Upgrade class-validator to version 0.14.0 or higher.

References

low severity

Regular Expression Denial of Service (ReDoS)

  • Vulnerable module: debug
  • Introduced through: @zasmilingidiot/particl-marketplace@0.3.13

Detailed paths

  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 socket.io@2.5.1 debug@4.1.1
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 socket.io@2.5.1 engine.io@3.6.2 debug@4.1.1
  • Introduced through: particl-desktop-testing@particl/particl-desktop#671fda81590363bf260c7ee858afb43c7a2bc0de @zasmilingidiot/particl-marketplace@0.3.13 socket.io@2.5.1 socket.io-parser@3.4.3 debug@4.1.1

Overview

debug is a small debugging utility.

Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS) in the function useColors via manipulation of the str argument. The vulnerability can cause a very low impact of about 2 seconds of matching time for data 50k characters long.

Note: CVE-2017-20165 is a duplicate of this vulnerability.

PoC

Use the following regex in the %o formatter.

/\s*\n\s*/

Details

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

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

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

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

This regular expression accomplishes the following:

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

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

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

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

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

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

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

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

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

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

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

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

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

Remediation

Upgrade debug to version 2.6.9, 3.1.0, 3.2.7, 4.3.1 or higher.

References