Skip to content

Commit

Permalink
Validate solution and nonce data types
Browse files Browse the repository at this point in the history
  • Loading branch information
harryttd committed Oct 13, 2023
1 parent e4a90e1 commit ba042d9
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,28 @@ const validateChallengeBody = (
res: Response,
next: NextFunction
) => {
const { solution, nonce } = req.body

if (!env.DISABLE_CHALLENGES && (!solution || !nonce)) {
return res.status(400).send({
status: "ERROR",
message: "'solution', and 'nonce', fields are required",
})
if (!env.DISABLE_CHALLENGES) {
const { solution, nonce } = req.body
if (!solution || !nonce) {
return res.status(400).send({
status: "ERROR",
message: "'solution', and 'nonce', fields are required",
})
}

if (!Number.isInteger(nonce)) {
return res.status(400).send({
status: "ERROR",
message: "'nonce' must be an integer",
})
}

if (typeof solution !== "string") {
return res.status(400).send({
status: "ERROR",
message: "'solution' must be a string",
})
}
}

next()
Expand Down

0 comments on commit ba042d9

Please sign in to comment.