Skip to content

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

TypeScript

fix(control-api): sanitize the non-production 500 client message (R1-M2)

Diego Zacarias1dd6090dce66
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index fe8a44aa0..e580496e1 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.438",
+ "version": "0.1.439",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.438",
+ "version": "0.1.439",
"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 8d342b02d..cde104553 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.438",
+ "version": "0.1.439",
"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 cc9ccac70..a5b7714b1 100644
--- a/control-api/src/http/errorHandler.ts
+++ b/control-api/src/http/errorHandler.ts
@@ -221,7 +221,12 @@ export function clerumErrorHandler(
if (process.env.NODE_ENV !== 'production') {
res.status(500).json({
error: 'Internal Server Error',
- message: err instanceof Error ? err.message : 'Unknown error',
+ // Sanitize the client-facing debug message the same way the 4xx branch
+ // does: a raw K8s ApiException `.message` embeds the metav1.Status body AND
+ // every apiserver header (Audit-Id, x-kubernetes-pf-*). A 5xx K8s error
+ // (etcd/apiserver down) is still an Error, so forwarding `err.message`
+ // verbatim here leaks those headers in dev/test.
+ message: clientErrorMessage(err, 500),
correlationId,
})
} else {
diff --git a/control-api/test/http.errorHandler.k8sStatus.test.ts b/control-api/test/http.errorHandler.k8sStatus.test.ts
index 28179f147..513dde373 100644
--- a/control-api/test/http.errorHandler.k8sStatus.test.ts
+++ b/control-api/test/http.errorHandler.k8sStatus.test.ts
@@ -122,6 +122,57 @@ describe('clerumErrorHandler — K8s status forwarding (UT-2a)', () => {
* same way the client body is: status + a safe message, never the headers or
* the raw `.message`.
*/
+ /**
+ * S1 follow-up (R1-M2, info disclosure to CLIENT on the 500 branch): the
+ * non-production 500 branch returns a debug `message` to the client. It used to
+ * forward `err.message` verbatim — but a K8s ApiException 5xx (etcd/apiserver
+ * down) is an Error whose `.message` embeds the metav1.Status body AND every
+ * apiserver header (Audit-Id, x-kubernetes-pf-*). So in dev/test the client got
+ * those headers. The 500 branch must sanitize the message the same way the 4xx
+ * branch does. Fixture derived from the real @kubernetes/client-node producer
+ * (T1), not a hand-built shape.
+ */
+ it('does NOT leak headers/audit-id on the non-production 500 branch for a real K8s ApiException 5xx', async () => {
+ const prev = process.env.NODE_ENV
+ process.env.NODE_ENV = 'development'
+ try {
+ const body = {
+ kind: 'Status',
+ apiVersion: 'v1',
+ status: 'Failure',
+ message: 'etcdserver: request timed out',
+ reason: 'ServiceUnavailable',
+ code: 503,
+ }
+ const headers = {
+ 'audit-id': 'a1b2c3-secret-audit-uuid',
+ 'x-kubernetes-pf-flowschema-uid': 'internal-flowschema-uid',
+ 'content-type': 'application/json',
+ }
+ const err = new ApiException(503, 'ServiceUnavailable', body, headers)
+
+ // Sanity: the real producer really does embed the leak in `.message`.
+ expect(err.message).toContain('Headers:')
+ expect(err.message).toContain('audit-id')
+
+ const res = await request(appThrowing(err)).get('/boom')
+ // 5xx never forwarded as the upstream status — collapses to 500.
+ expect(res.status).toBe(500)
+ expect(res.body.error).toBe('Internal Server Error')
+
+ const serialized = JSON.stringify(res.body)
+ expect(serialized).not.toContain('Headers:')
+ expect(serialized).not.toContain('audit-id')
+ expect(serialized).not.toContain('x-kubernetes-pf')
+ expect(serialized).not.toContain(err.message)
+ // A sanitized debug message still surfaces (the metav1.Status body.message,
+ // which carries no headers) so dev debuggability is preserved.
+ expect(res.body.message).toBe('etcdserver: request timed out')
+ } finally {
+ process.env.NODE_ENV = prev
+ }
+ })
+
it('does NOT log the raw ApiException message (headers/audit-id) for a forwarded 4xx', async () => {
const body = {
kind: 'Status',