Skip to content

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

TypeScript

fix: sanitize password mutation internal responses

Josué41af864cc77d
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 5b1803ccc..addda9e45 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.784",
+ "version": "0.1.785",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.784",
+ "version": "0.1.785",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",
diff --git a/control-api/package.json b/control-api/package.json
index 7a3d9faae..3d2fc31f1 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.784",
+ "version": "0.1.785",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/src/http/errorHandler.ts b/control-api/src/http/errorHandler.ts
index 1af0d79b0..1af2d3a1f 100644
--- a/control-api/src/http/errorHandler.ts
+++ b/control-api/src/http/errorHandler.ts
@@ -1,6 +1,7 @@
import type { NextFunction, Request, Response } from 'express'
import { ApiException } from '@kubernetes/client-node'
import { STATUS_CODES } from 'node:http'
+import { clearRateLimitHeaders } from '../middleware/rateLimitMiddleware.js'
import { rootLogger } from '../observability/logger.js'
import { PasswordMutationInternalError } from '../services/auth/passwordAdmissionError.js'
import { memberRegistrationErrorResponse } from '../services/memberRegistrationErrors.js'
@@ -160,6 +161,9 @@ export function clerumErrorHandler(
const log = req.log ?? rootLogger
if (err instanceof PasswordMutationInternalError) {
+ clearRateLimitHeaders(res)
+ res.removeHeader('Retry-After')
+ res.setHeader('Cache-Control', 'no-store')
res.status(500).json({ error: err.code, correlationId })
return
}
diff --git a/control-api/test/http.errorHandler.passwordInternalError.test.ts b/control-api/test/http.errorHandler.passwordInternalError.test.ts
new file mode 100644
index 000000000..db11175e5
--- /dev/null
+++ b/control-api/test/http.errorHandler.passwordInternalError.test.ts
@@ -0,0 +1,48 @@
+import { describe, expect, it } from 'vitest'
+import express from 'express'
+import request from 'supertest'
+import { clerumErrorHandler } from '../src/http/errorHandler.js'
+import { correlationIdMiddleware } from '../src/middleware/correlationId.js'
+import { PasswordMutationInternalError } from '../src/services/auth/passwordAdmissionError.js'
+
+function appThrowingPasswordMutationInternalError() {
+ const app = express()
+ app.use(correlationIdMiddleware)
+ app.post('/boom', (_req, res, next) => {
+ res.set({
+ 'RateLimit-Limit': '10',
+ 'RateLimit-Remaining': '9',
+ 'RateLimit-Policy': '10;w=60',
+ 'X-RateLimit-Limit': '10',
+ 'X-RateLimit-Remaining': '9',
+ 'X-RateLimit-Reset': '1776000000',
+ 'Retry-After': '30',
+ })
+ next(new PasswordMutationInternalError())
+ })
+ app.use(clerumErrorHandler)
+ return app
+}
+
+describe('clerumErrorHandler password mutation internal response', () => {
+ it('clears inherited rate metadata and marks the sanitized 500 as non-cacheable', async () => {
+ const correlationId = '0f1056c1-0f18-4818-8183-000000000085'
+ const response = await request(appThrowingPasswordMutationInternalError())
+ .post('/boom')
+ .set('x-correlation-id', correlationId)
+
+ expect(response.status).toBe(500)
+ expect(response.body).toEqual({
+ error: 'internal_error',
+ correlationId,
+ })
+ expect(response.headers['cache-control']).toBe('no-store')
+ expect(response.headers['retry-after']).toBeUndefined()
+ expect(response.headers['ratelimit-limit']).toBeUndefined()
+ expect(response.headers['ratelimit-remaining']).toBeUndefined()
+ expect(response.headers['ratelimit-policy']).toBeUndefined()
+ expect(response.headers['x-ratelimit-limit']).toBeUndefined()
+ expect(response.headers['x-ratelimit-remaining']).toBeUndefined()
+ expect(response.headers['x-ratelimit-reset']).toBeUndefined()
+ })
+})