Skip to content

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

honor azp

Thiago Araujo da Silva2737bca63359
diff --git a/backend/src/services/oauth-client/oauth-token-exchange-fns.test.ts b/backend/src/services/oauth-client/oauth-token-exchange-fns.test.ts
index 468e19ecb7..2b1ec9afc6 100644
--- a/backend/src/services/oauth-client/oauth-token-exchange-fns.test.ts
+++ b/backend/src/services/oauth-client/oauth-token-exchange-fns.test.ts
@@ -339,9 +339,17 @@ describe("verifySubjectToken", () => {
await expect(verify(token)).rejects.toThrow(/addressed to several audiences/);
});
- test("accepts a single-audience token that names a different authorized party", async () => {
+ // A token whose sole audience is our exchange audience can still have been minted for another client,
+ // so 'azp' has to be honoured here too.
+ test("rejects a single-audience token that names a different authorized party", async () => {
const token = signSubjectToken({ audience: AUDIENCE, authorizedParty: "some-client-id" });
+ await expect(verify(token)).rejects.toThrow(/was issued to 'some-client-id'/);
+ });
+
+ test("accepts a single-audience token whose authorized party is this application", async () => {
+ const token = signSubjectToken({ audience: AUDIENCE, authorizedParty: AUDIENCE });
+
await expect(verify(token)).resolves.toMatchObject({ subject: SUBJECT });
});
diff --git a/backend/src/services/oauth-client/oauth-token-exchange-fns.ts b/backend/src/services/oauth-client/oauth-token-exchange-fns.ts
index 07f4783bb3..6deaa97628 100644
--- a/backend/src/services/oauth-client/oauth-token-exchange-fns.ts
+++ b/backend/src/services/oauth-client/oauth-token-exchange-fns.ts
@@ -293,20 +293,18 @@ export const verifySubjectToken = async ({ subjectToken, oidcConfig, expectedAud
}
const audiences = Array.isArray(claims.aud) ? claims.aud : [claims.aud];
- if (audiences.length > 1) {
- const authorizedParty = typeof claims.azp === "string" ? claims.azp : undefined;
+ const authorizedParty = typeof claims.azp === "string" ? claims.azp : undefined;
- if (!authorizedParty) {
- throw new UnauthorizedError({
- message: `The subject token is addressed to several audiences (${audiences.join(", ")}) and carries no 'azp' claim, so there is no way to tell it was issued to this application rather than another one. Configure your identity provider to issue tokens addressed only to '${expectedAudience}', or to include an 'azp' claim.`
- });
- }
+ if (authorizedParty && authorizedParty !== expectedAudience) {
+ throw new UnauthorizedError({
+ message: `The subject token was issued to '${authorizedParty}', not to this application's configured token exchange audience ('${expectedAudience}'). Being addressed to this application as an audience is not enough to act on the user's behalf.`
+ });
+ }
- if (authorizedParty !== expectedAudience) {
- throw new UnauthorizedError({
- message: `The subject token was issued to '${authorizedParty}', not to this application's configured token exchange audience ('${expectedAudience}'). It is addressed to this application only as an additional audience, which is not enough to act on the user's behalf.`
- });
- }
+ if (!authorizedParty && audiences.length > 1) {
+ throw new UnauthorizedError({
+ message: `The subject token is addressed to several audiences (${audiences.join(", ")}) and carries no 'azp' claim, so there is no way to tell it was issued to this application rather than another one. Configure your identity provider to issue tokens addressed only to '${expectedAudience}', or to include an 'azp' claim.`
+ });
}
if (!claims.sub) {
diff --git a/docs/documentation/platform/oauth-token-exchange.mdx b/docs/documentation/platform/oauth-token-exchange.mdx
index 34d73aab59..346b9fb3c3 100644
--- a/docs/documentation/platform/oauth-token-exchange.mdx
+++ b/docs/documentation/platform/oauth-token-exchange.mdx
@@ -109,7 +109,7 @@ Your identity provider signs tokens for every application in your estate. Withou
Set it to your middleware's own registration in your identity provider, never to Infisical's.
-Some providers can be configured to address one token to several audiences at once, which would let a token minted for another application list yours alongside its own. When a subject token carries more than one audience, Infisical requires an `azp` (authorized party) claim naming your configured audience, and rejects the token otherwise. A token addressed to a single audience needs no `azp`.
+Some providers can be configured to address one token to several audiences at once, which would let a token minted for another application list yours alongside its own. When a subject token carries more than one audience, Infisical requires an `azp` (authorized party) claim naming your configured audience, and rejects the token otherwise. A token addressed to a single audience needs no `azp`, but if it carries one, that claim must name your configured audience as well.
## Exchanging a token