Skip to content

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

TypeScript

fix(control-ui): support prototype-named credential keys

Jose Ramirez34ac518e735c
diff --git a/control-ui/components/UpdateConnectorCredentials/index.tsx b/control-ui/components/UpdateConnectorCredentials/index.tsx
index 4add91bcb..94157d68d 100644
--- a/control-ui/components/UpdateConnectorCredentials/index.tsx
+++ b/control-ui/components/UpdateConnectorCredentials/index.tsx
@@ -57,6 +57,33 @@ export const CLOCK_SKEW_TOLERANCE_MS = 5_000
// banner at the bottom of the form.
const VALIDATION_ERROR_ID = 'mcp-cred-validation-error'
+// Kubernetes permits Secret keys that overlap Object.prototype, including
+// __proto__, constructor, and toString. Credential drafts and request payloads
+// therefore cannot be ordinary objects: reading an untouched key must mean
+// "absent", never an inherited method or prototype value.
+type CredentialMap = Record<string, string>
+
+function emptyCredentialMap(): CredentialMap {
+ return Object.create(null) as CredentialMap
+}
+
+function ownCredentialValue(credentials: CredentialMap, secretKey: string): string | undefined {
+ return Object.hasOwn(credentials, secretKey) ? credentials[secretKey] : undefined
+}
+
+function withCredentialValue(
+ credentials: CredentialMap,
+ secretKey: string,
+ value: string
+): CredentialMap {
+ const next = emptyCredentialMap()
+ for (const key of Object.keys(credentials)) {
+ next[key] = credentials[key]
+ }
+ next[secretKey] = value
+ return next
+}
+
/** Stable per-key input id, shared by the label's `htmlFor` and the
* post-submit focus lookup. */
function inputId(secretKey: string): string {
@@ -100,7 +127,7 @@ export function UpdateConnectorCredentials({
const { showToast } = useToast()
const { confirm, confirmDialog } = useConfirmDialog()
- const [draft, setDraft] = useState<Record<string, string>>({})
+ const [draft, setDraft] = useState<CredentialMap>(emptyCredentialMap)
const [validationError, setValidationError] = useState('')
// The secretKeys the last submit rejected. Drives per-input `aria-invalid` /
// `aria-describedby`, so the aggregate alert is not the ONLY way to learn
@@ -318,7 +345,7 @@ export function UpdateConnectorCredentials({
}
function updateField(secretKey: string, value: string) {
- setDraft(prev => ({ ...prev, [secretKey]: value }))
+ setDraft(prev => withCredentialValue(prev, secretKey, value))
if (validationError) setValidationError('')
// The alert the inputs point at is about to disappear, so the association
// has to go with it — a dangling aria-describedby is worse than none.
@@ -345,10 +372,10 @@ export function UpdateConnectorCredentials({
event.preventDefault()
if (phase === 'saving' || phase === 'rotating') return
- const data: Record<string, string> = {}
+ const data = emptyCredentialMap()
for (const key of envSecret!.keys) {
- const value = draft[key.secretKey]
- if (value && value.trim() !== '') data[key.secretKey] = value
+ const value = ownCredentialValue(draft, key.secretKey)
+ if (typeof value === 'string' && value.trim() !== '') data[key.secretKey] = value
}
if (mode === 'set') {
// Every declared key is required. HCC validates each key and answers
@@ -460,7 +487,7 @@ export function UpdateConnectorCredentials({
throw putError
}
}
- setDraft({})
+ setDraft(emptyCredentialMap())
setRotationCutoff(cutoff)
setPhase('rotating')
} catch (e) {
@@ -563,7 +590,7 @@ export function UpdateConnectorCredentials({
type="password"
autoComplete="new-password"
placeholder={mode === 'set' ? 'Required' : 'Leave blank to keep current value'}
- value={draft[k.secretKey] || ''}
+ value={ownCredentialValue(draft, k.secretKey) ?? ''}
onChange={e => updateField(k.secretKey, e.target.value)}
disabled={busy}
// Set mode creates the Secret in one shot: HCC answers
diff --git a/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsx b/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsx
index 9d53c58cf..42912d81d 100644
--- a/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsx
+++ b/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsx
@@ -132,6 +132,27 @@ async function submitSet(keys: Record<string, string>) {
const ALL_KEYS = { 'api-key': 'a-value', 'workspace-id': 'w-value' }
+// Kubernetes Secret keys may use every own property name on Object.prototype.
+// Keep this derived rather than hand-picking a few examples: __proto__,
+// constructor, and toString are all valid keys and all must behave like normal
+// user-controlled strings in both create and merge-patch flows.
+const OBJECT_PROTOTYPE_KEYS = Object.getOwnPropertyNames(Object.prototype)
+const PROTOTYPE_KEY_SECRET: EnvSecret = {
+ name: 'prototype-key-credentials',
+ keys: OBJECT_PROTOTYPE_KEYS.map((secretKey, index) => ({
+ secretKey,
+ envVar: `PROTOTYPE_KEY_${index}`,
+ })),
+}
+
+function prototypeKeyValues(prefix: string): Record<string, string> {
+ // Object.fromEntries defines __proto__ as an own data property, unlike an
+ // object literal or assignment to a normal object.
+ return Object.fromEntries(
+ OBJECT_PROTOTYPE_KEYS.map((secretKey, index) => [secretKey, `${prefix}-${index}`])
+ )
+}
+
/** The shape control-api actually returns for a duplicate create: a bare 500,
* NOT a 409 (see spec Non-goals). Mocking 409 here would be a test that can
* never fail against the real server. */
@@ -224,6 +245,56 @@ describe('UpdateConnectorCredentials — partial payload', () => {
})
})
+describe('UpdateConnectorCredentials — Object.prototype credential keys', () => {
+ it('creates every prototype-named key as an own property in set mode', async () => {
+ const values = prototypeKeyValues('set-value')
+ mockCreateMcpSecret.mockResolvedValue({
+ name: PROTOTYPE_KEY_SECRET.name,
+ namespace: 'mcp-server',
+ })
+
+ await renderPanel(PROTOTYPE_KEY_SECRET, 'set')
+
+ // An untouched prototype-named key is absent, not inherited text coerced
+ // into an input. This catches __proto__ before the submit path can hide it.
+ for (const secretKey of OBJECT_PROTOTYPE_KEYS) {
+ expect(screen.getByLabelText(secretKey, { exact: false })).toHaveValue('')
+ }
+
+ await submitSet(values)
+
+ expect(mockCreateMcpSecret).toHaveBeenCalledTimes(1)
+ const payload = mockCreateMcpSecret.mock.calls[0]?.[1]
+ expect(Object.keys(payload ?? {})).toEqual(OBJECT_PROTOTYPE_KEYS)
+ for (const secretKey of OBJECT_PROTOTYPE_KEYS) {
+ expect(Object.hasOwn(payload ?? {}, secretKey)).toBe(true)
+ expect(payload?.[secretKey]).toBe(values[secretKey])
+ }
+ })
+
+ it.each(OBJECT_PROTOTYPE_KEYS)(
+ 'sends %s as the sole own-property merge patch in rotate mode',
+ async secretKey => {
+ const value = `rotate-${secretKey}`
+ mockUpdateMcpSecret.mockResolvedValue({
+ name: PROTOTYPE_KEY_SECRET.name,
+ namespace: 'mcp-server',
+ keys: [secretKey],
+ affectedConnectors: [SERVER_NAME],
+ })
+
+ await renderPanel(PROTOTYPE_KEY_SECRET)
+ await submitRotation(Object.fromEntries([[secretKey, value]]))
+
+ expect(mockUpdateMcpSecret).toHaveBeenCalledTimes(1)
+ const payload = mockUpdateMcpSecret.mock.calls[0]?.[1]
+ expect(Object.keys(payload ?? {})).toEqual([secretKey])
+ expect(Object.hasOwn(payload ?? {}, secretKey)).toBe(true)
+ expect(payload?.[secretKey]).toBe(value)
+ }
+ )
+})
+
describe('UpdateConnectorCredentials — client-side validation', () => {
it('blocks submit and shows a validation error when no key is filled', async () => {
await renderPanel(ENV_SECRET)
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 15ba7d69c..97304a435 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.403",
+ "version": "0.1.404",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.403",
+ "version": "0.1.404",
"dependencies": {
"@clerum/llm-providers": "file:../packages/llm-providers",
"@clerum/workflow-recipe-capability-policy": "file:../packages/workflow-recipe-capability-policy",
diff --git a/control-ui/package.json b/control-ui/package.json
index ea2e095ec..8da72a9a5 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.403",
+ "version": "0.1.404",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",