Skip to content

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

require exp

Thiago Araujo da Silvaad84f5d18609
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 1fca84c6de..055beec0f9 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
@@ -83,7 +83,7 @@ type TSignOptions = {
audience?: string | string[];
issuer?: string;
algorithm?: jwt.Algorithm;
- expiresIn?: string | number;
+ expiresIn?: string | number | null;
notBefore?: string | number;
subject?: string | null;
keyId?: string | null;
@@ -103,7 +103,7 @@ const signSubjectToken = ({
algorithm,
audience,
issuer,
- expiresIn,
+ ...(expiresIn !== null ? { expiresIn } : {}),
...(notBefore !== undefined ? { notBefore } : {}),
...(keyId ? { keyid: keyId } : {})
});
@@ -338,6 +338,13 @@ describe("verifySubjectToken", () => {
await expect(verify(token)).rejects.toThrow(/has expired/);
});
+ // 'exp' is optional in RFC 7519, so a token that omits it would otherwise stay exchangeable forever.
+ test("rejects a token with no exp claim", async () => {
+ const token = signSubjectToken({ expiresIn: null });
+
+ await expect(verify(token)).rejects.toThrow(/no 'exp' claim/);
+ });
+
test("rejects a token that is not yet valid", async () => {
const token = signSubjectToken({ notBefore: 600 });
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 f67d72e531..93483f7d97 100644
--- a/backend/src/services/oauth-client/oauth-token-exchange-fns.ts
+++ b/backend/src/services/oauth-client/oauth-token-exchange-fns.ts
@@ -172,6 +172,13 @@ const toSubjectTokenError = (error: unknown, anchor: TOidcTrustAnchor, expectedA
}
if (error instanceof joseErrors.JWTClaimValidationFailed) {
+ if (error.claim === "exp") {
+ return new UnauthorizedError({
+ message:
+ "The subject token has no 'exp' claim, so it never expires and cannot be accepted. Configure your identity provider to set an expiry on tokens it issues for this application."
+ });
+ }
+
if (error.claim === "aud") {
return new UnauthorizedError({
message: `The subject token's audience does not match this application's configured token exchange audience ('${expectedAudience}').`
@@ -272,7 +279,10 @@ export const verifySubjectToken = async ({ subjectToken, oidcConfig, expectedAud
({ payload: claims } = await jwtVerify(subjectToken, publicKey, {
issuer: anchor.issuer,
audience: expectedAudience,
- algorithms: [anchor.algorithm]
+ algorithms: [anchor.algorithm],
+ // 'exp' is optional in RFC 7519 and only checked when present, so without this a token that omits
+ // it is exchangeable forever.
+ requiredClaims: ["exp"]
}));
} catch (error) {
logger.error(
diff --git a/docs/documentation/platform/oauth-token-exchange.mdx b/docs/documentation/platform/oauth-token-exchange.mdx
index d6429e34ce..e0e0651ae4 100644
--- a/docs/documentation/platform/oauth-token-exchange.mdx
+++ b/docs/documentation/platform/oauth-token-exchange.mdx
@@ -86,6 +86,7 @@ Two things it deliberately cannot do:
- **OIDC SSO must be configured and enabled** for your organization.
- **Your identity provider must sign tokens with an asymmetric algorithm** (RS256, RS512, or EdDSA) and publish a key ID (`kid`) in the token header.
+- **The tokens it issues must carry an expiry (`exp`).** Standard OIDC providers always set one; a token without it would be replayable indefinitely, so Infisical rejects it.
- **Each user must have signed in to Infisical through OIDC SSO at least once.** Infisical matches the token's subject to the account created on that first sign-in, so a user who has only ever used your middleware cannot be resolved yet. Treat one browser sign-in as an onboarding step.
- **You need a dedicated registration for your middleware in your identity provider**, so its tokens carry an audience distinct from Infisical's own.
@@ -181,7 +182,7 @@ Every exchange checks all of the following, and fails the request with a message
- The **signature** validates against your identity provider's published keys.
- The **issuer** matches your organization's configured OIDC SSO issuer.
- The **audience** matches the audience configured on the application.
-- The token is **not expired** and not used before its `nbf` time.
+- The token **carries an `exp` claim and has not passed it**, and is not used before its `nbf` time. A token with no expiry is rejected rather than treated as valid forever.
- The **signing algorithm** matches your OIDC SSO configuration.
- The token's **subject** resolves to a user who has signed in through your organization's OIDC SSO and is an active member of the organization.
- **MFA** requirements are satisfied, either because none apply or because the application declares that the identity provider enforces them.