Skip to content

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

TypeScript

fix: expose sdk rate limits to static analysis

Alfredo Lopez1b9c19f1778a
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 7f6c63bb9..847978bcb 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.403",
+ "version": "0.1.404",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.403",
+ "version": "0.1.404",
"dependencies": {
"@clerum/image-policy": "file:../packages/image-policy",
"@clerum/llm-providers": "file:../packages/llm-providers",
diff --git a/control-api/package.json b/control-api/package.json
index 8f26f28d7..27316108c 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.403",
+ "version": "0.1.404",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/src/middleware/pluginWorkloadSdkRateLimits.ts b/control-api/src/middleware/pluginWorkloadSdkRateLimits.ts
index e38a5aed1..cf1f7434c 100644
--- a/control-api/src/middleware/pluginWorkloadSdkRateLimits.ts
+++ b/control-api/src/middleware/pluginWorkloadSdkRateLimits.ts
@@ -1,23 +1,6 @@
import type { RequestHandler } from 'express'
-import { rateLimit } from 'express-rate-limit'
import { rateLimitMiddleware } from './rateLimitMiddleware.js'
-/**
- * High-ceiling IP guard placed before mcp-host/internal JWT verification.
- * Business quotas and the authenticated recipe limiter remain separate: this
- * layer only bounds unauthenticated crypto work (the outer app owns the JSON
- * body-size/parser boundary).
- */
-export function createPluginWorkloadSdkPreAuthRateLimit(): RequestHandler {
- return rateLimit({
- windowMs: 60_000,
- limit: 600,
- standardHeaders: 'draft-8',
- legacyHeaders: false,
- message: { error: 'Too Many Requests', retryable: true },
- })
-}
-
/**
* Distributed recipe-scoped guard for all authenticated SDK gateway routes.
* The pre-auth IP limiter cannot provide caller isolation, while this PG
diff --git a/control-api/src/routes/internal/pluginWorkloadSdk.ts b/control-api/src/routes/internal/pluginWorkloadSdk.ts
index cec9d1112..0cee68cb6 100644
--- a/control-api/src/routes/internal/pluginWorkloadSdk.ts
+++ b/control-api/src/routes/internal/pluginWorkloadSdk.ts
@@ -1,10 +1,8 @@
import { Router } from 'express'
+import { rateLimit } from 'express-rate-limit'
import { asyncHandler } from '../../http/asyncHandler.js'
import { requireInternalControlJwt } from '../../middleware/internalControlJwt.js'
-import {
- createPluginWorkloadSdkInternalRateLimit,
- createPluginWorkloadSdkPreAuthRateLimit,
-} from '../../middleware/pluginWorkloadSdkRateLimits.js'
+import { createPluginWorkloadSdkInternalRateLimit } from '../../middleware/pluginWorkloadSdkRateLimits.js'
import {
type PluginWorkloadSdkRevocationActor,
finalizePluginWorkloadSdkRevocation,
@@ -59,7 +57,13 @@ export function createInternalPluginWorkloadSdkRouter(): Router {
// the prefix so every current/future internal SDK route inherits the guard.
router.use(
'/internal/plugin-workload-sdk',
- createPluginWorkloadSdkPreAuthRateLimit(),
+ rateLimit({
+ windowMs: 60_000,
+ limit: 600,
+ standardHeaders: 'draft-8',
+ legacyHeaders: false,
+ message: { error: 'Too Many Requests', retryable: true },
+ }),
requireInternalControlJwt,
createPluginWorkloadSdkInternalRateLimit()
)
diff --git a/control-api/src/routes/mcp-host/plugin-workload-sdk.routes.ts b/control-api/src/routes/mcp-host/plugin-workload-sdk.routes.ts
index 788833fc6..cdc6b270c 100644
--- a/control-api/src/routes/mcp-host/plugin-workload-sdk.routes.ts
+++ b/control-api/src/routes/mcp-host/plugin-workload-sdk.routes.ts
@@ -1,11 +1,9 @@
import { type Request, type Response, Router } from 'express'
+import { rateLimit } from 'express-rate-limit'
import { pool } from '../../db.js'
import { asyncHandler } from '../../http/asyncHandler.js'
import { requireMcpHostJwt } from '../../middleware/mcpHostJwtAuth.js'
-import {
- createPluginWorkloadSdkPreAuthRateLimit,
- createPluginWorkloadSdkRequestRateLimit,
-} from '../../middleware/pluginWorkloadSdkRateLimits.js'
+import { createPluginWorkloadSdkRequestRateLimit } from '../../middleware/pluginWorkloadSdkRateLimits.js'
import { rateLimitMiddleware } from '../../middleware/rateLimitMiddleware.js'
import { pluginWorkloadSdkNotificationAuthDurationSeconds } from '../../observability/metrics.js'
import { enqueuePluginWorkloadSdkNotification } from '../../services/notificationEmitter.js'
@@ -520,7 +518,13 @@ export function createMcpHostPluginWorkloadSdkRoutes(): Router {
// recipe-scoped PG limiter (the outer app bounds JSON bodies).
router.use(
'/mcp-host/plugin-workload-sdk',
- createPluginWorkloadSdkPreAuthRateLimit(),
+ rateLimit({
+ windowMs: 60_000,
+ limit: 600,
+ standardHeaders: 'draft-8',
+ legacyHeaders: false,
+ message: { error: 'Too Many Requests', retryable: true },
+ }),
requireMcpHostJwt,
createPluginWorkloadSdkRequestRateLimit()
)
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index 3b8562910..d5ca0ce21 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.223",
+ "version": "0.1.224",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.223",
+ "version": "0.1.224",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@anthropic-ai/sdk": "^0.32.0",
diff --git a/mcp-host/package.json b/mcp-host/package.json
index def3b13e6..96e8015ee 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.223",
+ "version": "0.1.224",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --git a/mcp-host/src/pluginWorkloadSdk/bootstrapServer.ts b/mcp-host/src/pluginWorkloadSdk/bootstrapServer.ts
index 440c806ce..731f9004e 100644
--- a/mcp-host/src/pluginWorkloadSdk/bootstrapServer.ts
+++ b/mcp-host/src/pluginWorkloadSdk/bootstrapServer.ts
@@ -1,6 +1,6 @@
import express, { type NextFunction, type Request, type Response } from 'express'
+import { rateLimit } from 'express-rate-limit'
import type http from 'node:http'
-import { createMcpHostPreAuthRateLimit } from '../shared/httpRateLimit'
import type { ConfigureResponse, PluginWorkloadSdkBootstrapRequest } from '../workflow/types'
import {
requireWorkflowAuth,
@@ -36,7 +36,16 @@ export class PluginWorkloadSdkBootstrapServer {
// Bound invalid-token floods before Express parses request bodies. Scope
// this guard to bootstrap so liveness/readiness cannot be starved by an
// attacker exhausting an unrelated control bucket.
- this.app.use('/api/v1/workflow/plugin-workload-sdk/bootstrap', createMcpHostPreAuthRateLimit())
+ this.app.use(
+ '/api/v1/workflow/plugin-workload-sdk/bootstrap',
+ rateLimit({
+ windowMs: 60_000,
+ limit: 600,
+ standardHeaders: 'draft-8',
+ legacyHeaders: false,
+ message: { error: 'Too Many Requests', retryable: true },
+ })
+ )
this.app.use(express.json({ limit: '16kb' }))
this.app.get('/v1/runtime/health', (_req, res) => {
res.status(200).json({ status: 'healthy', mode: 'sdk-only', ready: true })
diff --git a/mcp-host/src/shared/httpRateLimit.ts b/mcp-host/src/shared/httpRateLimit.ts
deleted file mode 100644
index e8643ab59..000000000
--- a/mcp-host/src/shared/httpRateLimit.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import { rateLimit } from 'express-rate-limit'
-
-/**
- * Protects the HTTP boundary before JWT verification and body parsing.
- *
- * The authenticated, recipe-scoped limiters remain responsible for product
- * quotas. This limiter has a deliberately higher IP ceiling: its only job is
- * to bound unauthenticated crypto/body-parser work and prevent a caller from
- * bypassing the per-principal controls by rotating invalid tokens.
- */
-export function createMcpHostPreAuthRateLimit() {
- return rateLimit({
- windowMs: 60_000,
- limit: 600,
- standardHeaders: 'draft-8',
- legacyHeaders: false,
- message: { error: 'Too Many Requests', retryable: true },
- })
-}
diff --git a/mcp-host/src/workflow/workflowRouter.ts b/mcp-host/src/workflow/workflowRouter.ts
index 5bc9f8bc1..4fa455079 100644
--- a/mcp-host/src/workflow/workflowRouter.ts
+++ b/mcp-host/src/workflow/workflowRouter.ts
@@ -13,9 +13,9 @@
* Source of truth: STAGE-1-CRD-TWO-POD-FOUNDATION.md §4.7
*/
import { NextFunction, Request, Response, Router } from 'express'
+import { rateLimit } from 'express-rate-limit'
import * as fs from 'fs'
import * as path from 'path'
-import { createMcpHostPreAuthRateLimit } from '../shared/httpRateLimit'
import {
ArtifactPathError,
type OpenedArtifactFile,
@@ -100,7 +100,15 @@ export function createWorkflowRouter(service: WorkflowService): Router {
// control-plane guard, while this high-ceiling IP bucket prevents
// unauthenticated floods from making token verification the expensive
// denial path.
- router.use(createMcpHostPreAuthRateLimit())
+ router.use(
+ rateLimit({
+ windowMs: 60_000,
+ limit: 600,
+ standardHeaders: 'draft-8',
+ legacyHeaders: false,
+ message: { error: 'Too Many Requests', retryable: true },
+ })
+ )
// POST /execute — execute a single step (requires scope: execute, sub: coordinator)
router.post('/execute', requireWorkflowAuth('execute'), async (req: Request, res: Response) => {