Add ESLint & Run it against the system (#4470)

This commit is contained in:
Zach H 2021-11-13 14:49:06 -05:00 committed by ZeldaZach
parent 43eee6b32e
commit f789e02096
106 changed files with 1235 additions and 20242 deletions

View file

@ -20,11 +20,11 @@ export default class NormalizeService {
static normalizeGameObject(game: Game, gametypeMap: GametypeMap): void {
const { gameTypes, description } = game;
const hasType = gameTypes && gameTypes.length;
game.gameType = hasType ? gametypeMap[gameTypes[0]] : "";
game.gameType = hasType ? gametypeMap[gameTypes[0]] : '';
game.description = description || "";
game.description = description || '';
}
// Flatten logs[] into object mapped by targetType (room, game, chat)
static normalizeLogs(logs: Log[]): LogGroups {
return logs.reduce((obj, log) => {

View file

@ -4,5 +4,5 @@ function s4(): string {
}
export function guid(): string {
return s4() + s4() + "-" + s4() + "-" + s4() + "-" + s4() + "-" + s4() + s4() + s4();
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
}

View file

@ -1,3 +1,3 @@
export * from "./guid.util";
export * from "./sanitizeHtml.util";
export * from "./passwordHasher";
export * from './guid.util';
export * from './sanitizeHtml.util';
export * from './passwordHasher';

View file

@ -5,22 +5,22 @@ const HASH_ROUNDS = 1_000;
const SALT_LENGTH = 16;
export const hashPassword = (salt: string, password: string): string => {
let hashedPassword = salt + password;
for (let i = 0; i < HASH_ROUNDS; i++) {
// WHY DO WE DO IT THIS WAY?
hashedPassword = sha512(hashedPassword);
}
let hashedPassword = salt + password;
for (let i = 0; i < HASH_ROUNDS; i++) {
// WHY DO WE DO IT THIS WAY?
hashedPassword = sha512(hashedPassword);
}
return salt + Base64.stringify(hashedPassword);
return salt + Base64.stringify(hashedPassword);
};
export const generateSalt = (): string => {
const characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
const characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
let salt = "";
for (let i = 0; i < SALT_LENGTH; i++) {
salt += characters.charAt(Math.floor(Math.random() * characters.length));
}
let salt = '';
for (let i = 0; i < SALT_LENGTH; i++) {
salt += characters.charAt(Math.floor(Math.random() * characters.length));
}
return salt;
}
return salt;
}

View file

@ -1,11 +1,11 @@
import $ from "jquery";
import $ from 'jquery';
export function sanitizeHtml(msg: string): string {
const $div = $("<div>").html(msg);
const $div = $('<div>').html(msg);
const whitelist = {
tags: "br,a,img,center,b,font",
attrs: ["href","color"],
href: ["http://","https://","ftp://","//"]
tags: 'br,a,img,center,b,font',
attrs: ['href', 'color'],
href: ['http://', 'https://', 'ftp://', '//']
};
// remove all tags, attributes, and href protocols except some
@ -17,35 +17,36 @@ export function sanitizeHtml(msg: string): string {
}
function enforceTagWhitelist($el: JQuery<HTMLElement>, tags: string): void {
$el.find("*").not(tags).each(function() {
$el.find('*').not(tags).each(() => {
$(this).replaceWith(this.innerHTML);
});
}
function enforceAttrWhitelist($el: JQuery<HTMLElement>, attrs: string[]): void {
$el.find("*").each(function() {
var attributes = this.attributes;
var i = attributes.length;
while( i-- ) {
var attr = attributes[i];
if( $.inArray(attr.name,attrs) === -1 )
$el.find('*').each(() => {
const attributes = this.attributes;
let i = attributes.length;
while (i--) {
const attr = attributes[i];
if ($.inArray(attr.name, attrs) === -1) {
this.removeAttributeNode(attr);
}
}
});
}
function enforceHrefWhitelist($el: JQuery<HTMLElement>, hrefs: string[]): void {
$el.find("[href]").each(function() {
$el.find('[href]').each(() => {
const $_el = $(this);
const attributeValue = $_el.attr("href");
const attributeValue = $_el.attr('href');
for (let protocol in hrefs) {
if (attributeValue.indexOf(hrefs[protocol]) === 0) {
$_el.attr("target", "_blank");
return;
}
if (attributeValue.indexOf(hrefs[protocol]) === 0) {
$_el.attr('target', '_blank');
return;
}
}
$_el.removeAttr("href");
$_el.removeAttr('href');
});
}
}