-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaccount.js
More file actions
193 lines (185 loc) · 6.07 KB
/
Copy pathaccount.js
File metadata and controls
193 lines (185 loc) · 6.07 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
const express = require('express');
const router = express.Router();
// In-memory database for storing user information (including sensitive data)
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: 'user3', dob: '1985-05-15', address: '7, Ghost street', cardInfo: '9876-5432-1098-7654', children: ['Child3'], balance: 500, role: 'user' },
];
/**
* @swagger
* tags:
* name: Account
* description: User account endpoints
*/
/**
* @swagger
* /account/info/{username}:
* get:
* summary: Get user account information
* description: Retrieves user account information, which may include sensitive data
* tags: [Account]
* parameters:
* - in: path
* name: username
* required: true
* description: The username of the user whose information is being retrieved
* schema:
* type: string
* example: user1
* responses:
* 200:
* description: User account information retrieved successfully
* content:
* application/json:
* schema:
* 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: 1000
* role:
* type: string
* example: user
* 404:
* description: User not found
* content:
* application/json:
* schema:
* type: object
* properties:
* message:
* type: string
* example: User not found
*/
/**
* @swagger
* /account/update/{username}:
* put:
* summary: Update user profile
* description: Updates user profile information. Be cautious of mass assignment vulnerabilities.
* tags: [Account]
* parameters:
* - in: path
* name: username
* required: true
* description: The username of the user whose profile is being updated
* schema:
* type: string
* example: user1
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* 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: 1000
* role:
* type: string
* example: user
* responses:
* 200:
* description: User profile updated successfully
* content:
* application/json:
* schema:
* type: object
* properties:
* message:
* type: string
* example: Profile updated
* userInfo:
* 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: 1000
* 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.get('/info/:username', (req, res) => {
const { username } = req.params;
const userInfo = usersInfo.find(user => user.username === username);
if (!userInfo) {
return res.status(404).json({ message: 'User not found' });
}
return res.json(userInfo); // Returns sensitive information
});
router.put('/update/:username', (req, res) => {
const { username } = req.params;
const userInfo = usersInfo.find(user => user.username === username);
if (!userInfo) {
return res.status(404).json({ message: 'User not found' });
}
// Mass assignment vulnerability
Object.assign(userInfo, req.body);
return res.json({ message: 'Profile updated', userInfo });
});
module.exports = router;