SQL Injection Affecting @azhou/basemodel package, versions *


Severity

Recommended
0.0
high
0
10

CVSS assessment made by Snyk's Security Team. Learn more

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 Learn

Learn about SQL Injection vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-JS-AZHOUBASEMODEL-544026
  • published3 Feb 2020
  • disclosed2 Feb 2020
  • creditverichains

Introduced: 2 Feb 2020

CVE NOT AVAILABLE CWE-89  (opens in a new tab)

How to fix?

There is no fixed version for @azhou/basemodel.

Overview

@azhou/basemodel is a package.

Affected versions of this package are vulnerable to SQL Injection. All table names and fields arguments of all methods are fed directly into query by string concatenation without escaping which may lead to sql injection. In addition, order by fields of model.getAll(fields, orderby) is not escaped and directly used in query which lead to blind sql injection.

PoC

    model.getAll = function (fields, orderby) {
        if (typeof fields == 'string') {
            orderby = fields;
            fields = allFields;
        } else if (Array.isArray(fields) && (typeof orderby == 'string' || !orderby)) {
            if (fields.length == 0)
                fields = allFields;
        } else {
            fields = allFields;
            orderby = "";
        }

        return db.query("SELECT id," + fields.join(",") + " FROM `" + table + "`"
            + (orderby ? " ORDER BY " + orderby : ""));
    }

References

CVSS Scores

version 3.1