Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript: Model chaining calls in sqlite3. #5860

Merged
merged 1 commit into from May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions javascript/change-notes/2021-05-10-sqlite3-chaining.md
@@ -0,0 +1,3 @@
lgtm,codescanning
* Modelling of chaining methods in the `sqlite3` package has improved, which may lead to
additional results from the `js/sql-injection` query.
14 changes: 12 additions & 2 deletions javascript/ql/src/semmle/javascript/frameworks/SQL.qll
Expand Up @@ -341,18 +341,28 @@ private module Sqlite {
result = sqlite().getMember("verbose").getReturn()
}

/** Gets an expression that constructs a Sqlite database instance. */
/** Gets an expression that constructs or returns a Sqlite database instance. */
API::Node database() {
// new require('sqlite3').Database()
result = sqlite().getMember("Database").getInstance()
or
// chained call
result = getAChainingQueryCall()
or
result = API::Node::ofType("sqlite3", "Database")
}

/** A call to a query method on a Sqlite database instance that returns the same instance. */
private API::Node getAChainingQueryCall() {
result = database().getMember(["all", "each", "exec", "get", "run"]).getReturn()
}

/** A call to a Sqlite query method. */
private class QueryCall extends DatabaseAccess, DataFlow::MethodCallNode {
QueryCall() {
this = database().getMember(["all", "each", "exec", "get", "prepare", "run"]).getACall()
this = getAChainingQueryCall().getAnImmediateUse()
or
this = database().getMember("prepare").getACall()
}

override DataFlow::Node getAQueryArgument() { result = getArgument(0) }
Expand Down
Expand Up @@ -66,5 +66,6 @@
| spannerImport.js:4:8:4:17 | "SQL code" |
| sqlite-types.ts:4:12:4:49 | "UPDATE ... id = ?" |
| sqlite.js:7:8:7:45 | "UPDATE ... id = ?" |
| sqlite.js:8:8:8:45 | "UPDATE ... id = ?" |
| sqliteArray.js:6:12:6:49 | "UPDATE ... id = ?" |
| sqliteImport.js:2:8:2:44 | "UPDATE ... id = ?" |
3 changes: 2 additions & 1 deletion javascript/ql/test/library-tests/frameworks/SQL/sqlite.js
Expand Up @@ -4,6 +4,7 @@
var sqlite = require('sqlite3');

var db = new sqlite.Database(":memory:");
db.run("UPDATE tbl SET name = ? WHERE id = ?", "bar", 2);
db.run("UPDATE tbl SET name = ? WHERE id = ?", "bar", 2)
.run("UPDATE tbl SET name = ? WHERE id = ?", "foo", 3);

exports.db = db;