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
single use of token
Thiago Araujo da Silvaa6ea5647dfaf
diff --git a/backend/src/keystore/keystore.ts b/backend/src/keystore/keystore.tsindex 7c57d7cc33..b7fdb0039e 100644--- a/backend/src/keystore/keystore.ts+++ b/backend/src/keystore/keystore.ts@@ -88,6 +88,7 @@ export const KeyStorePrefixes = {UserMfaUnlockEmailSent: (userId: string) => `user-mfa-unlock-email-sent:${userId}` as const,UsedTotpCode: (userId: string, code: string) => `used-totp-code:${userId}:${code}` as const,UsedAccountRecoveryToken: (userId: string, jti: string) => `used-account-recovery-token:${userId}:${jti}` as const,+ UsedGitHubManifestState: (jti: string) => `used-github-manifest-state:${jti}` as const,AiMcpServerOAuth: (sessionId: string) => `ai-mcp-server-oauth:${sessionId}` as const,diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.tsindex 6205611223..293f3620ed 100644--- a/backend/src/server/routes/index.ts+++ b/backend/src/server/routes/index.ts@@ -1034,7 +1034,8 @@ export const registerRoutes = async (gitHubAppDAL,appConnectionDAL,permissionService,- kmsService+ kmsService,+ keyStore});// ldapService is created after loginService (below) due to dependency on processProviderCallbackdiff --git a/backend/src/services/github-app/github-app-service.ts b/backend/src/services/github-app/github-app-service.tsindex b930a462ad..f93c16796b 100644--- a/backend/src/services/github-app/github-app-service.ts+++ b/backend/src/services/github-app/github-app-service.ts@@ -5,6 +5,7 @@ import jwt from "jsonwebtoken";import { OrganizationActionScope } from "@app/db/schemas";import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";+import { KeyStorePrefixes, TKeyStoreFactory } from "@app/keystore/keystore";import { getConfig } from "@app/lib/config/env";import { crypto } from "@app/lib/crypto";import { DatabaseErrorCode } from "@app/lib/error-codes";@@ -37,6 +38,7 @@ type TGitHubAppServiceFactoryDep = {appConnectionDAL: Pick<TAppConnectionDALFactory, "countByGitHubApp">;permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;+ keyStore: Pick<TKeyStoreFactory, "setItemWithExpiryNX">;};export type TGitHubAppServiceFactory = ReturnType<typeof gitHubAppServiceFactory>;@@ -45,7 +47,8 @@ export const gitHubAppServiceFactory = ({gitHubAppDAL,appConnectionDAL,permissionService,- kmsService+ kmsService,+ keyStore}: TGitHubAppServiceFactoryDep) => {const listGitHubApps = async ({ orgPermission }: TListGitHubAppsDTO): Promise<TSanitizedGitHubApp[]> => {const { permission } = await permissionService.getOrgPermission({@@ -274,6 +277,7 @@ export const gitHubAppServiceFactory = ({const stateToken = jwt.sign({+ jti: crypto.nativeCrypto.randomUUID(),orgId: orgPermission.orgId,actorId: orgPermission.id,actorType: orgPermission.type,@@ -324,16 +328,27 @@ export const gitHubAppServiceFactory = ({throw new BadRequestError({ message: "SITE_URL is not configured." });}- let statePayload: TGitHubManifestStatePayload;+ let statePayload: TGitHubManifestStatePayload & { exp: number };try {- statePayload = jwt.verify(state, AUTH_SECRET) as TGitHubManifestStatePayload;+ statePayload = jwt.verify(state, AUTH_SECRET) as TGitHubManifestStatePayload & { exp: number };} catch {throw new BadRequestError({ message: "Invalid or expired GitHub manifest state. Please try again." });}- const { orgId, actorId, actorType, authMethod, name, instanceType, githubOrg, githubHost, installState } =+ const { jti, exp, orgId, actorId, actorType, authMethod, name, instanceType, githubOrg, githubHost, installState } =statePayload;+ if (!jti) {+ throw new BadRequestError({ message: "Invalid or expired GitHub manifest state. Please try again." });+ }+ const ttlSeconds = Math.max(1, exp - Math.floor(Date.now() / 1000));+ const claimed = await keyStore.setItemWithExpiryNX(KeyStorePrefixes.UsedGitHubManifestState(jti), ttlSeconds, "1");+ if (!claimed) {+ throw new BadRequestError({+ message: "This GitHub manifest registration link has already been used. Please try again."+ });+ }+const { permission } = await permissionService.getOrgPermission({actor: actorType as ActorType,actorId,diff --git a/backend/src/services/github-app/github-app-types.ts b/backend/src/services/github-app/github-app-types.tsindex 45a85041a4..3ed5e362fd 100644--- a/backend/src/services/github-app/github-app-types.ts+++ b/backend/src/services/github-app/github-app-types.ts@@ -10,6 +10,9 @@ export type TInitiateGitHubManifestDTO = {};export type TGitHubManifestStatePayload = {+ // Unique, single-use identifier. Consumed (claimed in the key store) on the first callback so a+ // captured state token cannot be replayed within its validity window.+ jti: string;orgId: string;actorId: string;actorType: string;