Skip to content

Commit 1975a83

Browse files
authored
Merge pull request github#3116 from max-schaefer/js/postgres-type-tracking
Approved by asgerf
2 parents 968ddc6 + efbcec0 commit 1975a83

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

change-notes/1.24/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
- [ncp](https://www.npmjs.com/package/ncp)
4343
- [node-dir](https://www.npmjs.com/package/node-dir)
4444
- [path-exists](https://www.npmjs.com/package/path-exists)
45+
- [pg](https://www.npmjs.com/package/pg)
4546
- [react](https://www.npmjs.com/package/react)
4647
- [recursive-readdir](https://www.npmjs.com/package/recursive-readdir)
4748
- [request](https://www.npmjs.com/package/request)

javascript/ql/src/semmle/javascript/frameworks/SQL.qll

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,22 @@ private module Postgres {
132132
result = DataFlow::moduleImport("pg-pool").getAnInstantiation()
133133
}
134134

135+
private DataFlow::SourceNode clientOrPool(DataFlow::TypeTracker t) {
136+
t.start() and
137+
(result = client() or result = newPool())
138+
or
139+
exists(DataFlow::TypeTracker t2 | result = clientOrPool(t2).track(t2, t))
140+
}
141+
142+
private DataFlow::SourceNode clientOrPool() {
143+
result = clientOrPool(DataFlow::TypeTracker::end())
144+
}
145+
135146
/** A call to the Postgres `query` method. */
136147
private class QueryCall extends DatabaseAccess, DataFlow::ValueNode {
137148
override MethodCallExpr astNode;
138149

139-
QueryCall() {
140-
exists(DataFlow::SourceNode recv | recv = client() or recv = newPool() |
141-
this = recv.getAMethodCall("query")
142-
)
143-
}
150+
QueryCall() { this = clientOrPool().getAMethodCall("query") }
144151

145152
override DataFlow::Node getAQueryArgument() {
146153
result = DataFlow::valueNode(astNode.getArgument(0))

javascript/ql/test/library-tests/frameworks/SQL/SqlString.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
| postgres1.js:37:21:37:24 | text |
1313
| postgres2.js:30:16:30:41 | 'SELECT ... number' |
1414
| postgres3.js:15:16:15:40 | 'SELECT ... s name' |
15+
| postgres5.js:8:21:8:25 | query |
1516
| sequelize2.js:10:17:10:118 | 'SELECT ... Y name' |
1617
| sequelize.js:8:17:8:118 | 'SELECT ... Y name' |
1718
| spanner2.js:5:26:5:35 | "SQL code" |
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const pg = require('pg');
2+
3+
function PgWrapper() {
4+
this.pool = new pg.Pool({});
5+
}
6+
7+
PgWrapper.prototype.query = function (query, params, cb) {
8+
this.pool.query(query, params || [], cb);
9+
};

0 commit comments

Comments
 (0)