Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix(agent-vault): refuse double braces in header prefixes
Scott Wilson5c6abf000a98
diff --git a/backend/e2e-test/routes/v1/agent-vault.spec.ts b/backend/e2e-test/routes/v1/agent-vault.spec.tsindex 10eca3f0c2..c9dd578fce 100644--- a/backend/e2e-test/routes/v1/agent-vault.spec.ts+++ b/backend/e2e-test/routes/v1/agent-vault.spec.ts@@ -1163,6 +1163,21 @@ describe("Agent Vault V1 Router", async () => {});expect(bracedPlaceholder.statusCode).toBe(422);+ // A prefix is sent as typed, so braces in one would reach the host as a reference nobody fills in.+ const bracedBearerPrefix = await inject("POST", servicesUrl(bundle.id), {+ name: "braced-bearer",+ hostPattern: "braced-bearer.example.com",+ credential: { type: "bearer", headerPrefix: "{{ORG}}", value: "x" }+ });+ expect(bracedBearerPrefix.statusCode).toBe(422);+ const bracedHeaderPrefix = await inject("POST", servicesUrl(bundle.id), {+ name: "braced-header",+ hostPattern: "braced-header.example.com",+ credential: { type: "passthrough" },+ customHeaders: [{ name: "X-Org", prefix: "org-{{ORG}}", value: "x" }]+ });+ expect(bracedHeaderPrefix.statusCode).toBe(422);+expect(await testDb("agent_vault_services").where({ accessBundleId: bundle.id })).toHaveLength(0);});diff --git a/backend/src/ee/routes/v1/agent-vault-routers/agent-vault-schemas.ts b/backend/src/ee/routes/v1/agent-vault-routers/agent-vault-schemas.tsindex 0d4e566219..743a82046b 100644--- a/backend/src/ee/routes/v1/agent-vault-routers/agent-vault-schemas.ts+++ b/backend/src/ee/routes/v1/agent-vault-routers/agent-vault-schemas.ts@@ -23,6 +23,7 @@ import {AgentVaultCustomHeaderInputSchema,AgentVaultCustomHeaderUpdateSchema,agentVaultHeaderNameSchema,+ agentVaultHeaderPrefixSchema,AgentVaultSubstitutionInputSchema,AgentVaultSubstitutionUpdateSchema} from "@app/ee/services/agent-vault/agent-vault-transformation-schemas";@@ -63,13 +64,7 @@ export const AgentVaultCredentialInputSchema = z.object({type: z.literal(AgentVaultCredentialType.Bearer),headerName: agentVaultHeaderNameSchema.optional().describe(AGENT_VAULT.SERVICE.headerName),- headerPrefix: z- .string()- .trim()- .max(64)- .regex(AGENT_VAULT_NO_CONTROL_CHARS_RE, AGENT_VAULT_NO_CONTROL_CHARS_MESSAGE)- .optional()- .describe(AGENT_VAULT.SERVICE.headerPrefix),+ headerPrefix: agentVaultHeaderPrefixSchema.optional().describe(AGENT_VAULT.SERVICE.headerPrefix),value: acceptsVariableReferences(z.string().min(1).max(8192).regex(AGENT_VAULT_NO_CONTROL_CHARS_RE, AGENT_VAULT_NO_CONTROL_CHARS_MESSAGE)).describe(AGENT_VAULT.SERVICE.value)@@ -99,13 +94,7 @@ export const AgentVaultCredentialUpdateSchema = z.object({type: z.literal(AgentVaultCredentialType.Bearer),headerName: agentVaultHeaderNameSchema.optional().describe(AGENT_VAULT.SERVICE.headerName),- headerPrefix: z- .string()- .trim()- .max(64)- .regex(AGENT_VAULT_NO_CONTROL_CHARS_RE, AGENT_VAULT_NO_CONTROL_CHARS_MESSAGE)- .optional()- .describe(AGENT_VAULT.SERVICE.headerPrefix),+ headerPrefix: agentVaultHeaderPrefixSchema.optional().describe(AGENT_VAULT.SERVICE.headerPrefix),value: acceptsVariableReferences(z.string().min(1).max(8192).regex(AGENT_VAULT_NO_CONTROL_CHARS_RE, AGENT_VAULT_NO_CONTROL_CHARS_MESSAGE))diff --git a/backend/src/ee/services/agent-vault/agent-vault-transformation-schemas.ts b/backend/src/ee/services/agent-vault/agent-vault-transformation-schemas.tsindex 9e4171cab7..a0b0305dc7 100644--- a/backend/src/ee/services/agent-vault/agent-vault-transformation-schemas.ts+++ b/backend/src/ee/services/agent-vault/agent-vault-transformation-schemas.ts@@ -46,11 +46,16 @@ export const agentVaultHeaderNameSchema = z.regex(AGENT_VAULT_HEADER_NAME_RE, AGENT_VAULT_HEADER_NAME_MESSAGE).refine((name) => !RESERVED_HEADER_NAMES.has(name.toLowerCase()), AGENT_VAULT_RESERVED_HEADER_MESSAGE);-const headerPrefixSchema = z+const hasNoDoubleBraces = (text: string) => !text.includes("{{") && !text.includes("}}");++// Shared with the bearer credential's own prefix. A prefix is sent as typed, so double braces in one would read+// as a variable reference the proxy never fills in.+export const agentVaultHeaderPrefixSchema = z.string().trim().max(64)- .regex(AGENT_VAULT_NO_CONTROL_CHARS_RE, AGENT_VAULT_NO_CONTROL_CHARS_MESSAGE);+ .regex(AGENT_VAULT_NO_CONTROL_CHARS_RE, AGENT_VAULT_NO_CONTROL_CHARS_MESSAGE)+ .refine(hasNoDoubleBraces, "A prefix can't contain {{ or }}. Put a variable reference in the value instead.");// For every field a variable can be used in, so a mistyped reference fails the save, not the request.export const acceptsVariableReferences = (schema: z.ZodString) =>@@ -71,7 +76,7 @@ const placeholderSchema = z.max(255).regex(AGENT_VAULT_NO_CONTROL_CHARS_RE, AGENT_VAULT_NO_CONTROL_CHARS_MESSAGE).refine(- (placeholder) => !placeholder.includes("{{") && !placeholder.includes("}}"),+ hasNoDoubleBraces,"A placeholder can't contain {{ or }}. Double braces are reserved for variable references.");@@ -85,14 +90,14 @@ const surfacesSchema = z// fetching the service first. `value` is optional on update because omitting it keeps what is sealed.export const AgentVaultCustomHeaderInputSchema = z.object({name: agentVaultHeaderNameSchema.describe(AGENT_VAULT.SERVICE.customHeaderName),- prefix: headerPrefixSchema.optional().describe(AGENT_VAULT.SERVICE.customHeaderPrefix),+ prefix: agentVaultHeaderPrefixSchema.optional().describe(AGENT_VAULT.SERVICE.customHeaderPrefix),value: secretValueSchema.describe(AGENT_VAULT.SERVICE.customHeaderValue)});export const AgentVaultCustomHeaderUpdateSchema = z.object({id: z.string().uuid().optional().describe(AGENT_VAULT.SERVICE.customHeaderId),name: agentVaultHeaderNameSchema.describe(AGENT_VAULT.SERVICE.customHeaderName),- prefix: headerPrefixSchema.optional().describe(AGENT_VAULT.SERVICE.updateCustomHeaderPrefix),+ prefix: agentVaultHeaderPrefixSchema.optional().describe(AGENT_VAULT.SERVICE.updateCustomHeaderPrefix),value: secretValueSchema.optional().describe(AGENT_VAULT.SERVICE.updateCustomHeaderValue)});diff --git a/docs/documentation/platform/agent-vault/variables.mdx b/docs/documentation/platform/agent-vault/variables.mdxindex 0eeb3713a6..351137b383 100644--- a/docs/documentation/platform/agent-vault/variables.mdx+++ b/docs/documentation/platform/agent-vault/variables.mdx@@ -61,7 +61,7 @@ A value can contain up to 3 references. If a value uses the same key more than oThe **Sends** preview shows each reference in the headers the proxy attaches. If a reference names a key the bundle doesn't have, Infisical marks the reference in red and won't save the service until you correct the key or add the variable.-Variables don't work in any other field, such as a host pattern, a path, a header name or prefix, or a substitution placeholder.+Variables don't work in any other field, such as a host pattern, a path, a header name or prefix, or a substitution placeholder. If a header prefix or a substitution placeholder contains `{{` or `}}`, Infisical won't save the service.When you edit a service later, each value you saved stays hidden, like any other stored credential. If a value uses variables, Infisical lists the variables under the field. To change a value, enter the whole value again, including any references you want to keep.diff --git a/frontend/src/components/agent-vault/service-sheet/serviceSchema.ts b/frontend/src/components/agent-vault/service-sheet/serviceSchema.tsindex 22be40d407..e7567bef03 100644--- a/frontend/src/components/agent-vault/service-sheet/serviceSchema.ts+++ b/frontend/src/components/agent-vault/service-sheet/serviceSchema.ts@@ -61,6 +61,11 @@ const NO_CONTROL_CHARS_RE = /^[^\x00-\x1f\x7f]*$/;const CONTROL_CHARS_MESSAGE ="This can't contain line breaks or other control characters. Check for a stray newline if you pasted it.";+// Double braces wrap a variable reference, and neither a prefix nor a placeholder takes one.+const hasDoubleBraces = (text: string) => text.includes("{{") || text.includes("}}");++const PREFIX_BRACES_MESSAGE = "A prefix can't contain {{ or }}.";+// Set by the proxy on every request, so naming one here would either be dropped or corrupt the request.const RESERVED_HEADER_NAMES = new Set(["host",@@ -210,6 +215,18 @@ export const buildServiceSchema = (service?: TAgentVaultService | null, variable});}+ if (+ data.credentialType === AgentVaultCredentialType.Bearer &&+ data.headerPrefix &&+ hasDoubleBraces(data.headerPrefix)+ ) {+ ctx.addIssue({+ code: z.ZodIssueCode.custom,+ path: ["headerPrefix"],+ message: PREFIX_BRACES_MESSAGE+ });+ }+const seenHeaders = new Set<string>();data.customHeaders.forEach((header, index) => {const at = (field: string, message: string) =>@@ -243,6 +260,8 @@ export const buildServiceSchema = (service?: TAgentVaultService | null, variableif (header.prefix && !NO_CONTROL_CHARS_RE.test(header.prefix)) {at("prefix", CONTROL_CHARS_MESSAGE);+ } else if (header.prefix && hasDoubleBraces(header.prefix)) {+ at("prefix", PREFIX_BRACES_MESSAGE);}});@@ -259,10 +278,7 @@ export const buildServiceSchema = (service?: TAgentVaultService | null, variableat("placeholder", "Required");} else if (!NO_CONTROL_CHARS_RE.test(substitution.placeholder)) {at("placeholder", CONTROL_CHARS_MESSAGE);- } else if (- substitution.placeholder.includes("{{") ||- substitution.placeholder.includes("}}")- ) {+ } else if (hasDoubleBraces(substitution.placeholder)) {at("placeholder","A placeholder can't contain {{ or }}. Those wrap a variable reference."