Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

fix(ai-providers): reject an unknown credential field instead of dropping it (#15747)

Hazem Adel4346201b4f8d
diff --git a/brain/knowledge/ai-intelligence/ai-providers.md b/brain/knowledge/ai-intelligence/ai-providers.md
index 8eddf3ab088..8028d07b79e 100644
--- a/brain/knowledge/ai-intelligence/ai-providers.md
+++ b/brain/knowledge/ai-intelligence/ai-providers.md
@@ -61,6 +61,7 @@ renders and preserves every real price; the cheapest in the set is 0.01.
- **The Agent and the Direct AI steps disagree about whether OpenAI does web search, and both are right.** `WEB_SEARCH_MODE_BY_PROVIDER` has no `OPENAI` entry, so `supportsWebSearch(OPENAI)` is `false` — the Agent asks that question before offering the tool and therefore has never had OpenAI web search (deliberately: it needs the Responses API, which breaks legacy BYOK models). Ask AI never asks it; it builds the tool straight from its own props and has had OpenAI web search all along. So `supportsWebSearch` is the *agent's* policy, not a statement of fact about the provider — reusing it as a general gate silently removes a capability Ask AI users have today. Whoever unifies the two paths has to keep the OpenAI branch reachable without routing it through that gate. The two paths also disagree about the unsupported tail: the piece's `webSearch` prop is a plain checkbox with no provider gating, and `createWebSearchTool` ends in `default: throw new Error('Provider X is not supported for web search')` — so ticking it on Azure, Mistral, xAI, or a Cloudflare Gateway model whose submodel prefix is not one of the four in `CF_GATEWAY_SUBMODEL_TO_PROVIDER` **fails the step**. The server's `buildWebSearchTools` returns `{}` for the same input, because the agent gates before calling it. The builder cannot simply be made to throw: `supportsWebSearch` is true for the `plugin` providers (`openrouter`, `activepieces`), the agent calls the builder for them, and there is no native entry for either because the plugin rides on the model settings instead — so `{}` is the correct answer there. The piece has the same shape, returning early for OpenRouter before the switch that throws. Hence two entry points: `buildWebSearchTools` stays total for callers that gate first, `buildWebSearchToolsOrThrow` reproduces the piece's error for callers that do not.
+- **The AI-provider create/update endpoints reject unknown `auth` keys rather than stripping them** (`strictAuth` in `packages/core/shared/src/lib/management/ai-providers/index.ts`). This is deliberately the request boundary only: `aiProviderCredentials()` still parses *stored* rows through the loose schemas, because a strict parse of a legacy row falls through to the `auth: {}` fallback and silently empties a working key. If you tighten the shared schemas themselves, you move a loud 400 into a quiet credential loss.
- **`aiProviderModule` is registered unconditionally, `agentModule` is not.** In `app.ts`, `aiProviderModule` sits outside the edition switch, while `agentModule` appears only in the `CLOUD` and `ENTERPRISE` arms — so an AI route hung off the provider module is on Community for free, and the same route hung off the agent module 404s there. That asymmetry is the cheapest way to satisfy [000036](../decisions/000036-the-worker-side-ai-path-is-community-edition-core.md): pick the module and there is no edition branch left to get wrong.
- **Chat falls back to the managed Activepieces row, so "no key is flagged for chat" is no longer a wall.** `pickChatRow` takes the `enabledForChat` row if there is one and otherwise the visible `ACTIVEPIECES` row; `findAvailableChatProviderRow` and both list endpoints share it, so what the picker shows is what a turn will actually run on. Before that, a platform whose managed row sat at `enabledForChat = false` — and nothing else flagged — got `SetupRequiredState` ("Set up an AI provider to get started") a second after the chat loaded. Migration `1802…AddChatRolloutFreeCreditGrant` was meant to repair exactly that state and matched zero rows: it compared `"provider" = 'ACTIVEPIECES'` while `AIProviderName` values are stored lowercase (`'activepieces'`). Enum values in raw SQL are the lowercase string, never the TS member name — grep the enum before writing the WHERE clause.
diff --git a/bun.lock b/bun.lock
index 66ce7146216..a4683ffd812 100644
--- a/bun.lock
+++ b/bun.lock
@@ -165,7 +165,7 @@
},
"packages/core/shared": {
"name": "@activepieces/shared",
- "version": "0.178.0",
+ "version": "0.179.0",
"dependencies": {
"@activepieces/core-execution": "workspace:*",
"@activepieces/core-formula": "workspace:*",
diff --git a/packages/core/shared/package.json b/packages/core/shared/package.json
index 83ebd6e2415..76ff9a9bad9 100644
--- a/packages/core/shared/package.json
+++ b/packages/core/shared/package.json
@@ -1,6 +1,6 @@
{
"name": "@activepieces/shared",
- "version": "0.178.0",
+ "version": "0.179.0",
"type": "commonjs",
"sideEffects": false,
"main": "./dist/src/index.js",
diff --git a/packages/core/shared/src/lib/management/ai-providers/index.ts b/packages/core/shared/src/lib/management/ai-providers/index.ts
index fc936e92aea..8b26f81d0a2 100644
--- a/packages/core/shared/src/lib/management/ai-providers/index.ts
+++ b/packages/core/shared/src/lib/management/ai-providers/index.ts
@@ -1,4 +1,4 @@
-import { ActivePiecesProviderAuthConfig, ActivePiecesProviderConfig, AIProviderAuthConfig, AIProviderConfig, AiProviderCredentials, AiProviderKeyStatus, AIProviderModelType, AIProviderName, AnthropicProviderAuthConfig, AnthropicProviderConfig, AzureProviderAuthConfig, AzureProviderConfig, BaseAIProviderAuthConfig, BaseModelSchema, BedrockProviderAuthConfig, BedrockProviderConfig, CloudflareGatewayProviderAuthConfig, CloudflareGatewayProviderConfig, GoogleProviderAuthConfig, GoogleProviderConfig, MistralProviderAuthConfig, MistralProviderConfig, OpenAICompatibleProviderAuthConfig, OpenAICompatibleProviderConfig, OpenAiCompatibleVendorConfig, OpenAIProviderAuthConfig, OpenAIProviderConfig, OpenRouterProviderAuthConfig, OpenRouterProviderConfig, VertexProviderAuthConfig, VertexProviderConfig } from '@activepieces/core-utils'
+import { ActivePiecesProviderAuthConfig, ActivePiecesProviderConfig, AIProviderConfig, AiProviderCredentials, AiProviderKeyStatus, AIProviderModelType, AIProviderName, AnthropicProviderAuthConfig, AnthropicProviderConfig, AzureProviderAuthConfig, AzureProviderConfig, BaseAIProviderAuthConfig, BaseModelSchema, BedrockProviderAuthConfig, BedrockProviderConfig, CloudflareGatewayProviderAuthConfig, CloudflareGatewayProviderConfig, GoogleProviderAuthConfig, GoogleProviderConfig, MistralProviderAuthConfig, MistralProviderConfig, OpenAICompatibleProviderAuthConfig, OpenAICompatibleProviderConfig, OpenAiCompatibleVendorConfig, OpenAIProviderAuthConfig, OpenAIProviderConfig, OpenRouterProviderAuthConfig, OpenRouterProviderConfig, VertexProviderAuthConfig, VertexProviderConfig } from '@activepieces/core-utils'
import { z } from 'zod'
export { ActivePiecesProviderAuthConfig, ActivePiecesProviderConfig, AIProviderAuthConfig, AIProviderConfig, AiProviderCredentials, aiProviderCredentials, AIProviderModelType, AnthropicProviderAuthConfig, AnthropicProviderConfig, AzureProviderAuthConfig, AzureProviderConfig, BaseAIProviderAuthConfig, BedrockProviderAuthConfig, BedrockProviderConfig, CloudflareGatewayProviderAuthConfig, CloudflareGatewayProviderConfig, GoogleProviderAuthConfig, GoogleProviderConfig, MistralProviderAuthConfig, MistralProviderConfig, OpenAICompatibleProviderAuthConfig, OpenAICompatibleProviderConfig, OpenAiCompatibleVendorConfig, OpenAIProviderAuthConfig, OpenAIProviderConfig, OpenRouterProviderAuthConfig, OpenRouterProviderConfig, ProviderModelConfig, VertexProviderAuthConfig, VertexProviderConfig } from '@activepieces/core-utils'
@@ -8,106 +8,120 @@ const ProviderConfigUnion = z.discriminatedUnion('provider', [
displayName: z.string().min(1),
provider: z.literal(AIProviderName.OPENAI),
config: OpenAIProviderConfig,
- auth: OpenAIProviderAuthConfig,
+ auth: strictAuth(OpenAIProviderAuthConfig),
}),
z.object({
displayName: z.string().min(1),
provider: z.literal(AIProviderName.OPENROUTER),
config: OpenRouterProviderConfig,
- auth: OpenRouterProviderAuthConfig,
+ auth: strictAuth(OpenRouterProviderAuthConfig),
}),
z.object({
displayName: z.string().min(1),
provider: z.literal(AIProviderName.ANTHROPIC),
config: AnthropicProviderConfig,
- auth: AnthropicProviderAuthConfig,
+ auth: strictAuth(AnthropicProviderAuthConfig),
}),
z.object({
displayName: z.string().min(1),
provider: z.literal(AIProviderName.AZURE),
config: AzureProviderConfig,
- auth: AzureProviderAuthConfig,
+ auth: strictAuth(AzureProviderAuthConfig),
}),
z.object({
displayName: z.string().min(1),
provider: z.literal(AIProviderName.GOOGLE),
config: GoogleProviderConfig,
- auth: GoogleProviderAuthConfig,
+ auth: strictAuth(GoogleProviderAuthConfig),
}),
z.object({
displayName: z.string().min(1),
provider: z.literal(AIProviderName.CLOUDFLARE_GATEWAY),
config: CloudflareGatewayProviderConfig,
- auth: CloudflareGatewayProviderAuthConfig,
+ auth: strictAuth(CloudflareGatewayProviderAuthConfig),
}),
z.object({
displayName: z.string().min(1),
provider: z.literal(AIProviderName.CUSTOM),
config: OpenAICompatibleProviderConfig,
- auth: OpenAICompatibleProviderAuthConfig,
+ auth: strictAuth(OpenAICompatibleProviderAuthConfig),
}),
z.object({
displayName: z.string().min(1),
provider: z.literal(AIProviderName.ACTIVEPIECES),
config: ActivePiecesProviderConfig,
- auth: ActivePiecesProviderAuthConfig,
+ auth: strictAuth(ActivePiecesProviderAuthConfig),
}),
z.object({
displayName: z.string().min(1),
provider: z.literal(AIProviderName.BEDROCK),
config: BedrockProviderConfig,
- auth: BedrockProviderAuthConfig,
+ auth: strictAuth(BedrockProviderAuthConfig),
}),
z.object({
displayName: z.string().min(1),
provider: z.literal(AIProviderName.VERTEX),
config: VertexProviderConfig,
- auth: VertexProviderAuthConfig,
+ auth: strictAuth(VertexProviderAuthConfig),
}),
z.object({
displayName: z.string().min(1),
provider: z.literal(AIProviderName.MISTRAL),
config: MistralProviderConfig,
- auth: MistralProviderAuthConfig,
+ auth: strictAuth(MistralProviderAuthConfig),
}),
z.object({
displayName: z.string().min(1),
provider: z.literal(AIProviderName.XAI),
config: OpenAiCompatibleVendorConfig,
- auth: BaseAIProviderAuthConfig,
+ auth: strictAuth(BaseAIProviderAuthConfig),
}),
z.object({
displayName: z.string().min(1),
provider: z.literal(AIProviderName.DEEPSEEK),
config: OpenAiCompatibleVendorConfig,
- auth: BaseAIProviderAuthConfig,
+ auth: strictAuth(BaseAIProviderAuthConfig),
}),
z.object({
displayName: z.string().min(1),
provider: z.literal(AIProviderName.ZAI),
config: OpenAiCompatibleVendorConfig,
- auth: BaseAIProviderAuthConfig,
+ auth: strictAuth(BaseAIProviderAuthConfig),
}),
z.object({
displayName: z.string().min(1),
provider: z.literal(AIProviderName.QWEN),
config: OpenAiCompatibleVendorConfig,
- auth: BaseAIProviderAuthConfig,
+ auth: strictAuth(BaseAIProviderAuthConfig),
}),
z.object({
displayName: z.string().min(1),
provider: z.literal(AIProviderName.MINIMAX),
config: OpenAiCompatibleVendorConfig,
- auth: BaseAIProviderAuthConfig,
+ auth: strictAuth(BaseAIProviderAuthConfig),
}),
z.object({
displayName: z.string().min(1),
provider: z.literal(AIProviderName.MOONSHOT),
config: OpenAiCompatibleVendorConfig,
- auth: BaseAIProviderAuthConfig,
+ auth: strictAuth(BaseAIProviderAuthConfig),
}),
])
+const StrictAIProviderAuthConfig = z.union([
+ strictAuth(AnthropicProviderAuthConfig),
+ strictAuth(AzureProviderAuthConfig),
+ strictAuth(GoogleProviderAuthConfig),
+ strictAuth(OpenAIProviderAuthConfig),
+ strictAuth(OpenRouterProviderAuthConfig),
+ strictAuth(CloudflareGatewayProviderAuthConfig),
+ strictAuth(OpenAICompatibleProviderAuthConfig),
+ strictAuth(ActivePiecesProviderAuthConfig),
+ strictAuth(BedrockProviderAuthConfig),
+ strictAuth(VertexProviderAuthConfig),
+ strictAuth(MistralProviderAuthConfig),
+])
+
export const AIProvider = z.object({
...BaseModelSchema,
displayName: z.string().min(1),
@@ -179,7 +193,7 @@ export type CreateAIProviderRequest = z.infer<typeof CreateAIProviderRequest>
export const UpdateAIProviderRequest = z.object({
displayName: z.string().min(1),
config: AIProviderConfig.optional(),
- auth: AIProviderAuthConfig.optional(),
+ auth: StrictAIProviderAuthConfig.optional(),
enabledForChat: z.boolean().optional(),
modelScope: AiProviderModelScope.optional(),
modelIds: z.array(z.string()).optional(),
@@ -238,6 +252,10 @@ export function getEffectiveProviderAndModel({
return { provider: mapped, model: split.model }
}
+function strictAuth<Shape extends z.ZodRawShape>(schema: z.ZodObject<Shape>): z.ZodObject<Shape, z.core.$strict> {
+ return z.strictObject(schema.shape)
+}
+
const CF_GATEWAY_SUBMODEL_TO_PROVIDER: Record<string, AIProviderName> = {
openai: AIProviderName.OPENAI,
anthropic: AIProviderName.ANTHROPIC,
diff --git a/packages/core/shared/test/management/ai-providers.test.ts b/packages/core/shared/test/management/ai-providers.test.ts
new file mode 100644
index 00000000000..bce907c2a1e
--- /dev/null
+++ b/packages/core/shared/test/management/ai-providers.test.ts
@@ -0,0 +1,38 @@
+import { AIProviderName } from '@activepieces/core-utils'
+import { describe, expect, it } from 'vitest'
+import { CreateAIProviderRequest, UpdateAIProviderRequest } from '../../src/lib/management/ai-providers'
+
+const bedrockRequest = {
+ displayName: 'AWS Bedrock',
+ provider: AIProviderName.BEDROCK,
+ config: { region: 'us-east-1' },
+ auth: { accessKeyId: 'ASIA', secretAccessKey: 'secret' },
+}
+
+describe('AI provider requests', () => {
+ it('keeps every credential the provider models', () => {
+ expect(CreateAIProviderRequest.parse(bedrockRequest).auth).toEqual(bedrockRequest.auth)
+ expect(UpdateAIProviderRequest.parse({ displayName: 'AWS Bedrock', auth: bedrockRequest.auth }).auth).toEqual(bedrockRequest.auth)
+ })
+
+ it('keeps a bedrock session token, so temporary credentials still reach AWS', () => {
+ const auth = { ...bedrockRequest.auth, sessionToken: 'temporary' }
+
+ expect(CreateAIProviderRequest.parse({ ...bedrockRequest, auth }).auth).toEqual(auth)
+ expect(UpdateAIProviderRequest.parse({ displayName: 'AWS Bedrock', auth }).auth).toEqual(auth)
+ })
+
+ it('rejects a credential field it cannot honour instead of dropping it', () => {
+ const auth = { ...bedrockRequest.auth, profileArn: 'arn:aws:rolesanywhere:::profile/1' }
+
+ expect(CreateAIProviderRequest.safeParse({ ...bedrockRequest, auth }).success).toBe(false)
+ expect(UpdateAIProviderRequest.safeParse({ displayName: 'AWS Bedrock', auth }).success).toBe(false)
+ })
+
+ it('still accepts every provider that sends only an api key', () => {
+ const request = { displayName: 'OpenAI', provider: AIProviderName.OPENAI, config: {}, auth: { apiKey: 'sk-live' } }
+
+ expect(CreateAIProviderRequest.safeParse(request).success).toBe(true)
+ expect(UpdateAIProviderRequest.safeParse({ displayName: 'OpenAI', auth: { apiKey: 'sk-live' } }).success).toBe(true)
+ })
+})