Submatter/apps/worker/src/tools/allowlist.ts

12 lines
492 B
TypeScript
Raw Normal View History

import { ALLOWED_COMMANDS } from "@tasks/shared/worker";
export function isAllowedCommand(
command: string,
allowedCommands?: readonly string[] | null,
): boolean {
const allowList = allowedCommands === undefined || allowedCommands === null ? ALLOWED_COMMANDS : allowedCommands;
if (allowList.length === 0) return false;
const normalized = command.trim().replace(/\s+/g, " ");
return allowList.some((allowed) => normalized === allowed || normalized.startsWith(`${allowed} `));
}