Skip to content

Commit 3656864

Browse files
committed
JS: Add database threat-model source modeling
1 parent 7c7420a commit 3656864

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

javascript/ql/lib/semmle/javascript/Concepts.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ abstract class DatabaseAccess extends DataFlow::Node {
148148
}
149149
}
150150

151+
/**
152+
* A DatabaseAccess seen as a ThreatModelSource.
153+
*/
154+
private class DatabaseAccessAsThreatModelSource extends ThreatModelSource::Range {
155+
DatabaseAccessAsThreatModelSource() { this = any(DatabaseAccess access).getAResult() }
156+
157+
override string getThreatModel() { result = "database" }
158+
159+
override string getSourceType() { result = "DatabaseAccess" }
160+
}
161+
151162
/**
152163
* A data flow node that reads persistent data.
153164
*/

javascript/ql/test/library-tests/threat-models/sources/sources.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,16 @@ const program = new Command();
4242
program.parse(process.argv); // $ threat-source=commandargs
4343

4444
SINK(program.opts().foo); // $ hasFlow SPURIOUS: threat-source=commandargs
45+
46+
// ------ reading from database ------
47+
48+
// Accessing database using mysql
49+
const mysql = require('mysql');
50+
const connection = mysql.createConnection({host: 'localhost'});
51+
connection.connect();
52+
connection.query('SELECT 1 + 1 AS solution', function (error, results, fields) { // $ threat-source=database
53+
if (error) throw error;
54+
SINK(results); // $ hasFlow
55+
SINK(results[0]); // $ hasFlow
56+
SINK(results[0].solution); // $ hasFlow
57+
});

0 commit comments

Comments
 (0)