Skip to content

Commit

Permalink
fix: validate UUID on setup before parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
confuser committed Jul 23, 2022
1 parent 004cca9 commit 781a4b0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cli/commands/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const inquirer = require('inquirer')
const editDotenv = require('edit-dotenv')
const DBMigrate = require('db-migrate')
const { Command, flags } = require('@oclif/command')
const { isAlphanumeric, isEmail, isLength } = require('validator')
const { isAlphanumeric, isEmail, isLength, isUUID } = require('validator')
const { generateVAPIDKeys } = require('web-push')
const { merge } = require('lodash')
const { parse } = require('uuid-parse')
Expand Down Expand Up @@ -273,6 +273,12 @@ class SetupCommand extends Command {
const askPlayer = async (question, conn, table) => {
const questions = [{ name: 'id', message: question }]
const { id } = await inquirer.prompt(questions)

if (!isUUID(id, 4)) {
this.log(`Invalid UUID format ${id}`)
return askPlayer(question, conn, table)
}

const parsedId = parse(id, Buffer.alloc(16))
const player = await playerExists(conn, table, parsedId)

Expand Down

0 comments on commit 781a4b0

Please sign in to comment.