Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🐛 Harden LicenseManager and AI moderation external calls (#2608)

Luke Vella996b973d9269
diff --git a/apps/web/src/features/licensing/mutations.ts b/apps/web/src/features/licensing/mutations.ts
index 7f8f26e76..edb501bd1 100644
--- a/apps/web/src/features/licensing/mutations.ts
+++ b/apps/web/src/features/licensing/mutations.ts
@@ -16,6 +16,8 @@ import { AppError } from "@/lib/errors/app-error";
const logger = createLogger("licensing/manager");
+const REQUEST_TIMEOUT_MS = 30_000;
+
export class LicenseManager {
apiUrl: string;
authToken?: string;
@@ -42,6 +44,7 @@ export class LicenseManager {
Authorization: `Bearer ${this.authToken}`,
},
body: JSON.stringify(input),
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
});
if (!res.ok) {
@@ -56,11 +59,17 @@ export class LicenseManager {
"Content-Type": "application/json",
},
body: JSON.stringify(input),
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
});
- const data = await res.json();
-
if (!res.ok) {
+ const text = await res.text();
+ let data: unknown = text;
+ try {
+ data = JSON.parse(text);
+ } catch {
+ // Non-JSON error response (e.g. HTML from a proxy) — keep raw text
+ }
logger.error({ data }, "License validation failed");
throw new AppError({
code: "INTERNAL_SERVER_ERROR",
@@ -69,7 +78,7 @@ export class LicenseManager {
});
}
- return validateLicenseKeyResponseSchema.parse(data);
+ return validateLicenseKeyResponseSchema.parse(await res.json());
}
}
diff --git a/apps/web/src/features/moderation/mutations.ts b/apps/web/src/features/moderation/mutations.ts
index 955968a8a..175fc414b 100644
--- a/apps/web/src/features/moderation/mutations.ts
+++ b/apps/web/src/features/moderation/mutations.ts
@@ -13,6 +13,8 @@ import { containsSuspiciousPatterns } from "./utils";
const logger = createLogger("moderation");
const aiLogger = createLogger("moderation/ai");
+const AI_REQUEST_TIMEOUT_MS = 30_000;
+
/**
* Moderates content using AI to detect inappropriate content
* @param text The text to moderate
@@ -22,6 +24,7 @@ async function moderateContentWithAI(text: string): Promise<ModerationResult> {
try {
const result = await generateText({
model: openai("gpt-4.1"),
+ abortSignal: AbortSignal.timeout(AI_REQUEST_TIMEOUT_MS),
messages: [
{
role: "system",
@@ -55,7 +58,7 @@ Brief explanation of why this verdict was chosen.`,
const reason = lines.slice(1).join("\n").trim() || "No reason provided";
let verdict: ModerationVerdict = "safe";
- if (verdictLine.includes("FLAGGED")) {
+ if (verdictLine.startsWith("FLAGGED")) {
verdict = "flagged";
}