Skip to content

False negative for JavaScript SQL injection #16548

@wtfiwtz

Description

@wtfiwtz

Description of the issue

I attempted to detect this vulnerability in our codebase but it doesn't get picked up. Similar to #7586 and #7591 but I can't quite see what changes are required to the CodeQL source (or how to analyse the data flows / evaluator logs).

const pg = require("pg");
const rl = require('readline');

// Introduce delibrate SQL injection to test CodeQL
rl.question('What is your name? ', ans => {
  console.log('Your name is', ans);

  const pgConn = new pg.Client({});
  pgConn.connect();

  pgConn.query(
    "SELECT * FROM users WHERE id = '" + ans + "'",
    (err, res) => {
      if (err) {
        console.log(err.stack);
      } else {
        console.log(res.rows[0]);
      }
      pgConn.end();
    }
  );

  rl.close();
});
codeql database create codeql --language=javascript-typescript
codeql database analyze codeql --rerun --verbose --format=csv --output codeql.csv codeql/javascript-queries@0.8.16:Security/CWE-089/SqlInjection.ql
codeql database analyze codeql --rerun --verbose --format=csv --output codeql.csv codeql/javascript-queries

Both the 2nd and 3rd commands give me an empty codeql.csv file (i.e. no issues detected).

Using `... ${...} ... ` or "" + ... concatenations didn't make any difference.

Is there any guidance on next steps to get this included in Github Advanced Security, etc?

I attempted this within a bigger repo with multiple AWS lambdas and it didn't pick it up there either.

Best regards,
Nigel

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions