-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathadmin.js
More file actions
174 lines (163 loc) · 5.51 KB
/
Copy pathadmin.js
File metadata and controls
174 lines (163 loc) · 5.51 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
const express = require('express');
const router = express.Router();
// In-memory database for storing user information (including sensitive data)
const users = []; // Simulated user storage for the sake of example
const usersInfo = [
{ username: 'user1', dob: '1990-01-01', address: '5, 3rd mainland Bridge', cardInfo: '1234-5678-9012-3456', children: ['Child1', 'Child2'], balance: 1000, role: 'user' },
{ username: 'user2', dob: '1985-05-17', address: '7, Ghost street', cardInfo: '9876-5432-1098-7654', children: ['Child3'], balance: 500, role: 'user' },
];
/**
* @swagger
* tags:
* name: Admin
* description: Admin-related endpoints
*/
/**
* @swagger
* /admin/hidden-admin-signup:
* post:
* summary: Create hidden admin account
* description: Allows the creation of an admin account without proper authorization checks, simulating a broken function-level authorization vulnerability.
* tags: [Admin]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* username:
* type: string
* example: adminUser
* password:
* type: string
* example: securePassword
* responses:
* 200:
* description: Admin account created successfully
* content:
* application/json:
* schema:
* type: object
* properties:
* message:
* type: string
* example: Admin account created
* newAdmin:
* type: object
* properties:
* username:
* type: string
* example: adminUser
* password:
* type: string
* example: securePassword
* role:
* type: string
* example: admin
* 400:
* description: Bad request, likely due to missing or invalid data
* content:
* application/json:
* schema:
* type: object
* properties:
* message:
* type: string
* example: Bad request
*/
/**
* @swagger
* /admin/grant-loan/{username}:
* post:
* summary: Grant a loan to a user
* description: Grants a loan to a user without proper authorization checks, simulating an insecure direct object reference vulnerability.
* tags: [Admin]
* parameters:
* - in: path
* name: username
* required: true
* description: The username of the user to whom the loan is being granted
* schema:
* type: string
* example: user1
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* amount:
* type: number
* format: float
* example: 500
* responses:
* 200:
* description: Loan granted successfully
* content:
* application/json:
* schema:
* type: object
* properties:
* message:
* type: string
* example: Loan granted
* user:
* type: object
* properties:
* username:
* type: string
* example: user1
* dob:
* type: string
* format: date
* example: '1990-01-01'
* address:
* type: string
* example: '5, 3rd mainland Bridge'
* cardInfo:
* type: string
* example: '1234-5678-9012-3456'
* children:
* type: array
* items:
* type: string
* example: ['Child1', 'Child2']
* balance:
* type: number
* format: float
* example: 1500
* role:
* type: string
* example: user
* 404:
* description: User not found
* content:
* application/json:
* schema:
* type: object
* properties:
* message:
* type: string
* example: User not found
*/
router.post('/hidden-admin-signup', (req, res) => {
const { username, password } = req.body;
// Simulated vulnerability: anyone can create an admin account
const newAdmin = { username, password, role: 'admin' };
users.push(newAdmin);
return res.json({ message: 'Admin account created', newAdmin });
});
router.post('/grant-loan/:username', (req, res) => {
const { username } = req.params;
const { amount } = req.body;
const user = usersInfo.find(user => user.username === username);
if (!user) {
return res.status(404).json({ message: 'User not found' });
}
// Grant loan without proper authorization checks
user.balance += amount;
return res.json({ message: 'Loan granted', user });
});
module.exports = router;