Skip to content

Commit c841d2d

Browse files
committed
fix security bugs
1 parent fc7afe9 commit c841d2d

File tree

24 files changed

+1220
-1112
lines changed

24 files changed

+1220
-1112
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules/
1+
node_modules/
2+
*.pem

flavorwheel/index.js

Whitespace-only changes.

idempotency/index.html

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Place order</title>
7+
</head>
8+
<body>
9+
<h1>Place Order</h1>
10+
<!-- ORDER -->
11+
<form method="POST">
12+
<input type = 'submit' value = 'Submit'>
13+
</form>
14+
</body>
15+
</html>

idempotency/index.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const app = require('express')();
2+
const fs = require('fs');
3+
const pg = require( 'pg');
4+
5+
const pool = new pg.Pool({
6+
"host": "husseinmac.local",
7+
"port": 5433,
8+
"user":"postgres",
9+
"password" : "password",
10+
"database" : "postgres",
11+
"max": 20,
12+
"connectionTimeoutMillis" : 0,
13+
"idleTimeoutMillis": 0
14+
})
15+
16+
17+
18+
app.get("/", (req,res) => {
19+
20+
res.sendFile(__dirname + "/index.html")
21+
})
22+
let id = 0;
23+
app.post("/", async (req,res) => {
24+
25+
try {
26+
const txtIndex = fs.readFileSync(__dirname + "/index.html")
27+
const sql = "insert into orders (username) values ($1)";
28+
29+
const result = await pool.query(sql, ['hussein']);
30+
id++;
31+
const updatedIndexHtml = txtIndex.toString().replace("<!-- ORDER -->", `<h1>Order ${id} placed successfully</h1>`)
32+
33+
//res.headers.add("")
34+
res.send(updatedIndexHtml)
35+
}
36+
catch(ex){
37+
console.error(ex)
38+
res.send(ex)
39+
}
40+
41+
})
42+
43+
app.listen(8080);

0 commit comments

Comments
 (0)