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
update docs
Thiago Araujo da Silvad351da9ee934
diff --git a/backend/src/services/oauth-client/oauth-client-service.ts b/backend/src/services/oauth-client/oauth-client-service.tsindex d2b7f2118f..48e352a9b5 100644--- a/backend/src/services/oauth-client/oauth-client-service.ts+++ b/backend/src/services/oauth-client/oauth-client-service.ts@@ -182,22 +182,27 @@ export const oauthClientServiceFactory = ({// MFA enforcement, the OIDC SSO configuration and OIDC user aliases all live on the root// organization, matching the login flow.- const getClientRootOrg = async (orgId: string): Promise<TOrganizations> => {+ // Both orgs are returned because callers on the exchange path need each of them: the root org for+ // federation state, the client's own org for its token lifetime setting. They are the same row+ // whenever the client does not belong to a sub-organization.+ const getClientOrgs = async (orgId: string): Promise<{ clientOrg: TOrganizations; rootOrg: TOrganizations }> => {const clientOrg = await orgDAL.findById(orgId);if (!clientOrg) throw new NotFoundError({ message: "OAuth client organization not found" });const isSubOrganization = Boolean(clientOrg.rootOrgId && clientOrg.id !== clientOrg.rootOrgId);- if (!isSubOrganization) return clientOrg;+ if (!isSubOrganization) return { clientOrg, rootOrg: clientOrg };const rootOrg = await orgDAL.findById(clientOrg.rootOrgId as string);if (!rootOrg) throw new NotFoundError({ message: "OAuth client organization not found" });- return rootOrg;+ return { clientOrg, rootOrg };};+ const getClientRootOrg = async (orgId: string) => (await getClientOrgs(orgId)).rootOrg;+// Token exchange has nothing to verify a subject token against until federation is live. Failing at// configuration time puts the message in front of the admin setting the application up.const getActiveOidcConfigOrThrow = async (orgId: string) => {- const rootOrg = await getClientRootOrg(orgId);+ const { clientOrg, rootOrg } = await getClientOrgs(orgId);const oidcConfig = await oidcConfigDAL.findOne({ orgId: rootOrg.id });if (!oidcConfig) {@@ -214,7 +219,7 @@ export const oauthClientServiceFactory = ({});}- return { oidcConfig, rootOrg };+ return { oidcConfig, rootOrg, clientOrg };};const createOauthClient = async (dto: TCreateOauthClientDTO, actor: OrgServiceActor) => {@@ -504,12 +509,11 @@ export const oauthClientServiceFactory = ({return client;};- const getTokenLifetimes = async (orgId: string) => {+ const resolveTokenLifetimes = (org?: TOrganizations) => {const appCfg = getConfig();let accessTokenExpiresIn: string | number = appCfg.JWT_AUTH_LIFETIME;let refreshTokenExpiresIn: string | number = appCfg.JWT_REFRESH_LIFETIME;- const org = await orgDAL.findById(orgId);if (org?.userTokenExpiration) {accessTokenExpiresIn = getMinExpiresIn(appCfg.JWT_AUTH_LIFETIME, org.userTokenExpiration);refreshTokenExpiresIn = org.userTokenExpiration;@@ -518,6 +522,8 @@ export const oauthClientServiceFactory = ({return { accessTokenExpiresIn, refreshTokenExpiresIn };};+ const getTokenLifetimes = async (orgId: string) => resolveTokenLifetimes(await orgDAL.findById(orgId));+// RFC 8693 token exchange: the SSO login path with the token supplied directly instead of collected// through a browser redirect, and an access token issued instead of a session cookie. With no redirect// URI, no PKCE and no browser session to anchor trust on, the audience check below is what stops any@@ -535,7 +541,7 @@ export const oauthClientServiceFactory = ({});}- const { oidcConfig, rootOrg } = await getActiveOidcConfigOrThrow(client.orgId);+ const { oidcConfig, rootOrg, clientOrg } = await getActiveOidcConfigOrThrow(client.orgId);const { subject } = await verifySubjectToken({subjectToken: dto.subjectToken,@@ -598,7 +604,7 @@ export const oauthClientServiceFactory = ({});if (!tokenSession) throw new BadRequestError({ message: "Failed to create user token session" });- const { accessTokenExpiresIn } = await getTokenLifetimes(client.orgId);+ const { accessTokenExpiresIn } = resolveTokenLifetimes(clientOrg);const accessToken = signOauthToken({diff --git a/backend/src/services/oauth-client/oauth-token-exchange-fns.ts b/backend/src/services/oauth-client/oauth-token-exchange-fns.tsindex 93483f7d97..f6cb24d01c 100644--- a/backend/src/services/oauth-client/oauth-token-exchange-fns.ts+++ b/backend/src/services/oauth-client/oauth-token-exchange-fns.ts@@ -32,9 +32,9 @@ const buildDiscoveryDocumentUrl = (discoveryUrl: string) => {type TOidcDiscoveryMetadata = { jwks_uri?: string; issuer?: string };-// Fetching the discovery document is a network round trip, and token exchange runs on every request the-// middleware makes, so resolving it per exchange would put the identity provider in the path of every-// Infisical API call that middleware makes, and make a blip at the provider fail all of them.+// Fetching the discovery document is a network round trip. Integrators are told to exchange once per+// user and cache the token, but we cannot enforce that, and a middleware that exchanges per request+// would otherwise make the identity provider a synchronous dependency of every Infisical call it serves.//// Only the fetch is cached, never the resolved trust anchor. The algorithm and the preferred issuer come// from the org's own SSO configuration, so an admin changing either still takes effect on the nextdiff --git a/docs/documentation/platform/oauth-token-exchange.mdx b/docs/documentation/platform/oauth-token-exchange.mdxindex 9a3ac269de..3684cfd361 100644--- a/docs/documentation/platform/oauth-token-exchange.mdx+++ b/docs/documentation/platform/oauth-token-exchange.mdx@@ -175,6 +175,25 @@ curl https://app.infisical.com/api/v4/secrets \Delegated tokens are currently accepted on the read-only secret-fetch endpoints. Endpoint coverage is expanding; if your integration needs an endpoint that rejects a delegated token, let us know which one.</Note>+## Cache the access token++<Warning>+ Exchange once per user and reuse the access token until it expires. Do not exchange on every request your middleware serves.+</Warning>++The access token is valid for `expires_in` seconds, usually an hour. Exchanging per request instead of per token throws away that whole window and makes your identity provider a hard dependency of every call you make to Infisical: a momentary blip there becomes a failure of your own request path, and both Infisical and your provider see traffic proportional to your request volume rather than to your user count.++Cache it keyed by user, and treat the exchange as the slow path:++- Keep the token in memory keyed by the subject token's `sub` claim, alongside its expiry.+- Reuse it while it is valid, refreshing slightly early (say 60 seconds before `expires_in` elapses) so an in-flight request never carries a token that expires mid-call.+- Exchange again when it is gone. No refresh token is issued, so re-exchange against the user's still-valid identity provider token.+- Drop the entry when the user's session at your identity provider ends, so their Infisical access does not outlive it.++<Note>+ The token endpoint is rate limited per source IP. A middleware that caches correctly makes roughly one exchange per user per token lifetime and stays well inside it; one that exchanges per request will be throttled under load. If you have sized your caching and still expect to approach the limit, contact us before rolling out.+</Note>+## What Infisical verifiesEvery exchange checks all of the following, and fails the request with a message naming the problem if any of them does not hold: