From 916bc733c3a9337ed92ebc66017af3c2e0749f22 Mon Sep 17 00:00:00 2001 From: AlecM33 Date: Sat, 26 Feb 2022 00:25:53 -0500 Subject: [PATCH 1/3] stricter content security policy --- client/src/modules/DeckStateManager.js | 14 +++-- client/src/modules/GameCreationStepManager.js | 18 +++---- client/src/modules/HTMLFragments.js | 14 ++--- client/src/modules/Toast.js | 48 +++++++++++------ client/src/scripts/game.js | 18 +++---- client/src/scripts/join.js | 6 +-- client/src/styles/GLOBAL.css | 53 ++++++++++++++++++- client/src/styles/create.css | 1 + client/src/styles/game.css | 2 +- client/src/styles/join.css | 5 ++ client/src/styles/modal.css | 3 +- client/src/view_templates/CreateTemplate.js | 10 ++-- client/src/views/home.html | 4 +- server/modules/GameManager.js | 5 ++ server/modules/ServerBootstrapper.js | 10 ++++ 15 files changed, 153 insertions(+), 58 deletions(-) diff --git a/client/src/modules/DeckStateManager.js b/client/src/modules/DeckStateManager.js index 773a0b9..1299271 100644 --- a/client/src/modules/DeckStateManager.js +++ b/client/src/modules/DeckStateManager.js @@ -36,7 +36,7 @@ export class DeckStateManager { if (option) { this.customRoleOptions.splice(this.customRoleOptions.indexOf(option), 1); localStorage.setItem('play-werewolf-custom-roles', JSON.stringify(this.customRoleOptions.concat(this.deck.filter(card => card.custom === true)))); - toast('"' + name + '" deleted.', 'error', true, true, 3); + toast('"' + name + '" deleted.', 'error', true, true, 'short'); } } @@ -88,7 +88,7 @@ export class DeckStateManager { loadCustomRolesFromFile (file, updateRoleListFunction, loadDefaultCardsFn, showIncludedCardsFn) { const reader = new FileReader(); reader.onerror = (e) => { - toast(reader.error.message, 'error', true, true, 5); + toast(reader.error.message, 'error', true, true, 'medium'); }; reader.onload = (e) => { let string; @@ -100,13 +100,19 @@ export class DeckStateManager { if (validateCustomRoleCookie(string)) { this.customRoleOptions = JSON.parse(string); // we know it is valid JSON from the validate function ModalManager.dispelModal('upload-custom-roles-modal', 'modal-background'); - toast('Roles imported successfully', 'success', true, true, 3); + toast('Roles imported successfully', 'success', true, true, 'short'); localStorage.setItem('play-werewolf-custom-roles', JSON.stringify(this.customRoleOptions)); updateRoleListFunction(this, document.getElementById('deck-select')); // loadDefaultCardsFn(this); // showIncludedCardsFn(this); } else { - toast('Invalid formatting. Make sure you import the file as downloaded from this page.', 'error', true, true, 5); + toast( + 'Invalid formatting. Make sure you import the file as downloaded from this page.', + 'error', + true, + true, + 'medium' + ); } }; reader.readAsText(file); diff --git a/client/src/modules/GameCreationStepManager.js b/client/src/modules/GameCreationStepManager.js index 2dda6bc..36c1c04 100644 --- a/client/src/modules/GameCreationStepManager.js +++ b/client/src/modules/GameCreationStepManager.js @@ -132,7 +132,7 @@ export class GameCreationStepManager { button.classList.remove('submitted'); button.addEventListener('click', this.steps['4'].forwardHandler); if (e.status === 429) { - toast('You\'ve sent this request too many times.', 'error', true, true, 6); + toast('You\'ve sent this request too many times.', 'error', true, true, 'medium'); } }); } @@ -280,23 +280,23 @@ function renderRoleSelectionStep (game, containerId, step, deckManager) { if (fileList.length > 0) { const file = fileList[0]; if (file.size > 1000000) { - toast('Your file is too large (max 1MB)', 'error', true, true, 5); + toast('Your file is too large (max 1MB)', 'error', true, true, 'medium'); return; } if (file.type !== 'text/plain') { - toast('Your file must be a text file', 'error', true, true, 5); + toast('Your file must be a text file', 'error', true, true, 'medium'); return; } deckManager.loadCustomRolesFromFile(file, updateCustomRoleOptionsList, loadDefaultCards, showIncludedCards); } else { - toast('You must upload a text file', 'error', true, true, 5); + toast('You must upload a text file', 'error', true, true, 'medium'); } }; const clickHandler = () => { const actions = document.getElementById('custom-role-actions'); - if (actions.style.display !== 'none') { + if (window.getComputedStyle(actions, null).display !== 'none') { actions.style.display = 'none'; } else { actions.style.display = 'block'; @@ -563,7 +563,7 @@ function initializeRemainingEventListeners (deckManager) { if (!deckManager.getCustomRoleOption(name) && !deckManager.getCard(name)) { // confirm there is no existing custom role with the same name processNewCustomRoleSubmission(name, description, team, deckManager, false); } else { - toast('There is already a role with this name', 'error', true, true, 3); + toast('There is already a role with this name', 'error', true, true, 'short'); } } else { const option = deckManager.getCustomRoleOption(deckManager.currentlyEditingRoleName); @@ -573,7 +573,7 @@ function initializeRemainingEventListeners (deckManager) { if (!deckManager.getCustomRoleOption(name) && !deckManager.getCard(name)) { processNewCustomRoleSubmission(name, description, team, deckManager, true, option); } else { - toast('There is already a role with this name', 'error', true, true, 3); + toast('There is already a role with this name', 'error', true, true, 'short'); } } } @@ -653,7 +653,7 @@ function addCustomRoleEventListeners (deckManager, select) { if (!deckManager.getCard(name)) { deckManager.addToDeck(name); const cardEl = constructCompactDeckBuilderElement(deckManager.getCard(name), deckManager); - toast('"' + name + '" made available below.', 'success', true, true, 4); + toast('"' + name + '" made available below.', 'success', true, true, 'medium'); if (deckManager.getCard(name).team === globals.ALIGNMENT.GOOD) { document.getElementById('deck-good').appendChild(cardEl); } else { @@ -661,7 +661,7 @@ function addCustomRoleEventListeners (deckManager, select) { } updateCustomRoleOptionsList(deckManager, select); } else { - toast('"' + select.value + '" already included.', 'error', true, true, 3); + toast('"' + select.value + '" already included.', 'error', true, true, 'short'); } } }; diff --git a/client/src/modules/HTMLFragments.js b/client/src/modules/HTMLFragments.js index 3c4a8ab..a5f8bc0 100644 --- a/client/src/modules/HTMLFragments.js +++ b/client/src/modules/HTMLFragments.js @@ -53,7 +53,7 @@ export const HTMLFragments = { -