From e49905c5ad5f97cc0e036ab12cd44731c87ba4d5 Mon Sep 17 00:00:00 2001 From: Nick Funk Date: Thu, 5 Sep 2019 15:36:09 -0600 Subject: [PATCH] [CORL-571] Filter empty strings from banned and suspect word lists (#2521) * Filter empty strings from banned and suspect word lists CORL-571 * fix: changed form --- src/core/server/services/tenant/index.ts | 25 +++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/core/server/services/tenant/index.ts b/src/core/server/services/tenant/index.ts index 8b3fe203b..b0eb33d66 100644 --- a/src/core/server/services/tenant/index.ts +++ b/src/core/server/services/tenant/index.ts @@ -6,7 +6,10 @@ import { URL } from "url"; import { discover } from "coral-server/app/middleware/passport/strategies/oidc/discover"; import { Config } from "coral-server/config"; import { TenantInstalledAlreadyError } from "coral-server/errors"; -import { GQLSettingsInput } from "coral-server/graph/tenant/schema/__generated__/types"; +import { + GQLSettingsInput, + GQLSettingsWordListInput, +} from "coral-server/graph/tenant/schema/__generated__/types"; import logger from "coral-server/logger"; import { createTenant, @@ -21,6 +24,20 @@ import TenantCache from "./cache"; export type UpdateTenant = GQLSettingsInput; +function cleanWordList( + list: GQLSettingsWordListInput +): GQLSettingsWordListInput { + if (list.banned) { + list.banned = list.banned.filter(Boolean); + } + + if (list.suspect) { + list.suspect = list.suspect.filter(Boolean); + } + + return list; +} + export async function update( mongo: Db, redis: Redis, @@ -39,6 +56,12 @@ export async function update( delete input.live.enabled; } + // If the word list was specified, we should validate it to ensure there isn't + // any empty spaces. + if (input.wordList) { + input.wordList = cleanWordList(input.wordList); + } + const updatedTenant = await updateTenant(mongo, tenant.id, input); if (!updatedTenant) { return null;