electron-prebuilt-compile@8.2.0

Vulnerabilities

42 via 48 paths

Dependencies

582

Source

npm

Find, fix and prevent vulnerabilities in your code.

Severity
  • 32
  • 9
  • 1
Status
  • 42
  • 0
  • 0

high severity

Prototype Pollution

  • Vulnerable module: ajv
  • Introduced through: electron-compilers@5.9.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron-compilers@5.9.0 less@2.7.3 request@2.81.0 har-validator@4.2.1 ajv@4.11.8

Overview

ajv is an Another JSON Schema Validator

Affected versions of this package are vulnerable to Prototype Pollution. A carefully crafted JSON schema could be provided that allows execution of other code by prototype pollution. (While untrusted schemas are recommended against, the worst case of an untrusted schema should be a denial of service, not execution of code.)

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

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 ajv to version 6.12.3 or higher.

References

high severity

Sandbox Bypass

  • Vulnerable module: constantinople
  • Introduced through: electron-compilers@5.9.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron-compilers@5.9.0 jade@1.11.0 constantinople@3.0.2

Overview

constantinople determines whether a JavaScript expression evaluates to a constant (using acorn).

Affected versions of this package are vulnerable to a sandbox bypass which can lead to arbitrary code execution.

Remediation

Upgrade constantinople to version 3.1.1 or higher.

References

high severity

Buffer Overflow

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Buffer Overflow in SCTP.

Remediation

Upgrade electron to version 6.1.12, 7.3.0, 8.3.0 or higher.

References

high severity

Heap Overflow

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Heap Overflow. A Heap buffer overflow exists in the media component of Google Chrome, which also affects chromium.

Remediation

Upgrade electron to version 6.1.10, 7.2.2, 8.2.1 or higher.

References

high severity

Heap-based Buffer Overflow

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Heap-based Buffer Overflow in Freetype.

Remediation

Upgrade electron to version 8.5.3, 9.3.3, 10.1.5 or higher.

References

high severity

Improper Access Control

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Improper Access Control. It has an inappropriate implementation in V8.

Remediation

Upgrade electron to version 6.1.10, 7.2.2, 8.2.1 or higher.

References

high severity

Improper Validation

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Improper Validation in URL formatting.

Remediation

Upgrade electron to version 6.1.12, 7.3.0, 8.3.0 or higher.

References

high severity

Out-of-bounds Write

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Out-of-bounds Write in PDFium.

Remediation

Upgrade electron to version 7.3.0, 8.3.0 or higher.

References

high severity

Privilege Escalation

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Privilege Escalation. This is a context isolation bypass, meaning that code running in the main world context in the renderer can reach into the isolated Electron context and perform privileged actions.

##Note: Only apps using contextIsolation are affected.

Remediation

Upgrade electron to version 7.2.4, 8.2.4 or higher.

References

high severity

Privilege Escalation

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Privilege Escalation. This is a context isolation bypass, meaning that code running in the main world context in the renderer can reach into the isolated Electron context and perform privileged actions.

##Note: Only apps using both contextIsolation and contextBridge are affected.

Remediation

Upgrade electron to version 7.2.4, 8.2.4 or higher.

References

high severity

Privilege Escalation

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Privilege Escalation. This is a context isolation bypass, meaning that code running in the main world context in the renderer can reach into the isolated Electron context and perform privileged actions.

##Note: Only apps using contextIsolation are affected.

Remediation

Upgrade electron to version 6.1.11, 7.2.4, 8.2.4 or higher.

References

high severity

Site Isolation Bypass

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Site Isolation Bypass. parent_execution_origin_ is provided from parent's RenderFrameHostImpl::last_committed_origin_ that is set during navigation commit. Worker creation IPC from the renderer to browser could race with navigation commit, and could see the wrong last committed origin.

Remediation

Upgrade electron to version 7.2.2, 8.2.1 or higher.

References

high severity

Type Confusion

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Type Confusion via Blink.

Remediation

Upgrade electron to version 6.1.12, 7.3.0, 8.3.0 or higher.

References

high severity

new

Use After Free

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Use After Free via the site isolation.

Remediation

Upgrade electron to version 8.5.4, 10.1.6, 11.0.1 or higher.

References

high severity

Use After Free

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Use After Free. Multiple user after free vulnerabilities exists in the WebAudio component of chromium.

Remediation

Upgrade electron to version 6.1.10, 7.2.2, 8.2.1 or higher.

References

high severity

Use After Free

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Use After Free via the audio component.

Remediation

Upgrade electron to version 7.2.2, 8.2.2, 9.0.0-beta.10 or higher.

References

high severity

Use After Free

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Use After Free. It allows a remote attacker to potentially exploit heap corruption via a crafted HTML page.

Remediation

Upgrade electron to version 7.2.2, 8.2.1 or higher.

References

high severity

Use After Free

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Use After Free. It allowed a remote attacker to potentially exploit heap corruption via a crafted HTML page.

Remediation

Upgrade electron to version 6.1.10, 7.2.2, 8.2.1 or higher.

References

high severity

Use After Free

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Use After Free via the audio component. It allowed a remote attacker to potentially exploit heap corruption via a crafted HTML page.

Remediation

Upgrade electron to version 6.1.10, 7.2.2, 8.2.1 or higher.

References

high severity

Use After Free

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Use After Free via the audio component.

Remediation

Upgrade electron to version 8.2.1, 7.2.2 or higher.

References

high severity

Use After Free

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Use After Free. Initialize() could potentially run twice in MojoVideoEncodeAcceleratorService.

Remediation

Upgrade electron to version 6.1.10, 7.2.2, 8.2.1 or higher.

References

high severity

Use After Free

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Use After Free in storage.

Remediation

Upgrade electron to version 6.1.12, 7.3.0, 8.3.0 or higher.

References

high severity

Use After Free

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Use After Free in task scheduling.

Remediation

Upgrade electron to version 6.1.12, 7.3.0, 8.3.0 or higher.

References

high severity

Use After Free

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Use After Free in payments

Remediation

Upgrade electron to version 6.1.12, 7.3.0, 8.3.0 or higher.

References

high severity

Use After Free

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Use After Free in ANGLE.

Remediation

Upgrade electron to version 6.1.12, 7.3.0, 8.3.0 or higher.

References

high severity

Use After Free

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Use After Free in WebRTC.

Remediation

Upgrade electron to version 8.3.1 or higher.

References

high severity

Use After Free

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Use After Free via the extensions component.

Remediation

Upgrade electron to version 8.4.0 or higher.

References

high severity

Use After Free

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Use After Free in SCTP.

Remediation

Upgrade electron to version 7.3.3, 8.5.1, 9.2.1 or higher.

References

high severity

Use After Free

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Use After Free in WebUSB.

Remediation

Upgrade electron to version 7.3.3, 8.5.1, 9.2.2 or higher.

References

high severity

Arbitrary Code Execution

  • Vulnerable module: js-yaml
  • Introduced through: electron-compilers@5.9.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron-compilers@5.9.0 @paulcbetts/vueify@9.4.3 cssnano@3.10.0 postcss-svgo@2.1.6 svgo@0.7.2 js-yaml@3.7.0

Overview

js-yaml is a human-friendly data serialization language.

Affected versions of this package are vulnerable to Arbitrary Code Execution. When an object with an executable toString() property used as a map key, it will execute that function. This happens only for load(), which should not be used with untrusted data anyway. safeLoad() is not affected because it can't parse functions.

Remediation

Upgrade js-yaml to version 3.13.1 or higher.

References

high severity

Improper minification of non-boolean comparisons

  • Vulnerable module: uglify-js
  • Introduced through: electron-compilers@5.9.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron-compilers@5.9.0 jade@1.11.0 transformers@2.1.0 uglify-js@2.2.5
    Remediation: Open PR to patch uglify-js@2.2.5.

Overview

uglify-js is a JavaScript parser, minifier, compressor and beautifier toolkit.

Tom MacWright discovered that UglifyJS versions 2.4.23 and earlier are affected by a vulnerability which allows a specially crafted Javascript file to have altered functionality after minification. This bug was demonstrated by Yan to allow potentially malicious code to be hidden within secure code, activated by minification.

Details

In Boolean algebra, DeMorgan's laws describe the relationships between conjunctions (&&), disjunctions (||) and negations (!). In Javascript form, they state that:

 !(a && b) === (!a) || (!b)
 !(a || b) === (!a) && (!b)

The law does not hold true when one of the values is not a boolean however.

Vulnerable versions of UglifyJS do not account for this restriction, and erroneously apply the laws to a statement if it can be reduced in length by it.

Consider this authentication function:

function isTokenValid(user) {
    var timeLeft =
        !!config && // config object exists
        !!user.token && // user object has a token
        !user.token.invalidated && // token is not explicitly invalidated
        !config.uninitialized && // config is initialized
        !config.ignoreTimestamps && // don't ignore timestamps
        getTimeLeft(user.token.expiry); // > 0 if expiration is in the future

    // The token must not be expired
    return timeLeft > 0;
}

function getTimeLeft(expiry) {
  return expiry - getSystemTime();
}

When minified with a vulnerable version of UglifyJS, it will produce the following insecure output, where a token will never expire:

( Formatted for readability )

function isTokenValid(user) {
    var timeLeft = !(                       // negation
        !config                             // config object does not exist
        || !user.token                      // user object does not have a token
        || user.token.invalidated           // token is explicitly invalidated
        || config.uninitialized             // config isn't initialized
        || config.ignoreTimestamps          // ignore timestamps
        || !getTimeLeft(user.token.expiry)  // > 0 if expiration is in the future
    );
    return timeLeft > 0
}

function getTimeLeft(expiry) {
    return expiry - getSystemTime()
}

Remediation

Upgrade UglifyJS to version 2.4.24 or higher.

References

high severity

new

Prototype Pollution

  • Vulnerable module: y18n
  • Introduced through: yargs@6.6.0 and electron-compile@6.4.4

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 yargs@6.6.0 y18n@3.2.1
    Remediation: Upgrade to yargs@16.0.0.
  • Introduced through: electron-prebuilt-compile@8.2.0 electron-compile@6.4.4 yargs@4.8.1 y18n@3.2.1

Overview

y18n is a the bare-bones internationalization library used by yargs

Affected versions of this package are vulnerable to Prototype Pollution. PoC by po6ix:

const y18n = require('y18n')();

y18n.setLocale('__proto__');
y18n.updateLocale({polluted: true});

console.log(polluted); // 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

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 y18n to version 5.0.5 or higher.

References

medium severity

Arbitrary File Read

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Arbitrary File Read. It allows arbitrary local file read by defining unsafe window options on a child window opened via window.open.

Remediation

Upgrade electron to version 7.2.4, 8.2.4 or higher.

References

medium severity

Improper Access Control

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Improper Access Control. Apps using both contextIsolation and sandbox: true or nativeWindowOpen: true are affected. Code running in the main world context in the renderer can reach into the isolated Electron context and perform privileged actions.

Remediation

Upgrade electron to version 8.5.2, 9.3.1, 10.1.2, 11.0.0-beta.6 or higher.

References

medium severity

Improper Restriction of Rendered UI Layers or Frames

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Improper Restriction of Rendered UI Layers or Frames. The will-navigate event that apps use to prevent navigations to unexpected destinations can be bypassed when a sub-frame performs a top-frame navigation across sites.

Remediation

Upgrade electron to version 8.5.1, 9.3.0, 10.0.1, 11.0.0-beta.1 or higher.

References

medium severity

Use After Free

  • Vulnerable module: electron
  • Introduced through: electron@8.2.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron@8.2.0

Overview

electron is a framework which lets you write cross-platform desktop applications using JavaScript, HTML and CSS.

Affected versions of this package are vulnerable to Use After Free. The rendering_orphan_handlers_ and deletable_orphan_handlers_ handlers can hold references to the context after BaseAudioContext is destroyed.

Remediation

Upgrade electron to version 6.1.10, 7.2.2, 8.2.1 or higher.

References

medium severity

Prototype Pollution

  • Vulnerable module: hoek
  • Introduced through: electron-compilers@5.9.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron-compilers@5.9.0 less@2.7.3 request@2.81.0 hawk@3.1.3 hoek@2.16.3
    Remediation: Open PR to patch hoek@2.16.3.
  • Introduced through: electron-prebuilt-compile@8.2.0 electron-compilers@5.9.0 less@2.7.3 request@2.81.0 hawk@3.1.3 boom@2.10.1 hoek@2.16.3
    Remediation: Open PR to patch hoek@2.16.3.
  • Introduced through: electron-prebuilt-compile@8.2.0 electron-compilers@5.9.0 less@2.7.3 request@2.81.0 hawk@3.1.3 sntp@1.0.9 hoek@2.16.3
    Remediation: Open PR to patch hoek@2.16.3.
  • Introduced through: electron-prebuilt-compile@8.2.0 electron-compilers@5.9.0 less@2.7.3 request@2.81.0 hawk@3.1.3 cryptiles@2.0.5 boom@2.10.1 hoek@2.16.3
    Remediation: Open PR to patch hoek@2.16.3.

Overview

hoek is an Utility methods for the hapi ecosystem.

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

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

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 hoek to version 4.2.1, 5.0.3 or higher.

References

medium severity

Denial of Service (DoS)

  • Vulnerable module: js-yaml
  • Introduced through: electron-compilers@5.9.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron-compilers@5.9.0 @paulcbetts/vueify@9.4.3 cssnano@3.10.0 postcss-svgo@2.1.6 svgo@0.7.2 js-yaml@3.7.0

Overview

js-yaml is a human-friendly data serialization language.

Affected versions of this package are vulnerable to Denial of Service (DoS). The parsing of a specially crafted YAML file may exhaust the system resources.

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 js-yaml to version 3.13.0 or higher.

References

medium severity

Prototype Pollution

  • Vulnerable module: minimist
  • Introduced through: electron-compilers@5.9.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron-compilers@5.9.0 detective-sass@2.0.1 gonzales-pe@3.4.7 minimist@1.1.3
  • Introduced through: electron-prebuilt-compile@8.2.0 electron-compilers@5.9.0 detective-scss@1.0.1 gonzales-pe@3.4.7 minimist@1.1.3

Overview

minimist is a parse argument options module.

Affected versions of this package are vulnerable to Prototype Pollution. The library could be tricked into adding or modifying properties of Object.prototype using a constructor or __proto__ payload.

PoC by Snyk

require('minimist')('--__proto__.injected0 value0'.split(' '));
console.log(({}).injected0 === 'value0'); // true

require('minimist')('--constructor.prototype.injected1 value1'.split(' '));
console.log(({}).injected1 === 'value1'); // true

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 minimist to version 0.2.1, 1.2.3 or higher.

References

medium severity

Regular Expression Denial of Service (ReDoS)

  • Vulnerable module: uglify-js
  • Introduced through: electron-compilers@5.9.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron-compilers@5.9.0 jade@1.11.0 transformers@2.1.0 uglify-js@2.2.5
    Remediation: Open PR to patch uglify-js@2.2.5.

Overview

The parse() function in the uglify-js package prior to version 2.6.0 is vulnerable to regular expression denial of service (ReDoS) attacks when long inputs of certain patterns are processed.

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 to version 2.6.0 or greater. If a direct dependency update is not possible, use snyk wizard to patch this vulnerability.

References

medium severity

Prototype Pollution

  • Vulnerable module: yargs-parser
  • Introduced through: electron-compile@6.4.4 and yargs@6.6.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron-compile@6.4.4 yargs@4.8.1 yargs-parser@2.4.1
  • Introduced through: electron-prebuilt-compile@8.2.0 yargs@6.6.0 yargs-parser@4.2.1
    Remediation: Upgrade to yargs@13.1.0.

Overview

yargs-parser is a mighty option parser used by yargs.

Affected versions of this package are vulnerable to Prototype Pollution. The library could be tricked into adding or modifying properties of Object.prototype using a __proto__ payload.

Our research team checked several attack vectors to verify this vulnerability:

  1. It could be used for privilege escalation.
  2. The library could be used to parse user input received from different sources:
    • terminal emulators
    • system calls from other code bases
    • CLI RPC servers

PoC by Snyk

const parser = require("yargs-parser");
console.log(parser('--foo.__proto__.bar baz'));
console.log(({}).bar);

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

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 yargs-parser to version 5.0.0-security.0, 13.1.2, 15.0.1, 18.1.1 or higher.

References

low severity

Regular Expression Denial of Service (ReDoS)

  • Vulnerable module: clean-css
  • Introduced through: electron-compilers@5.9.0

Detailed paths

  • Introduced through: electron-prebuilt-compile@8.2.0 electron-compilers@5.9.0 jade@1.11.0 clean-css@3.4.28

Overview

clean-css is a fast and efficient CSS optimizer for Node.js platform and any modern browser.

Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS). attacks. This can cause an impact of about 10 seconds matching time for data 70k characters long.

Disclosure Timeline

  • Feb 15th, 2018 - Initial Disclosure to package owner
  • Feb 20th, 2018 - Initial Response from package owner
  • Mar 6th, 2018 - Fix issued
  • Mar 7th, 2018 - Vulnerability published

Details

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

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

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

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

This regular expression accomplishes the following:

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

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

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

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

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

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

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

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

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

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

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

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

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

Remediation

Upgrade clean-css to version 4.1.11 or higher.

References