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
improvement: set cache lifetime to token expiry
Scott Wilsond4b06ce6488f
diff --git a/backend/src/keystore/keystore.ts b/backend/src/keystore/keystore.tsindex 7260fd832a..7cb72229e3 100644--- a/backend/src/keystore/keystore.ts+++ b/backend/src/keystore/keystore.ts@@ -138,7 +138,6 @@ export const KeyStoreTtls = {MfaSessionInSeconds: 300, // 5 minutesWebAuthnChallengeInSeconds: 300, // 5 minutesUsedTotpCodeInSeconds: 120, // covers the full ±30s acceptance window (window:1 → 90s) with margin- UsedAccountRecoveryTokenInSeconds: 900, // 15 minutes — matches JWT_SIGNUP_LIFETIME defaultProjectSSEConnectionTtlSeconds: 180, // Must be > heartbeat interval (60s) * 2TelemetryIdentifyIdentityInSeconds: 86400, // 24 hoursRefreshTokenGraceInSeconds: 10,diff --git a/backend/src/server/routes/v2/password-router.ts b/backend/src/server/routes/v2/password-router.tsindex 03a7cc4866..1d4dd8c598 100644--- a/backend/src/server/routes/v2/password-router.ts+++ b/backend/src/server/routes/v2/password-router.ts@@ -26,7 +26,8 @@ export const registerPasswordRouter = async (server: FastifyZodProvider) => {type: ResetPasswordV2Type.Recovery,newPassword: req.body.newPassword,userId: token.userId,- recoveryTokenJti: token.jti+ recoveryTokenJti: token.jti,+ recoveryTokenExpiresAt: token.exp});}});diff --git a/backend/src/services/auth/auth-password-service.ts b/backend/src/services/auth/auth-password-service.tsindex 740412e981..359d94953f 100644--- a/backend/src/services/auth/auth-password-service.ts+++ b/backend/src/services/auth/auth-password-service.ts@@ -1,4 +1,4 @@-import { KeyStorePrefixes, KeyStoreTtls, TKeyStoreFactory } from "@app/keystore/keystore";+import { KeyStorePrefixes, TKeyStoreFactory } from "@app/keystore/keystore";import { getConfig } from "@app/lib/config/env";import { crypto } from "@app/lib/crypto/cryptography";import { BadRequestError, UnauthorizedError } from "@app/lib/errors";@@ -30,16 +30,26 @@ export const authPaswordServiceFactory = ({smtpService,keyStore}: TAuthPasswordServiceFactoryDep) => {- const resetPasswordV2 = async ({ userId, newPassword, oldPassword, type, recoveryTokenJti }: TResetPasswordV2DTO) => {+ const resetPasswordV2 = async ({+ userId,+ newPassword,+ oldPassword,+ type,+ recoveryTokenJti,+ recoveryTokenExpiresAt+ }: TResetPasswordV2DTO) => {const cfg = getConfig();if (type === ResetPasswordV2Type.Recovery) {- if (!recoveryTokenJti) {+ if (!recoveryTokenJti || !recoveryTokenExpiresAt) {throw new UnauthorizedError({ message: "Invalid recovery token" });}+ // Marker TTL tracks the token's own remaining lifetime so non-default JWT_SIGNUP_LIFETIME+ // configs can't outlast the replay marker and reopen the reuse window.+ const ttlSeconds = Math.max(1, recoveryTokenExpiresAt - Math.floor(Date.now() / 1000));const claimed = await keyStore.setItemWithExpiryNX(KeyStorePrefixes.UsedAccountRecoveryToken(userId, recoveryTokenJti),- KeyStoreTtls.UsedAccountRecoveryTokenInSeconds,+ ttlSeconds,"1");if (!claimed) {diff --git a/backend/src/services/auth/auth-password-type.ts b/backend/src/services/auth/auth-password-type.tsindex 48d919073c..5878e0afda 100644--- a/backend/src/services/auth/auth-password-type.ts+++ b/backend/src/services/auth/auth-password-type.ts@@ -9,6 +9,7 @@ export type TResetPasswordV2DTO = {newPassword: string;oldPassword?: string;recoveryTokenJti?: string;+ recoveryTokenExpiresAt?: number;};export type TResetPasswordViaBackupKeyDTO = {diff --git a/backend/src/services/auth/auth-type.ts b/backend/src/services/auth/auth-type.tsindex 0fda15cd5b..4ab41adf50 100644--- a/backend/src/services/auth/auth-type.ts+++ b/backend/src/services/auth/auth-type.ts@@ -123,6 +123,7 @@ export type AuthModeAccountRecoveryTokenPayload = {authTokenType: AuthTokenType.ACCOUNT_RECOVERY_TOKEN;userId: string;jti: string;+ exp: number;};export enum MfaMethod {