-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (32 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const mysql = require('mysql');
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'root',
database: 'sqlInjectionDemo',
multipleStatements: true
});
function sqlInjectionProblem() {
const id = "1;DELETE FROM user_login";
const sql = "SELECT * FROM user_login WHERE id = " + id + ""; // problem
connection.query(sql, (error, results) => {
if (!error) {
console.log("results: " + JSON.stringify(results));
} else {
console.log("error: " + JSON.stringify(error));
}
});
}
function sqlInjectionSolution() {
const id = "1;DELETE FROM user_login";
const sql="SELECT * FROM user_login WHERE id = "+ connection.escape(id) +""; // solution
connection.query(sql, (error, results) => {
if (!error) {
console.log("results: " + JSON.stringify(results));
} else {
console.log("error: " + JSON.stringify(error));
}
});
}
//sqlInjectionProblem();
//sqlInjectionSolution();