Skip to content

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

only accept one or another for now

Thiago Araujo da Silva0cc737366132
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.md
index 98986356d3..b3261b0c9d 100644
--- a/backend/CLAUDE.md
+++ b/backend/CLAUDE.md
@@ -249,8 +249,10 @@ invalidating anything already issued. Sessions are tagged with
`getOauthClientSessionUserAgent(clientId)`, the only handle we have on them. Rotation revokes only on
exchange applications: there the secret alone mints tokens for any user, whereas in the redirect flow it
has to be paired with an authorization code or refresh token and blanket revocation would just sign
-everyone out. The tag is per client, not per grant, so a client holding both grants loses its
-redirect-flow tokens too (the safe direction, and only reachable through the API).
+everyone out. The tag is per client, not per grant, which is unambiguous because a client cannot hold
+both flows: `assertValidOauthClientGrantConfig` rejects the token-exchange grant alongside
+`authorization_code`, in the API as well as the UI, so an application is either a redirect-flow client or
+an exchange client. A service needing both registers twice.
**That sweep only reaps sessions that already exist, so the exchange rechecks the client after creating
its own.** `exchangeSubjectToken` authenticates the client, then spends provider discovery, JWKS
diff --git a/backend/e2e-test/routes/v1/oauth-token-exchange.spec.ts b/backend/e2e-test/routes/v1/oauth-token-exchange.spec.ts
index 3f2acea77b..9730751e74 100644
--- a/backend/e2e-test/routes/v1/oauth-token-exchange.spec.ts
+++ b/backend/e2e-test/routes/v1/oauth-token-exchange.spec.ts
@@ -116,6 +116,20 @@ describe("OAuth client grant type registration", async () => {
expect(res.payload).toContain("audience only applies");
});
+ // An application is one flow or the other, so the UI's flow picker is the whole story and an edit made
+ // through it can never silently drop a grant the API had registered.
+ test("an application cannot hold both the redirect flow and token exchange", async () => {
+ const res = await createClient({
+ name: "e2e-both-flows",
+ grantTypes: [OauthGrantType.AuthorizationCode, OauthGrantType.RefreshToken, TOKEN_EXCHANGE_GRANT],
+ redirectUris: ["https://app.example.com/callback"],
+ tokenExchangeAudience: "api://e2e-mcp"
+ });
+
+ expect(res.statusCode).toBe(400);
+ expect(res.payload).toContain("cannot be combined");
+ });
+
// Duplicates used to slip through below the array bound and come back as "too many items" above it,
// so the same mistake failed differently depending on how often it was repeated.
test("reports duplicate grant types as duplicates, however many there are", async () => {
diff --git a/backend/src/server/routes/v1/oauth-router.ts b/backend/src/server/routes/v1/oauth-router.ts
index 0ddb763dad..e7f5d317c9 100644
--- a/backend/src/server/routes/v1/oauth-router.ts
+++ b/backend/src/server/routes/v1/oauth-router.ts
@@ -33,7 +33,7 @@ const grantTypesSchema = z
message: "Grant types must not contain duplicate values"
})
.describe(
- "The OAuth grant types this application may use. Redirect URIs apply only to authorization_code; the token exchange audience applies only to the token-exchange grant."
+ "The OAuth grant types this application may use. An application uses either the redirect flow (authorization_code, optionally with refresh_token) or the token-exchange grant. Redirect URIs apply only to authorization_code; the token exchange audience applies only to the token-exchange grant."
);
const tokenExchangeAudienceSchema = z
diff --git a/backend/src/services/oauth-client/oauth-client-fns.test.ts b/backend/src/services/oauth-client/oauth-client-fns.test.ts
index 6bf0e8ce9f..c4c06d15f6 100644
--- a/backend/src/services/oauth-client/oauth-client-fns.test.ts
+++ b/backend/src/services/oauth-client/oauth-client-fns.test.ts
@@ -272,14 +272,24 @@ describe("assertValidOauthClientGrantConfig", () => {
expect(() => assertValidOauthClientGrantConfig(exchangeFlow)).not.toThrow();
});
- test("accepts an application registered for both grants", () => {
+ test("rejects an application registered for both flows", () => {
expect(() =>
assertValidOauthClientGrantConfig({
grantTypes: [OauthGrantType.AuthorizationCode, OauthGrantType.RefreshToken, OauthGrantType.TokenExchange],
resolved: { redirectUris: ["https://app.example.com/callback"], tokenExchangeAudience: "api://mcp" },
supplied: { redirectUris: ["https://app.example.com/callback"], tokenExchangeAudience: "api://mcp" }
})
- ).not.toThrow();
+ ).toThrow(/cannot be combined with the 'authorization_code' grant/);
+ });
+
+ test("rejects the token exchange grant alongside authorization_code alone", () => {
+ expect(() =>
+ assertValidOauthClientGrantConfig({
+ grantTypes: [OauthGrantType.AuthorizationCode, OauthGrantType.TokenExchange],
+ resolved: { redirectUris: ["https://app.example.com/callback"], tokenExchangeAudience: "api://mcp" },
+ supplied: { tokenExchangeAudience: "api://mcp" }
+ })
+ ).toThrow(/cannot be combined with the 'authorization_code' grant/);
});
test("rejects an empty grant type list", () => {
diff --git a/backend/src/services/oauth-client/oauth-client-fns.ts b/backend/src/services/oauth-client/oauth-client-fns.ts
index 13fff25c0b..48a64d101b 100644
--- a/backend/src/services/oauth-client/oauth-client-fns.ts
+++ b/backend/src/services/oauth-client/oauth-client-fns.ts
@@ -160,6 +160,12 @@ export const assertValidOauthClientGrantConfig = ({ grantTypes, resolved, suppli
const isRedirectBased = grantTypes.includes(OauthGrantType.AuthorizationCode);
const isTokenExchange = grantTypes.includes(OauthGrantType.TokenExchange);
+ if (isRedirectBased && isTokenExchange) {
+ throw new BadRequestError({
+ message: `The '${OauthGrantType.TokenExchange}' grant cannot be combined with the '${OauthGrantType.AuthorizationCode}' grant. An application uses one or the other. Register a second application if you need both flows.`
+ });
+ }
+
if (grantTypes.includes(OauthGrantType.RefreshToken) && !grantTypes.includes(OauthGrantType.AuthorizationCode)) {
throw new BadRequestError({
message: `The '${OauthGrantType.RefreshToken}' grant requires the '${OauthGrantType.AuthorizationCode}' grant, because refresh tokens are only issued by the authorization code flow.`
diff --git a/docs/documentation/platform/oauth-token-exchange.mdx b/docs/documentation/platform/oauth-token-exchange.mdx
index 346b9fb3c3..b637f3e410 100644
--- a/docs/documentation/platform/oauth-token-exchange.mdx
+++ b/docs/documentation/platform/oauth-token-exchange.mdx
@@ -93,6 +93,8 @@ You need permission to manage both OAuth applications and SSO, because enabling
- **Identity provider enforces MFA**: Turn this on to declare that your identity provider already requires MFA. Without it, exchanges fail for any user who requires MFA, because there is no Infisical MFA challenge to run.
There is no issuer to set here. Infisical always verifies against your organization's OIDC SSO provider, which cannot be overridden per application.
+
+ An application uses one flow or the other. Registering it for token exchange rules out the authorization code flow, and the reverse, so a service that needs both needs two registrations. This holds for the API too: sending `grantTypes` containing both the token-exchange grant and `authorization_code` is rejected.
</Step>
<Step title="Store the credentials">
Infisical shows the **Client ID** and **Client Secret** on creation.
diff --git a/frontend/src/hooks/api/oauthClients/types.ts b/frontend/src/hooks/api/oauthClients/types.ts
index a431b83cd1..8313c16170 100644
--- a/frontend/src/hooks/api/oauthClients/types.ts
+++ b/frontend/src/hooks/api/oauthClients/types.ts
@@ -1,4 +1,3 @@
-// Redirect URIs and PKCE apply only to AuthorizationCode, the audience only to TokenExchange.
export enum OauthGrantType {
AuthorizationCode = "authorization_code",
RefreshToken = "refresh_token",