Add another validity filter

This commit is contained in:
Ajay
2025-04-25 12:55:44 -04:00
parent 9f745d3a8b
commit 0d005c23bf
5 changed files with 26 additions and 4 deletions

View File

@@ -108,12 +108,32 @@ export async function canSubmit(userID: HashedUserID, category: Category): Promi
}
}
export function validSubmittedData(userAgent: string): boolean {
export function validSubmittedData(userAgent: string, userAgentR: string): boolean {
if (!config.validityCheck.userAgent) {
return true;
}
return !new RegExp(config.validityCheck.userAgent).test(userAgent);
for (const key of Object.keys(config.validityCheck)) {
const check = (config.validityCheck as Record<string, string | null>)[key];
if (check === null) {
continue;
} else {
switch (key) {
case "userAgent":
if (!userAgent.match(check)) {
return false;
}
break;
case "userAgentR":
if (!userAgentR.match(new RegExp(check))) {
return false;
}
break;
}
}
}
return true;
}
export async function canSubmitGlobal(userID: HashedUserID): Promise<CanSubmitGlobalResult> {