Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(gfs): resolve CodeQL alerts on the legacy-standalone report route

Alfredo Lopezf2dfeb080ea6
diff --git a/control-api/src/routes/gfs/legacyStandaloneGrants.ts b/control-api/src/routes/gfs/legacyStandaloneGrants.ts
index 1a462c880..9abe85b03 100644
--- a/control-api/src/routes/gfs/legacyStandaloneGrants.ts
+++ b/control-api/src/routes/gfs/legacyStandaloneGrants.ts
@@ -2,6 +2,7 @@ import type { Request, Response, Router } from 'express'
import { pool } from '../../db.js'
import { asyncHandler } from '../../http/asyncHandler.js'
import { requireAuthForControlUI } from '../../middleware/controlUIAuth.js'
+import { rateLimitMiddleware } from '../../middleware/rateLimitMiddleware.js'
export const LEGACY_STANDALONE_HOST_SUBJECT_ID = '1st:mcp-host/standalone'
const LEGACY_GRANT_REPORT_LIMIT = 1000
@@ -57,9 +58,22 @@ export async function handleLegacyStandaloneGrantReport(
}
export function registerLegacyStandaloneGrantReportRoute(router: Router): void {
+ // Per-admin token bucket mirroring the sibling /gfs/grants surfaces
+ // (grants.ts): auth runs first, so adminAuth.sub is present when the limiter
+ // keys. A dedicated bucket keeps this read-only migration report from
+ // consuming the grant-mutation budget while still bounding operator polling.
+ const legacyGrantReportRateLimit = rateLimitMiddleware({
+ bucketType: 'gfs_grants_legacy_report',
+ maxPerMinute: 30,
+ getBucketKey: req => {
+ const sub = (req as { adminAuth?: { sub?: string } }).adminAuth?.sub
+ return sub ? `gfsgrants-legacy:${sub}` : null
+ },
+ })
router.get(
'/gfs/grants/legacy-standalone',
requireAuthForControlUI,
+ legacyGrantReportRateLimit,
asyncHandler(handleLegacyStandaloneGrantReport)
)
}
diff --git a/control-api/test/gfsResources.routeTransaction.test.ts b/control-api/test/gfsResources.routeTransaction.test.ts
index de4da6820..b1f0e63a9 100644
--- a/control-api/test/gfsResources.routeTransaction.test.ts
+++ b/control-api/test/gfsResources.routeTransaction.test.ts
@@ -1,7 +1,6 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
const FILE = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
-const SRC = 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'
const OTHER = 'dddddddd-dddd-dddd-dddd-dddddddddddd'
const state = vi.hoisted(() => {