Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

misc: greptile

Sheen Capadngan01a957249294
diff --git a/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-client-fns.test.ts b/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-client-fns.test.ts
index e64f8cdebb..84a6dacdb1 100644
--- a/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-client-fns.test.ts
+++ b/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-client-fns.test.ts
@@ -47,7 +47,8 @@ describe("client registration", () => {
serverUrl: "https://mcp.example.com/mcp",
registrationEndpoint: "https://mcp.example.com/register",
redirectUri: "https://app.infisical.com/agent-vault/oauth/callback",
- grantTypesSupported: null
+ grantTypesSupported: null,
+ tokenEndpointAuthMethodsSupported: null
};
test("sends the full metadata and keeps the method the server assigned", async () => {
@@ -78,6 +79,29 @@ describe("client registration", () => {
expect(calls[0].json).toMatchObject({ grant_types: ["authorization_code"] });
});
+ test("asks for a confidential client when the server lists its auth methods without none", async () => {
+ const { http, calls } = stubPosts([json(201, { client_id: "c-3", client_secret: "s-3" })]);
+ const result = await registerOauthClient({
+ http,
+ ...args,
+ tokenEndpointAuthMethodsSupported: ["client_secret_post"]
+ });
+ expect(calls[0].json).toMatchObject({ token_endpoint_auth_method: "client_secret_post" });
+ expect(result.client).toEqual({
+ clientId: "c-3",
+ clientSecret: "s-3",
+ tokenEndpointAuthMethod: AgentVaultOauthClientAuthMethod.ClientSecretPost
+ });
+
+ const both = stubPosts([json(201, { client_id: "c-4" })]);
+ await registerOauthClient({
+ http: both.http,
+ ...args,
+ tokenEndpointAuthMethodsSupported: ["client_secret_basic", "none"]
+ });
+ expect(both.calls[0].json).toMatchObject({ token_endpoint_auth_method: "none" });
+ });
+
test("a rejected registration is retried once without application_type, keeping the grant types", async () => {
const { http, calls } = stubPosts([
json(400, { error: "invalid_client_metadata" }),
diff --git a/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-client-fns.ts b/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-client-fns.ts
index 49955468b2..de143962a5 100644
--- a/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-client-fns.ts
+++ b/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-client-fns.ts
@@ -37,7 +37,7 @@ const SUPPORTED_AUTH_METHODS = Object.values(AgentVaultOauthClientAuthMethod) as
export const MAX_CLIENT_ID_LENGTH = 2048;
export const MAX_CLIENT_SECRET_LENGTH = 4096;
-const parseRegistration = (body: string): TOauthClient | null => {
+const parseRegistration = (body: string, requestedMethod: AgentVaultOauthClientAuthMethod): TOauthClient | null => {
let parsed: Record<string, unknown>;
try {
parsed = JSON.parse(body) as Record<string, unknown>;
@@ -62,7 +62,9 @@ const parseRegistration = (body: string): TOauthClient | null => {
// The server may assign a method other than the one asked for; what it returns is what the client holds.
let method = typeof parsed.token_endpoint_auth_method === "string" ? parsed.token_endpoint_auth_method : null;
if (!method || !SUPPORTED_AUTH_METHODS.includes(method)) {
- method = clientSecret ? AgentVaultOauthClientAuthMethod.ClientSecretBasic : AgentVaultOauthClientAuthMethod.None;
+ if (!clientSecret) method = AgentVaultOauthClientAuthMethod.None;
+ else if (requestedMethod !== AgentVaultOauthClientAuthMethod.None) method = requestedMethod;
+ else method = AgentVaultOauthClientAuthMethod.ClientSecretBasic;
}
return {
clientId: parsed.client_id,
@@ -71,28 +73,44 @@ const parseRegistration = (body: string): TOauthClient | null => {
};
};
+// RFC 8414 makes client_secret_basic the default when the server lists no methods.
+const secretAuthMethod = (supported: string[] | null) =>
+ supported &&
+ !supported.includes(AgentVaultOauthClientAuthMethod.ClientSecretBasic) &&
+ supported.includes(AgentVaultOauthClientAuthMethod.ClientSecretPost)
+ ? AgentVaultOauthClientAuthMethod.ClientSecretPost
+ : AgentVaultOauthClientAuthMethod.ClientSecretBasic;
+
// RFC 7591. Servers must ignore metadata fields they don't understand, so the only one a strict server can refuse
// is `application_type` (an OIDC registration value); a refusal is retried once without it. `grant_types` stays,
// or a strict server registers authorization_code only and every refresh fails with unauthorized_client. It drops
// refresh_token only when the server's metadata lists its grants without it, since a strict one refuses the request.
+// It asks for a public client unless the server lists its auth methods without `none`, for the same reason.
export const registerOauthClient = async ({
http,
serverUrl,
registrationEndpoint,
redirectUri,
- grantTypesSupported
+ grantTypesSupported,
+ tokenEndpointAuthMethodsSupported
}: {
http: TOauthHttpClient;
serverUrl: string;
registrationEndpoint: string;
redirectUri: string;
grantTypesSupported: string[] | null;
+ tokenEndpointAuthMethodsSupported: string[] | null;
}): Promise<{ client: TOauthClient; compatibility: AgentVaultOauthCompatibility[] }> => {
const refreshSupported = !grantTypesSupported || grantTypesSupported.includes("refresh_token");
+ const publicClientSupported =
+ !tokenEndpointAuthMethodsSupported ||
+ tokenEndpointAuthMethodsSupported.includes(AgentVaultOauthClientAuthMethod.None);
const minimal = {
client_name: AGENT_VAULT_OAUTH_CLIENT_NAME,
redirect_uris: [redirectUri],
- token_endpoint_auth_method: AgentVaultOauthClientAuthMethod.None,
+ token_endpoint_auth_method: publicClientSupported
+ ? AgentVaultOauthClientAuthMethod.None
+ : secretAuthMethod(tokenEndpointAuthMethodsSupported),
grant_types: refreshSupported ? [AGENT_VAULT_OAUTH_GRANT_TYPE, "refresh_token"] : [AGENT_VAULT_OAUTH_GRANT_TYPE],
response_types: ["code"]
};
@@ -120,7 +138,7 @@ export const registerOauthClient = async ({
lastReason = "";
}
if (response.status === 200 || response.status === 201) {
- const client = parseRegistration(response.body);
+ const client = parseRegistration(response.body, minimal.token_endpoint_auth_method);
if (!client) {
throw new OauthRegistrationError("its registration endpoint returned no usable client ID.", response.status);
}
@@ -141,7 +159,7 @@ export const registerOauthClient = async ({
);
};
-// An admin-entered client. RFC 8414 makes client_secret_basic the default when the server lists no methods.
+// An admin-entered client.
export const manualOauthClient = ({
clientId,
clientSecret,
@@ -152,12 +170,5 @@ export const manualOauthClient = ({
tokenEndpointAuthMethodsSupported: string[] | null;
}): TOauthClient => {
if (!clientSecret) return { clientId, tokenEndpointAuthMethod: AgentVaultOauthClientAuthMethod.None };
- const supported = tokenEndpointAuthMethodsSupported;
- const method =
- supported &&
- !supported.includes(AgentVaultOauthClientAuthMethod.ClientSecretBasic) &&
- supported.includes(AgentVaultOauthClientAuthMethod.ClientSecretPost)
- ? AgentVaultOauthClientAuthMethod.ClientSecretPost
- : AgentVaultOauthClientAuthMethod.ClientSecretBasic;
- return { clientId, clientSecret, tokenEndpointAuthMethod: method };
+ return { clientId, clientSecret, tokenEndpointAuthMethod: secretAuthMethod(tokenEndpointAuthMethodsSupported) };
};
diff --git a/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-http-fns.ts b/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-http-fns.ts
index bbfe1a76f2..6bfd951c97 100644
--- a/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-http-fns.ts
+++ b/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-http-fns.ts
@@ -110,6 +110,26 @@ export const agentVaultOauthHttpClient: TOauthHttpClient = {
);
response.data?.destroy?.();
const challenge = headerValue(response.headers["www-authenticate"]);
- return { status: response.status, wwwAuthenticate: challenge || null };
+ if (challenge || (response.status >= 200 && response.status < 300)) {
+ return { status: response.status, wwwAuthenticate: challenge || null };
+ }
+
+ // An SSE server may only challenge the GET that opens its stream, and answer the POST with 405.
+ const sse = await safeRequest
+ .get<Readable>(url, {
+ timeout: TIMEOUT_MS,
+ signal: AbortSignal.timeout(TIMEOUT_MS),
+ "axios-retry": { retries: 0 },
+ responseType: "stream",
+ validateStatus: () => true,
+ headers: { Accept: "text/event-stream" }
+ })
+ .catch(() => null);
+ if (sse) {
+ sse.data?.destroy?.();
+ const sseChallenge = headerValue(sse.headers["www-authenticate"]);
+ if (sseChallenge) return { status: sse.status, wwwAuthenticate: sseChallenge };
+ }
+ return { status: response.status, wwwAuthenticate: null };
}
};
diff --git a/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-service.ts b/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-service.ts
index 43e64ac78d..f363c98ede 100644
--- a/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-service.ts
+++ b/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-service.ts
@@ -350,7 +350,8 @@ export const agentVaultOauthServiceFactory = ({
serverUrl,
registrationEndpoint: discovery.registrationEndpoint,
redirectUri: callbackUri,
- grantTypesSupported: discovery.grantTypesSupported
+ grantTypesSupported: discovery.grantTypesSupported,
+ tokenEndpointAuthMethodsSupported: discovery.tokenEndpointAuthMethodsSupported
});
client = registered.client;
compatibility.push(...registered.compatibility);
diff --git a/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-token-fns.socket.test.ts b/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-token-fns.socket.test.ts
index c53769cab1..f06f857a0f 100644
--- a/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-token-fns.socket.test.ts
+++ b/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-token-fns.socket.test.ts
@@ -35,13 +35,15 @@ vi.mock("@app/lib/validator", async (importOriginal) => {
const actual = await importOriginal<typeof import("@app/lib/validator")>();
const post: typeof actual.safeRequest.post = (url, data, options) =>
actual.safeRequest.post(url, data, { ...options, ca: transportTrust.ca });
- return { ...actual, safeRequest: { ...actual.safeRequest, post } };
+ const get: typeof actual.safeRequest.get = (url, options) =>
+ actual.safeRequest.get(url, { ...options, ca: transportTrust.ca });
+ return { ...actual, safeRequest: { ...actual.safeRequest, post, get } };
});
describe("OAuth token requests over HTTPS", () => {
let server: https.Server;
let issuer: string;
- const requests: { path: string; authorization?: string; form: URLSearchParams }[] = [];
+ const requests: { method?: string; path: string; authorization?: string; form: URLSearchParams }[] = [];
beforeAll(async () => {
const keys = forge.pki.rsa.generateKeyPair(2048);
@@ -69,8 +71,19 @@ describe("OAuth token requests over HTTPS", () => {
});
request.on("end", () => {
const form = new URLSearchParams(body);
- requests.push({ path: request.url ?? "", authorization: request.headers.authorization, form });
- if (request.url === "/redirect") {
+ requests.push({
+ method: request.method,
+ path: request.url ?? "",
+ authorization: request.headers.authorization,
+ form
+ });
+ if (request.url === "/sse" && request.method === "GET") {
+ response.writeHead(401, { "WWW-Authenticate": `Bearer resource_metadata="${issuer}/meta"` });
+ response.end();
+ } else if (request.url === "/sse") {
+ response.writeHead(405);
+ response.end();
+ } else if (request.url === "/redirect") {
response.writeHead(302, { Location: `${issuer}/unexpected` });
response.end();
} else if (request.url === "/unavailable") {
@@ -189,6 +202,12 @@ describe("OAuth token requests over HTTPS", () => {
expect(requests).toHaveLength(0);
});
+ test("the MCP probe falls back to GET when an SSE server refuses the POST without a challenge", async () => {
+ const result = await agentVaultOauthHttpClient.probe(`${issuer}/sse`);
+ expect(result).toEqual({ status: 401, wwwAuthenticate: `Bearer resource_metadata="${issuer}/meta"` });
+ expect(requests.map(({ method, path }) => `${method} ${path}`)).toEqual(["POST /sse", "GET /sse"]);
+ });
+
test("a provider trickling response bytes cannot extend the request deadline", async () => {
const startedAt = Date.now();
await expect(
diff --git a/frontend/src/components/agent-vault/service-sheet/OAuthAuthorizeCard.tsx b/frontend/src/components/agent-vault/service-sheet/OAuthAuthorizeCard.tsx
index 7ab8751f7c..4146ef5394 100644
--- a/frontend/src/components/agent-vault/service-sheet/OAuthAuthorizeCard.tsx
+++ b/frontend/src/components/agent-vault/service-sheet/OAuthAuthorizeCard.tsx
@@ -324,6 +324,7 @@ export const OAuthAuthorizeCard = ({ accessBundleId, service, onSignInChange }:
} else {
head = (
<Status
+ icon={<CheckIcon />}
title={
authorizedAt ? (
<Tooltip>
@@ -380,12 +381,13 @@ export const OAuthAuthorizeCard = ({ accessBundleId, service, onSignInChange }:
<FieldContent>
<div className="flex flex-col gap-3">
{status ? (
- <div className="flex flex-col gap-2">
- <div className="flex items-start justify-between gap-4">
- <div className="min-w-0 flex-1">{status.head}</div>
- {!isOwnApp && authorizeButton}
+ <div className="flex items-start justify-between gap-4">
+ <div className="flex min-w-0 flex-1 flex-col gap-1.5">
+ {status.head}
+ {/* Indented to the status text, past its icon, so the details read as part of it. */}
+ {status.details && <div className="pl-5">{status.details}</div>}
</div>
- {status.details}
+ {!isOwnApp && authorizeButton}
</div>
) : (
!isOwnApp && <div>{authorizeButton}</div>
diff --git a/frontend/src/components/agent-vault/service-sheet/serviceSchema.test.ts b/frontend/src/components/agent-vault/service-sheet/serviceSchema.test.ts
index 3e1cae84ed..40f3eddf5b 100644
--- a/frontend/src/components/agent-vault/service-sheet/serviceSchema.test.ts
+++ b/frontend/src/components/agent-vault/service-sheet/serviceSchema.test.ts
@@ -289,6 +289,23 @@ describe("buildServiceSchema with OAuth", () => {
expect(
buildServiceSchema().safeParse(mcpForm({ ...authorized, headerName: "Host" })).success
).toBe(true);
+ expect(
+ buildServiceSchema().safeParse(
+ mcpForm({ ...authorized, headerName: "X Api Key", headerPrefix: "p".repeat(65) })
+ ).success
+ ).toBe(true);
+ const bearer = buildServiceSchema().safeParse(
+ mcpForm({
+ credentialType: AgentVaultCredentialType.Bearer,
+ secret: "token",
+ headerName: "X Api Key",
+ headerPrefix: "p".repeat(65)
+ })
+ );
+ expect(bearer.error?.issues.map((issue) => issue.path.join("."))).toEqual([
+ "headerName",
+ "headerPrefix"
+ ]);
const clash = buildServiceSchema().safeParse(
mcpForm({
...authorized,
diff --git a/frontend/src/components/agent-vault/service-sheet/serviceSchema.ts b/frontend/src/components/agent-vault/service-sheet/serviceSchema.ts
index 4b1c6a9057..a30e3a78d9 100644
--- a/frontend/src/components/agent-vault/service-sheet/serviceSchema.ts
+++ b/frontend/src/components/agent-vault/service-sheet/serviceSchema.ts
@@ -267,16 +267,9 @@ export const buildServiceSchema = (
hostDraft: z.string(),
pathDraft: z.string(),
credentialType: z.nativeEnum(AgentVaultCredentialType),
- headerName: z
- .string()
- .trim()
- .max(128)
- .regex(
- /^[A-Za-z0-9!#$%&'*+.^_`|~-]*$/,
- "A header name can't contain spaces or colons. Use letters, digits and dashes, as in X-API-Key."
- )
- .optional(),
- headerPrefix: z.string().trim().max(64).optional(),
+ // Checked in superRefine, only while Bearer is selected: switching away hides these fields but keeps them.
+ headerName: z.string().trim().optional(),
+ headerPrefix: z.string().trim().optional(),
username: z.string().trim().max(256).optional(),
secret: z.string().max(8192).optional(),
oauthAuthorizationId: z.string(),
@@ -418,6 +411,31 @@ export const buildServiceSchema = (
credentialHeader = "Authorization";
}
+ if (hasHeaderShape && data.headerName) {
+ if (data.headerName.length > 128) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ path: ["headerName"],
+ message: "A header name can be at most 128 characters."
+ });
+ } else if (!/^[A-Za-z0-9!#$%&'*+.^_`|~-]*$/.test(data.headerName)) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ path: ["headerName"],
+ message:
+ "A header name can't contain spaces or colons. Use letters, digits and dashes, as in X-API-Key."
+ });
+ }
+ }
+
+ if (hasHeaderShape && data.headerPrefix && data.headerPrefix.length > 64) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ path: ["headerPrefix"],
+ message: "A prefix can be at most 64 characters."
+ });
+ }
+
// Basic and OAuth always write Authorization, which is not reserved, so only bearer can name one.
if (
hasHeaderShape &&