forked from AvishiktaBagchi/cdru-cloudsec-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
49 lines (41 loc) · 1.15 KB
/
Copy pathapp.js
File metadata and controls
49 lines (41 loc) · 1.15 KB
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
require('dotenv').config();
const express = require('express');
const app = express();
// homepage
app.get('/', (req, res) => {
res.send("CDRU Application");
});
// Vulnerability #1: Reflected XSS
app.get('/user', (req, res) => {
const name = req.query.name;
res.send(`<h1>Hello ${name}</h1>`);
});
// Vulnerability #2: Sensitive data exposure
app.get('/debug', (req, res) => {
res.json({
env: process.env, // leaks EVERYTHING
message: "Debug info exposed"
});
});
// Vulnerability #3: Broken auth
app.get('/admin', (req, res) => {
if (req.query.email === process.env.ADMIN_EMAIL) {
res.send("Welcome admin!");
} else {
res.send("Access denied");
}
});
// Vulnerability #4: Input abuse (DAST detectable)
app.get('/search', (req, res) => {
const query = req.query.q;
res.send(`You searched for: ${query}`);
});
// Logging for forensics (IMPORTANT)
app.use((req, res, next) => {
console.log(`IP: ${req.ip} | Path: ${req.path} | Query: ${JSON.stringify(req.query)}`);
next();
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`App running on port ${PORT}`);
});