Skip to content

Commit 0a3343a

Browse files
committed
Added test cases for v2 and v3 sql injection of dynamodb
1 parent a7173e0 commit 0a3343a

File tree

1 file changed

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

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import {DynamoDBClient, ExecuteStatementCommand, BatchExecuteStatementCommand, DynamoDB} from "@aws-sdk/client-dynamodb";
2+
const express = require('express');
3+
4+
const app = express();
5+
const region = 'us-east-1';
6+
7+
app.post('/partiql/v3/execute', async (req, res) => {
8+
const client = new DynamoDBClient({});
9+
let maliciousInput = req.body.data; // $ MISSING: Source
10+
11+
const statement = `SELECT * FROM Users WHERE username = '${maliciousInput}'`;
12+
const command = new ExecuteStatementCommand({
13+
Statement: statement
14+
});
15+
await client.send(command); // $ MISSING: Alert
16+
17+
const updateStatement = "UPDATE Users SET status = 'active' WHERE id = " + maliciousInput;
18+
const updateCommand = new ExecuteStatementCommand({
19+
Statement: updateStatement
20+
});
21+
await client.send(updateCommand); // $ MISSING: Alert
22+
23+
24+
const batchInput = {
25+
Statements: [{
26+
Statement: `SELECT * FROM Users WHERE username = '${maliciousInput}'`
27+
},
28+
{
29+
Statement: "UPDATE Users SET role = 'user' WHERE username = bob"
30+
}
31+
]
32+
};
33+
34+
const batchCommand = new BatchExecuteStatementCommand(batchInput);
35+
await client.send(batchCommand); // $ MISSING: Alert
36+
37+
const batchInput2 = {
38+
Statements: maliciousInput.map(input => ({
39+
Statement: `SELECT * FROM SensitiveData WHERE username = '${input}'`
40+
}))
41+
};
42+
43+
const batchCommand2 = new BatchExecuteStatementCommand(batchInput2);
44+
await client.send(batchCommand2); // $ MISSING: Alert
45+
46+
const client2 = new DynamoDB({});
47+
await client2.send(command); // $ MISSING: Alert
48+
await client2.send(batchCommand); // $ MISSING: Alert
49+
});
50+
51+
app.post('/partiql/v2/execute', async (req, res) => {
52+
const AWS = require('aws-sdk');
53+
const dynamodb = new AWS.DynamoDB({
54+
region: 'us-east-1'
55+
});
56+
let maliciousInput = req.body.data; // $ MISSING: Source
57+
const params = {
58+
Statement: `SELECT * FROM Users WHERE username = '${maliciousInput}'`
59+
};
60+
61+
dynamodb.executeStatement(params, function(err, data) {}); // $ MISSING: Alert
62+
const params2 = {
63+
Statements: [{
64+
Statement: `SELECT * FROM Users WHERE username = '${maliciousInput}'`
65+
},
66+
{
67+
Statement: `SELECT * FROM Users WHERE username = '${maliciousInput}'`
68+
}
69+
]
70+
};
71+
72+
dynamodb.batchExecuteStatement(params2, function(err, data) {}); // $ MISSING: Alert
73+
});

0 commit comments

Comments
 (0)