-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (33 loc) · 936 Bytes
/
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
const express = require('express')
const app = express()
const mysql = require('mysql')
// Uppkoppling
let connection = mysql.createConnection({
host: 'localhost',
user: 'injectionManager',
password: 'br0mmabl0cks',
database: 'injection',
})
// Starta kontakt med servern.
connection.connect()
// BAD
app.get('/users/:id', (req, res) => {
let query = `SELECT * FROM users WHERE users.id = '${req.params.id}'`
console.log(query)
connection.query(query, (err, result, fields) => {
if (err) throw err
res.json(result)
})
})
// GOOD
app.get('/members/:id', (req, res) => {
let query = "SELECT * FROM members WHERE id = " + connection.escape(req.params.id)
console.log(query)
connection.query(query, (err, result, fields) => {
if (err) throw err
res.json(result)
})
})
app.listen(8080, () => {
console.log("The perils of sql injection is alive...")
})