Skip to content

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

TypeScript

fix(control-api): reject invalid Secret key names with 400, not an opaque 500

Alfredo Lopezf383e92f246b
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 1bf20ca32..72203d2f3 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.393",
+ "version": "0.1.394",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.393",
+ "version": "0.1.394",
"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 1376f982e..f30245741 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.393",
+ "version": "0.1.394",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/src/routes/admin/secrets.ts b/control-api/src/routes/admin/secrets.ts
index c6c1a7ffa..723c22da4 100644
--- a/control-api/src/routes/admin/secrets.ts
+++ b/control-api/src/routes/admin/secrets.ts
@@ -388,6 +388,15 @@ export function createAdminSecretsRouter(gateway: K8sGateway): Router {
return
}
for (const [key, val] of Object.entries(data)) {
+ // A Kubernetes Secret data key must be [-._a-zA-Z0-9]+. Reject an
+ // invalid key with a clear 400 up front instead of letting the apiserver
+ // refuse the patch as an opaque 500 the operator can't act on.
+ if (!/^[A-Za-z0-9_.-]+$/.test(key)) {
+ res.status(400).json({
+ error: `data key "${key}" is not a valid Secret key (only letters, digits, '-', '_', '.')`,
+ })
+ return
+ }
if (typeof val !== 'string') {
res.status(400).json({ error: `data["${key}"] must be a string` })
return
diff --git a/control-api/test/routes.mcpSecrets.test.ts b/control-api/test/routes.mcpSecrets.test.ts
index 569ae3b82..9d6d311b3 100644
--- a/control-api/test/routes.mcpSecrets.test.ts
+++ b/control-api/test/routes.mcpSecrets.test.ts
@@ -600,6 +600,22 @@ describe('PUT /admin/mcp-secrets/:name (credential rotation, issue #223)', () =>
expect(gateway.mergeSecret).not.toHaveBeenCalled()
})
+ it('rejects an invalid Secret key name with a 400, not an opaque apiserver 500', async () => {
+ const gateway = createGateway()
+ const app = makeApp(gateway)
+
+ // A key with a space (or any char outside [-._a-zA-Z0-9]) can never be a
+ // valid Secret data key. Catching it here returns an actionable 400 rather
+ // than letting the apiserver reject the merge as a 500 the operator can't act on.
+ const res = await request(app)
+ .put('/admin/mcp-secrets/linear-credentials')
+ .send({ data: { 'bad key': 'value' } })
+ .expect(400)
+
+ expect(res.body.error).toContain('not a valid Secret key')
+ expect(gateway.mergeSecret).not.toHaveBeenCalled()
+ })
+
// ── Gateway failure ──────────────────────────────────────────────────────
it('still returns 200 when listing connectors fails AFTER a successful merge (M1)', async () => {