Skip to content

Commit 032cfc1

Browse files
committed
Added test cases for hana clients.
1 parent 0f1aee0 commit 032cfc1

File tree

1 file changed

+86
-0
lines changed
  • javascript/ql/test/query-tests/Security/CWE-089/untyped

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
const hana = require('@sap/hana-client');
2+
const express = require('express');
3+
4+
const app = express();
5+
const connectionParams = {};
6+
app.post('/documents/find', (req, res) => {
7+
const conn = hana.createConnection();
8+
conn.connect(connectionParams, (err) => {
9+
let maliciousInput = req.body.data; // $ MISSING: Source
10+
const query = `SELECT * FROM Users WHERE username = '${maliciousInput}'`;
11+
conn.exec(query, (err, rows) => {}); // $ MISSING: Alert
12+
conn.disconnect();
13+
});
14+
15+
conn.connect(connectionParams, (err) => {
16+
const maliciousInput = req.body.data; // $ MISSING: Source
17+
const stmt = conn.prepare(`SELECT * FROM Test WHERE ID = ? AND username = ` + maliciousInput); // $ MISSING: Alert
18+
stmt.exec([maliciousInput], (err, rows) => {}); // maliciousInput is treated as a parameter
19+
conn.disconnect();
20+
});
21+
22+
conn.connect(connectionParams, (err) => {
23+
const maliciousInput = req.body.data; // $ MISSING: Source
24+
var stmt = conn.prepare(`INSERT INTO Customers(ID, NAME) VALUES(?, ?) ` + maliciousInput); // $ MISSING: Alert
25+
stmt.execBatch([[1, maliciousInput], [2, maliciousInput]], function(err, rows) {}); // maliciousInput is treated as a parameter
26+
conn.disconnect();
27+
});
28+
29+
conn.connect(connectionParams, (err) => {
30+
const maliciousInput = req.body.data; // $ MISSING: Source
31+
var stmt = conn.prepare("SELECT * FROM Customers WHERE ID >= ? AND ID < ?" + maliciousInput); // $ MISSING: Alert
32+
stmt.execQuery([100, maliciousInput], function(err, rs) {}); // $ maliciousInput is treated as a parameter
33+
conn.disconnect();
34+
});
35+
});
36+
37+
var hdbext = require('@sap/hdbext');
38+
var express = require('express');
39+
var dbStream = require('@sap/hana-client/extension/Stream');
40+
41+
var app1 = express();
42+
const hanaConfig = {};
43+
app1.use(hdbext.middleware(hanaConfig));
44+
45+
app1.get('/execute-query', function (req, res) {
46+
var client = req.db;
47+
let maliciousInput = req.body.data; // $ MISSING: Source
48+
client.exec('SELECT * FROM DUMMY' + maliciousInput, function (err, rs) {}); // $ MISSING: Alert
49+
50+
dbStream.createProcStatement(client, 'CALL PROC_DUMMY (?, ?, ?, ?, ?)' + maliciousInput, function (err, stmt) { // $ MISSING: Alert
51+
stmt.exec({ A: maliciousInput, B: 4 }, function (err, params, dummyRows, tablesRows) {}); // maliciousInput is treated as a parameter
52+
});
53+
54+
hdbext.loadProcedure(client, null, 'PROC_DUMMY' + maliciousInput, function(err, sp) { // $ MISSING: Alert
55+
sp(3, maliciousInput, function(err, parameters, dummyRows, tablesRows) {}); // maliciousInput is treated as a parameter
56+
});
57+
});
58+
59+
60+
var hdb = require('hdb');
61+
const async = require('async');
62+
63+
const options = {};
64+
const app2 = express();
65+
66+
app2.post('/documents/find', (req, res) => {
67+
var client = hdb.createClient(options);
68+
let maliciousInput = req.body.data; // $ MISSING: Source
69+
70+
client.connect(function onconnect(err) {
71+
async.series([client.exec.bind(client, "INSERT INTO NUMBERS VALUES (1, 'one')" + maliciousInput)], function (err) {}); // $ MISSING: Alert
72+
73+
client.exec('select * from DUMMY' + maliciousInput, function (err, rows) {}); // $ MISSING: Alert
74+
client.exec('select * from DUMMY' + maliciousInput, options, function(err, rows) {}); // $ MISSING: Alert
75+
76+
client.prepare('select * from DUMMY where DUMMY = ?' + maliciousInput, function (err, statement){ // $ MISSING: Alert
77+
statement.exec([maliciousInput], function (err, rows) {}); // maliciousInput is treated as a parameter
78+
});
79+
80+
client.prepare('call PROC_DUMMY (?, ?, ?, ?, ?)' + maliciousInput, function(err, statement){ // $ MISSING: Alert
81+
statement.exec({A: 3, B: maliciousInput}, function(err, parameters, dummyRows, tableRows) {});
82+
});
83+
84+
client.execute('select A, B from TEST.NUMBERS order by A' + maliciousInput, function(err, rs) {}); // $ MISSING: Alert
85+
});
86+
});

0 commit comments

Comments
 (0)