Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(auth): clear ACUC Redis cache when API keys are deleted (#3228)

firecrawl-spring[bot]0f5169d9ac09
diff --git a/apps/api/src/controllers/v0/admin/rotate-api-key.ts b/apps/api/src/controllers/v0/admin/rotate-api-key.ts
index 9e3fb1cf3..c96086aa9 100644
--- a/apps/api/src/controllers/v0/admin/rotate-api-key.ts
+++ b/apps/api/src/controllers/v0/admin/rotate-api-key.ts
@@ -5,6 +5,7 @@ import crypto from "crypto";
import { z } from "zod";
import { validate as isUuid } from "uuid";
import { parseApi, apiKeyToFcApiKey } from "../../../lib/parseApi";
+import { clearACUC } from "../../auth";
export async function integRotateApiKeyController(req: Request, res: Response) {
let logger = _logger.child({
@@ -119,7 +120,18 @@ export async function integRotateApiKeyController(req: Request, res: Response) {
if (deleteError) {
logger.error("Failed to delete leaked API key", { error: deleteError });
- logger.warn("Old API key may still be active", { oldKey: normalizedApiKey });
+ logger.warn("Old API key may still be active", {
+ oldKey: normalizedApiKey,
+ });
+ }
+
+ // Clear ACUC Redis cache so the deleted key stops authenticating immediately
+ try {
+ await clearACUC(normalizedApiKey);
+ } catch (cacheError) {
+ logger.warn("Failed to clear ACUC cache for rotated key", {
+ error: cacheError,
+ });
}
logger.info("Rotated API key", { teamId });
diff --git a/apps/api/src/controllers/v2/agent-signup-confirm.ts b/apps/api/src/controllers/v2/agent-signup-confirm.ts
index 43dd31444..9ae8ca839 100644
--- a/apps/api/src/controllers/v2/agent-signup-confirm.ts
+++ b/apps/api/src/controllers/v2/agent-signup-confirm.ts
@@ -267,6 +267,13 @@ export async function agentSignupBlockController(req: Request, res: Response) {
});
}
+ // Fetch the API key value before deletion so we can clear ACUC cache
+ const { data: apiKeyData } = await supabase_service
+ .from("api_keys")
+ .select("key")
+ .eq("id", sponsor.api_key_id)
+ .single();
+
// Disable the API key
const { error: deleteKeyError } = await supabase_service
.from("api_keys")
@@ -277,6 +284,17 @@ export async function agentSignupBlockController(req: Request, res: Response) {
logger.warn("Failed to delete agent API key", { error: deleteKeyError });
}
+ // Clear ACUC Redis cache so the deleted key stops authenticating immediately
+ if (apiKeyData) {
+ try {
+ await clearACUC(apiKeyData.key);
+ } catch (cacheError) {
+ logger.warn("Failed to clear ACUC cache for blocked agent key", {
+ error: cacheError,
+ });
+ }
+ }
+
// Ban the sandboxed team
const { error: banError } = await supabase_service
.from("teams")