Skip to content

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

TypeScript

fix(gfs): separate ingress backstop from operation quotas

Alfredo Lopez415455b02d4e
diff --git a/control-api/src/config.ts b/control-api/src/config.ts
index 7d2c353a9..9d64f357f 100644
--- a/control-api/src/config.ts
+++ b/control-api/src/config.ts
@@ -133,9 +133,14 @@ type Config = {
approvalRlExternalPerMin: number
oauthBrokerRlPerMin: number
adminPublicTokenRlPerMin: number
- // External Desktop GFS is a separate authority plane. These values are the
- // approved fixed budgets for its pre-resolution and resolved-operation gates.
+ // External Desktop GFS is a separate authority plane. The process-local
+ // ingress backstop is intentionally wider than the distributed operation
+ // buckets so normal Desktop read waterfalls cannot consume the security
+ // budgets before authority resolution. The narrower values remain the
+ // authoritative per-user/IP/actor operation ceilings.
+ externalGfsIngressRlPerMin: number
externalGfsTokenUserRlPerMin: number
+ externalGfsTokenIpRlPerMin: number
externalGfsIpRlPerMin: number
externalGfsOperationRlPerMin: number
// Stateless-agent wake endpoint: per-host wake rate limit + server-side
@@ -734,9 +739,12 @@ export const config: Config = {
oauthBrokerRlPerMin: Number(process.env.CONTROL_API_OAUTH_BROKER_RL_PER_MIN || 60),
adminPublicTokenRlPerMin: Number(process.env.CONTROL_API_ADMIN_PUBLIC_TOKEN_RL_PER_MIN || 20),
// Approved GFS authority-boundary budgets. Keep them fixed here rather than
- // accepting an unreviewed environment override: token minting is 10/min per
- // Desktop user and 30/min per source IP; every other operation class is 30/min.
+ // accepting an unreviewed environment override. The 1800/min ingress guard
+ // is only a coarse process-local backstop; token/user, token/IP, operation/IP,
+ // and resolved session/actor buckets remain independently bounded below.
+ externalGfsIngressRlPerMin: 1_800,
externalGfsTokenUserRlPerMin: 10,
+ externalGfsTokenIpRlPerMin: 600,
externalGfsIpRlPerMin: 30,
externalGfsOperationRlPerMin: 30,
// Default derived from the wake mechanism's worst case, not picked ad hoc.
diff --git a/control-api/src/middleware/externalGfsRateLimit.ts b/control-api/src/middleware/externalGfsRateLimit.ts
index 841092b0d..ea941ff81 100644
--- a/control-api/src/middleware/externalGfsRateLimit.ts
+++ b/control-api/src/middleware/externalGfsRateLimit.ts
@@ -272,7 +272,7 @@ export function externalGfsPreResolutionRateLimit(
},
{
key: `gfs-ext:pre:token:ip:${sourceIpDigest(req)}`,
- maxPerMinute: config.externalGfsIpRlPerMin,
+ maxPerMinute: config.externalGfsTokenIpRlPerMin,
},
]
: [
diff --git a/control-api/src/routes/external/gfs.ts b/control-api/src/routes/external/gfs.ts
index df8a85bb6..7f425470c 100644
--- a/control-api/src/routes/external/gfs.ts
+++ b/control-api/src/routes/external/gfs.ts
@@ -253,13 +253,16 @@ export function createExternalGfsRouter(): Router {
const router = Router()
// The durable externalGfs* guards below are the authoritative distributed
- // limiter. These direct express-rate-limit guards intentionally mirror the
- // approved quotas at the routing boundary so static analysis can prove that
- // every auth/authority/handler path is metered. They keep no response quota
- // headers: the distributed guard owns the externally forwarded values.
+ // limiter. These direct express-rate-limit guards provide a recognisable
+ // routing-boundary backstop so static analysis can prove every
+ // auth/authority/handler path is metered. The all-route ingress guard is
+ // deliberately wider than the product quotas; the per-class guards and
+ // distributed buckets retain the narrower security budgets. They keep no
+ // response quota headers: the distributed guard owns the externally
+ // forwarded values.
const externalGfsIngressRateLimit = rateLimit({
windowMs: 60_000,
- limit: config.externalGfsIpRlPerMin,
+ limit: config.externalGfsIngressRlPerMin,
standardHeaders: false,
legacyHeaders: false,
keyGenerator: externalGfsIngressRateKey,
diff --git a/control-api/test/middleware.externalGfsRateLimit.test.ts b/control-api/test/middleware.externalGfsRateLimit.test.ts
index 28fa5e56e..75938ab89 100644
--- a/control-api/test/middleware.externalGfsRateLimit.test.ts
+++ b/control-api/test/middleware.externalGfsRateLimit.test.ts
@@ -20,7 +20,9 @@ const logger = vi.hoisted(() => ({
vi.mock('../src/config.js', () => ({
config: {
+ externalGfsIngressRlPerMin: 1800,
externalGfsTokenUserRlPerMin: 10,
+ externalGfsTokenIpRlPerMin: 600,
externalGfsIpRlPerMin: 30,
externalGfsOperationRlPerMin: 30,
},
@@ -227,7 +229,7 @@ describe('external GFS rate boundary', () => {
expect(handler).not.toHaveBeenCalled()
})
- it('enforces the fixed 30/min source-IP ceiling after an allowed token user bucket', async () => {
+ it('enforces the fixed 600/min token source-IP ceiling after an allowed token user bucket', async () => {
checkAndIncrement.mockResolvedValueOnce(allowed(9)).mockResolvedValueOnce(denied())
const { app, resolver, handler } = buildApp()
@@ -236,7 +238,7 @@ describe('external GFS rate boundary', () => {
.set('x-user-session-token', 'session-one')
expect(response.status).toBe(429)
- expect(response.headers['x-ratelimit-limit']).toBe('30')
+ expect(response.headers['x-ratelimit-limit']).toBe('600')
expect(checkAndIncrement).toHaveBeenNthCalledWith(
1,
`gfs-ext:pre:token:user:${DESKTOP_USER_ID}`,
@@ -245,7 +247,7 @@ describe('external GFS rate boundary', () => {
expect(checkAndIncrement).toHaveBeenNthCalledWith(
2,
expect.stringMatching(/^gfs-ext:pre:token:ip:[0-9a-f]{64}$/),
- 30
+ 600
)
expect(resolver).not.toHaveBeenCalled()
expect(handler).not.toHaveBeenCalled()
@@ -266,7 +268,7 @@ describe('external GFS rate boundary', () => {
expect(checkAndIncrement).toHaveBeenNthCalledWith(
2,
`gfs-ext:pre:token:ip:${clientIpDigest}`,
- 30
+ 600
)
})
diff --git a/control-api/test/routes.externalGfs.test.ts b/control-api/test/routes.externalGfs.test.ts
index b86f82a84..8f029a104 100644
--- a/control-api/test/routes.externalGfs.test.ts
+++ b/control-api/test/routes.externalGfs.test.ts
@@ -38,7 +38,9 @@ vi.mock('../src/config.js', () => ({
// The eligibility guard maps caller agent names to 1st:<hostsNamespace>/<name>.
hostsNamespace: 'mcp-host',
desktopGfsOperatorLinkingEnabled: false,
+ externalGfsIngressRlPerMin: 1800,
externalGfsTokenUserRlPerMin: 10,
+ externalGfsTokenIpRlPerMin: 600,
externalGfsIpRlPerMin: 30,
externalGfsOperationRlPerMin: 30,
},
@@ -231,27 +233,51 @@ function dbReturning(
}
describe('POST /external/gfs/token (user mint — existing signer, sub=users.id)', () => {
- it('enforces the recognised ingress limit before session authentication or authority resolution', async () => {
+ it('allows a mixed GFS journey beyond the former 30/min ingress cap', async () => {
auth()
const app = await buildApp()
- for (let attempt = 0; attempt < 30; attempt += 1) {
+ for (let attempt = 0; attempt < 31; attempt += 1) {
const response = await request(app)
.post('/external/gfs/not-classified')
.set('x-user-session-token', 'sess')
expect(response.status).toBe(404)
}
- const exhausted = await request(app)
- .post('/external/gfs/not-classified')
- .set('x-user-session-token', 'sess')
-
- expect(exhausted.status).toBe(429)
- expect(mockVerifyExternalSessionToken).toHaveBeenCalledTimes(30)
+ expect(mockVerifyExternalSessionToken).toHaveBeenCalledTimes(31)
expect(mockResolveActiveLink).not.toHaveBeenCalled()
expect(mockQuery).not.toHaveBeenCalled()
})
+ it('enforces the configurable ingress backstop before session or authority work', async () => {
+ const previousIngressLimit = (config as { externalGfsIngressRlPerMin: number })
+ .externalGfsIngressRlPerMin
+ ;(config as { externalGfsIngressRlPerMin: number }).externalGfsIngressRlPerMin = 3
+ try {
+ auth()
+ const app = await buildApp()
+
+ for (let attempt = 0; attempt < 3; attempt += 1) {
+ const response = await request(app)
+ .post('/external/gfs/not-classified')
+ .set('x-user-session-token', 'sess')
+ expect(response.status).toBe(404)
+ }
+
+ const exhausted = await request(app)
+ .post('/external/gfs/not-classified')
+ .set('x-user-session-token', 'sess')
+
+ expect(exhausted.status).toBe(429)
+ expect(mockVerifyExternalSessionToken).toHaveBeenCalledTimes(3)
+ expect(mockResolveActiveLink).not.toHaveBeenCalled()
+ expect(mockQuery).not.toHaveBeenCalled()
+ } finally {
+ ;(config as { externalGfsIngressRlPerMin: number }).externalGfsIngressRlPerMin =
+ previousIngressLimit
+ }
+ })
+
it('enforces the recognised 10/min token route limit per authenticated user', async () => {
auth()
const app = await buildApp()