fully validate game creation parameters sent through the API

This commit is contained in:
AlecM33
2022-12-29 17:05:09 -05:00
parent e0dffe17b6
commit 66698500b9
7 changed files with 67 additions and 12 deletions

View File

@@ -2,7 +2,7 @@ export const globals = {
CHAR_POOL: 'abcdefghijklmnopqrstuvwxyz0123456789',
USER_SIGNATURE_LENGTH: 25,
CLOCK_TICK_INTERVAL_MILLIS: 100,
MAX_CUSTOM_ROLE_NAME_LENGTH: 30,
MAX_CUSTOM_ROLE_NAME_LENGTH: 50,
MAX_CUSTOM_ROLE_DESCRIPTION_LENGTH: 500,
TOAST_DURATION_DEFAULT: 6,
ACCESS_CODE_LENGTH: 4,

View File

@@ -5,6 +5,5 @@ export class Game {
this.timerParams = timerParams;
this.hasDedicatedModerator = hasDedicatedModerator;
this.moderatorName = moderatorName;
this.accessCode = null;
}
}

View File

@@ -54,11 +54,13 @@ export class GameCreationStepManager {
title: 'Set an optional timer:',
forwardHandler: (e) => {
if (e.type === 'click' || e.code === 'Enter') {
const hours = parseInt(document.getElementById('game-hours').value);
const minutes = parseInt(document.getElementById('game-minutes').value);
if ((isNaN(hours) && isNaN(minutes))
|| (isNaN(hours) && minutes > 0 && minutes < 60)
|| (isNaN(minutes) && hours > 0 && hours < 6)
let hours = parseInt(document.getElementById('game-hours').value);
let minutes = parseInt(document.getElementById('game-minutes').value);
hours = isNaN(hours) ? null : hours;
minutes = isNaN(minutes) ? null : minutes;
if ((hours === null && minutes === null)
|| (hours === null && minutes > 0 && minutes < 60)
|| (minutes === null && hours > 0 && hours < 6)
|| (hours === 0 && minutes > 0 && minutes < 60)
|| (minutes === 0 && hours > 0 && hours < 6)
|| (hours > 0 && hours < 6 && minutes >= 0 && minutes < 60)
@@ -571,7 +573,7 @@ function processNewCustomRoleSubmission (name, description, team, deckManager, i
}
function hasTimer (hours, minutes) {
return (!isNaN(hours) || !isNaN(minutes));
return hours !== null || minutes !== null;
}
function validateName (name) {

View File

@@ -333,7 +333,7 @@ function validateCustomRoleCookie (cookie) {
const cookieJSON = JSON.parse(cookie);
if (Array.isArray(cookieJSON)) {
for (const entry of cookieJSON) {
if (typeof entry === 'object') {
if (entry !== null && typeof entry === 'object') {
if (typeof entry.role !== 'string' || entry.role.length > globals.MAX_CUSTOM_ROLE_NAME_LENGTH
|| typeof entry.team !== 'string' || (entry.team !== globals.ALIGNMENT.GOOD && entry.team !== globals.ALIGNMENT.EVIL)
|| typeof entry.description !== 'string' || entry.description.length > globals.MAX_CUSTOM_ROLE_DESCRIPTION_LENGTH