Skip to content

Commit 9b8e7ba

Browse files
author
Nitro
committed
Update and improve the security
1 parent 03f1891 commit 9b8e7ba

3 files changed

Lines changed: 23 additions & 6 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ Request: `/comment`
143143
```json
144144
{
145145
"id":"ID from mongodb, ObjectID",
146+
"email":"User Email, @avonoldfarms.com",
146147
"pw":"String, MD5 encrypted password"
147148
}
148149
```
@@ -151,6 +152,7 @@ Request: `/comment`
151152
```json
152153
{
153154
"id":"5f59080a5923552004a899f3",
155+
"email":"test1@avonoldfarms.com",
154156
"pw":"4a7d1ed414474e4033ac29ccb8653d9b"
155157
}
156158
```

src/database/comment.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ async function addComment(date, name, email, pw, meal, menu, like, comment) {
3131
}
3232
}
3333

34-
async function deleteComment(id, pw) {
34+
async function deleteComment(id, email, pw) {
3535
const db = await getDB()
3636
let item = await db.collection(colName).findOne(
3737
{
3838
_id: id,
39+
email: email,
3940
pw: pw,
4041
}
4142
)

src/index.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Backend Ver: v2.0.1
2+
13
// Importing Environmental Variables
24
if (process.env.NODE_ENV !== 'production') {
35
require('dotenv').config()
@@ -30,7 +32,7 @@ const {
3032
isComment
3133
} = require('./modules/valid')
3234

33-
const debug = true
35+
const debug = false
3436

3537
// Initializing App
3638
const app = express()
@@ -195,19 +197,31 @@ app.post('/comment', async (req, res) => {
195197

196198
app.post('/delete_comment', async (req, res) => {
197199
let id = ObjectID(req.body.id) // Hexadecimal
200+
let email = req.body.email
198201
let pw = req.body.pw // MD5
199202

203+
if (debug) {
204+
console.log(id)
205+
console.log(email)
206+
console.log(pw)
207+
}
208+
200209
if (!isHexadecimal(id)) {
201210
callback(res, 400, 'POST Error: Invalid comment id.')
202211
return
203212
}
204213

214+
if (!isEmail(email)) {
215+
callback(res, 400, 'POST Error: Invalid email.')
216+
return
217+
}
218+
205219
if (!isMD5(pw)) {
206220
callback(res, 400, 'POST Error: Invalid password.')
207221
return
208222
}
209223

210-
const r = await deleteComment(id, pw).catch((error) => {
224+
const r = await deleteComment(id, email, pw).catch((error) => {
211225
if (error === 403) {
212226
callback(res, 403, 'POST Error: Cannot find the comment to delete.')
213227
} else {
@@ -244,9 +258,9 @@ app.get('/comment', async (req, res) => {
244258
})
245259

246260
function callback(res, code, text) {
247-
if (debug) {
248-
console.log(text)
249-
}
261+
//if (debug) {
262+
console.log(text)
263+
//}
250264
res.status(code).send({ message: text })
251265
}
252266

0 commit comments

Comments
 (0)