From 2543ac8b11af11f034836591046cdb52911f9403 Mon Sep 17 00:00:00 2001 From: Elizabeth Alexander Hunt Date: Tue, 13 May 2025 09:50:15 -0700 Subject: snapshot --- utils/validate_identifier.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'utils/validate_identifier.ts') diff --git a/utils/validate_identifier.ts b/utils/validate_identifier.ts index e2a1dc5..ec8b77b 100644 --- a/utils/validate_identifier.ts +++ b/utils/validate_identifier.ts @@ -1,11 +1,17 @@ +import { Either } from "./mod.ts"; + export const validateIdentifier = (token: string) => { return (/^[a-zA-Z0-9_\-:. \/]+$/).test(token) && !token.includes(".."); }; -export const invalidExecutionEntriesOf = ( +// ensure {@param obj} is a Record with stuff that won't +// have the potential for shell injection, just to be super safe. +export const validateExecutionEntries = ( obj: Record, -): Array<[string, unknown]> => { - return Object.entries(obj).filter((e) => +): Either, Record> => { + const invalidEntries = Object.entries(obj).filter((e) => !e.every((x) => typeof x === "string" && validateIdentifier(x)) ); + if (invalidEntries.length > 0) return Either.left(invalidEntries); + return Either.right(> obj); }; -- cgit v1.2.3-70-g09d2