Skip to content

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

TypeScript

fix(control-api): stop a non-string credential from 500ing the provider-transition guard

Jose Ramirezc99bdc8027ab
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/routes/admin/resources.ts b/control-api/src/routes/admin/resources.ts
index df401f419..ed3260924 100644
--- a/control-api/src/routes/admin/resources.ts
+++ b/control-api/src/routes/admin/resources.ts
@@ -269,8 +269,13 @@ async function providerTransitionError(
// Trimmed, because this reads the RAW envelope while the Secret is written
// from the CLEANED values: `validateCommunicationChannelCredentials` drops
// whitespace-only entries, so a truthy " " here would satisfy the guard
- // and then never reach the Secret.
- if (!credentials?.[key]?.trim() && !existingKeys.includes(key)) {
+ // and then never reach the Secret. A present-but-non-string value (e.g. a
+ // number) is NOT "missing" though: it's `validateCommunicationChannelCredentials`
+ // below that owns rejecting the wrong type with its own 400, so this only
+ // calls `.trim()` once `typeof` has confirmed there's a string to trim.
+ const rawValue = credentials?.[key]
+ const isMissing = rawValue === undefined || (typeof rawValue === 'string' && !rawValue.trim())
+ if (isMissing && !existingKeys.includes(key)) {
return `credentials["${key}"] is required to enable the ${provider} provider on this CommunicationChannel`
}
}
diff --git a/control-api/test/routes.providerTransition.test.ts b/control-api/test/routes.providerTransition.test.ts
index 5e87a1a89..58914f71f 100644
--- a/control-api/test/routes.providerTransition.test.ts
+++ b/control-api/test/routes.providerTransition.test.ts
@@ -126,6 +126,25 @@ describe('admin communicationchannels — provider transition validation (#312)'
expect(gatewayMock.createSecret).not.toHaveBeenCalled()
})
+ it('POST declaring email with a numeric (non-string) credential value → 400 from validation, not a 500', async () => {
+ // providerTransitionError runs before validateCommunicationChannelCredentials
+ // and reads the raw, untrusted body. A bare `credentials?.[key]?.trim()` call
+ // throws on a non-string value ("... .trim is not a function"), turning this
+ // into an unhandled 500 instead of the ordinary validation 400.
+ const res = await request(makeApp())
+ .post('/admin/communicationchannels')
+ .send({
+ metadata: { name: 'jose-email' },
+ spec: { hostRef: 'h1', email: [{ emails: ['[email protected]'] }] },
+ credentials: { 'email-username': 123, 'email-password': 'pw' },
+ })
+
+ expect(res.status).toBe(400)
+ expect(res.body.error).toBe('credentials["email-username"] must be a string')
+ expect(gatewayMock.createResource).not.toHaveBeenCalled()
+ expect(gatewayMock.createSecret).not.toHaveBeenCalled()
+ })
+
// ── ALLOWING ─────────────────────────────────────────────────────────────
// Without these, a validator that reads nothing at all still passes every
// blocking case above.