CVE-2021-21277: Angular expressions Remote Code Execution Vulnerability

HIGH
Advisory Identifier: GHSA-j6px-jwvv-vpwq
CVSS 8.8
CWE-94 CWE-74
Published
Advisory Summary

CVE-2021-21277 is a HIGH (CVSS 8.8) remote code execution vulnerability (CWE-94: Improper Control of Generation of Code ('Code Injection')) affecting Angular expressions libraries in the npm ecosystem. The issue involves angular expressions - remote code execution. Remediation is available by upgrading affected packages to version 1.1.2.

CVE-2021-21277 at a Glance

CVE Identifier CVE-2021-21277
GHSA Identifier GHSA-j6px-jwvv-vpwq
Severity HIGH
CVSS v3.1 Base Score 8.8
CWE Classification CWE-94: Improper Control of Generation of Code ('Code Injection')
Affected Product Angular expressions
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 8.8

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required Low (PR:L)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2021-21277

To remediate this vulnerability, upgrade all affected Angular expressions dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

angular-expressions fixed: 1.1.2
npm install angular-expressions@1.1.2
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls angular-expressions

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2021-21277, inspect your project dependencies using npm:

npm ls angular-expressions

Analyze the terminal output to locate any version of Angular expressions in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.1.2), your application is affected.

Note: The npm ls angular-expressions command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-94: Improper Control of Generation of Code ('Code Injection'), where the product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. In Angular expressions, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Impact The vulnerability, reported by GoSecure Inc, allows Remote Code Execution, if you call `expressions.compile(userControlledInput)` where `userControlledInput` is text that comes from user input. This time, the security of the package could be bypassed by using a more complex payload, using a `.constructor.constructor` technique. * If running angular-expressions in the browser, an attacker could run any browser script when the application code calls expressions.compile(userControlledInput). * If running angular-expressions on the server, an attacker could run any Javascript expression, thus gaining Remote Code Execution. ### Patches Users should upgrade to version 1.1.2 of angular-expressions ### Workarounds A temporary workaround might be either to : * disable user-controlled input that will be fed into angular-expressions in your application OR * allow only following characters in the userControlledInput : ```js if (/^[|a-zA-Z.0-9 :"'+-?]+$/.test(userControlledInput)) { var result = expressions.compile(userControlledInput); } else { result = undefined; } ``` ### References [Removal of angular-expression sandbox](http://blog.angularjs.org/2016/09/angular-16-expression-sandbox-removal.html) ### For more information If you have any questions or comments about this advisory: * Open an issue in [angular-expressions](https://github.com/peerigon/angular-expressions/issues) * [Email us](mailto:contact@javascript-ninja.fr) ### Credits The issue was reported by Maxime Nadeau from GoSecure, Inc.

CVE-2021-21277 Affected Angular expressions Versions

1 component(s)
Fixed Versions:
1.1.2
Product / Package Ecosystem Affected Versions Fixed Version
angular-expressions
npm
< 1.1.2
1.1.2

References

Frequently Asked Questions

What is CVE-2021-21277?
CVE-2021-21277 is a security vulnerability in Angular expressions involving Angular Expressions - Remote Code Execution under CWE-94: Improper Control of Generation of Code ('Code Injection').
Which Angular expressions versions are affected?
Affected versions include releases prior to 1.1.2 across affected packages: angular-expressions.
What version fixes CVE-2021-21277?
Upgrading to 1.1.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is angular-expressions affected?
Yes, angular-expressions is affected in releases prior to 1.1.2. Upgrade your dependency to 1.1.2 or later.
What is the CVSS score of CVE-2021-21277?
CVE-2021-21277 has a CVSS v3.1 base score of 8.8 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2021-21277?
CVE-2021-21277 is classified under CWE-94: Improper Control of Generation of Code ('Code Injection') (The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.).
How can I check npm dependencies for CVE-2021-21277?
Run the dependency tree command: 'npm ls angular-expressions'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-j6px-jwvv-vpwq",
  "modified" : "2022-10-20T13:26:13Z",
  "published" : "2021-02-01T15:01:26Z",
  "aliases" : [ "CVE-2021-21277" ],
  "summary" : "Angular Expressions - Remote Code Execution",
  "details" : "### Impact\n\nThe vulnerability, reported by GoSecure Inc, allows Remote Code Execution, if you call `expressions.compile(userControlledInput)` where `userControlledInput` is text that comes from user input.\n\nThis time, the security of the package could be bypassed by using a more complex payload, using a `.constructor.constructor` technique.\n\n* If running angular-expressions in the browser, an attacker could run any browser script when the application code calls expressions.compile(userControlledInput).\n* If running angular-expressions on the server, an attacker could run any Javascript expression, thus gaining Remote Code Execution.\n\n### Patches\n\nUsers should upgrade to version 1.1.2 of angular-expressions\n\n### Workarounds\n\nA temporary workaround might be either to : \n\n* disable user-controlled input that will be fed into angular-expressions in your application\n\nOR\n\n* allow only following characters in the userControlledInput : \n\n```js\nif (/^[|a-zA-Z.0-9 :\"'+-?]+$/.test(userControlledInput)) {\n      var result = expressions.compile(userControlledInput);\n}\nelse {\n     result = undefined;\n}\n```\n\n### References\n\n[Removal of angular-expression sandbox](http://blog.angularjs.org/2016/09/angular-16-expression-sandbox-removal.html)\n\n### For more information\n\nIf you have any questions or comments about this advisory:\n* Open an issue in [angular-expressions](https://github.com/peerigon/angular-expressions/issues)\n* [Email us](mailto:contact@javascript-ninja.fr)\n\n### Credits \n\nThe issue was reported by Maxime Nadeau from GoSecure, Inc.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "angular-expressions"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.1.2"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/peerigon/angular-expressions/security/advisories/GHSA-j6px-jwvv-vpwq"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-21277"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/peerigon/angular-expressions/commit/07edb62902b1f6127b3dcc013da61c6316dd0bf1"
  }, {
    "type" : "WEB",
    "url" : "https://www.npmjs.com/package/angular-expressions"
  }, {
    "type" : "WEB",
    "url" : "http://blog.angularjs.org/2016/09/angular-16-expression-sandbox-removal.html"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-74", "CWE-94" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-02-01T15:00:53Z",
    "nvd_published_at" : "2021-02-01T15:15:00Z"
  }
}