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
fix(pam): validate gateway org ownership on resource and domain create/update
Saif15da0bdbb435
diff --git a/backend/src/ee/services/pam-domain/pam-domain-service.ts b/backend/src/ee/services/pam-domain/pam-domain-service.tsindex 4e2ca88913..63db99c336 100644--- a/backend/src/ee/services/pam-domain/pam-domain-service.ts+++ b/backend/src/ee/services/pam-domain/pam-domain-service.ts@@ -45,6 +45,7 @@ export const pamDomainServiceFactory = ({pamResourceDAL,permissionService,kmsService,+ gatewayV2DAL,gatewayV2Service,gatewayPoolService,resourceMetadataDAL@@ -115,7 +116,12 @@ export const pamDomainServiceFactory = ({}));- if (gatewayPoolId) {+ if (gatewayId) {+ const gateway = await gatewayV2DAL.findOne({ id: gatewayId, orgId: actor.orgId });+ if (!gateway) {+ throw new NotFoundError({ message: "Gateway not found or does not belong to this organization" });+ }+ } else if (gatewayPoolId) {await gatewayPoolService.resolveAttachableGatewayFromPool({poolId: gatewayPoolId,orgId: actor.orgId,@@ -232,7 +238,12 @@ export const pamDomainServiceFactory = ({);}- if (gatewayPoolId && gatewayPoolId !== domain.gatewayPoolId) {+ if (gatewayId && gatewayId !== domain.gatewayId) {+ const gateway = await gatewayV2DAL.findOne({ id: gatewayId, orgId: actor.orgId });+ if (!gateway) {+ throw new NotFoundError({ message: "Gateway not found or does not belong to this organization" });+ }+ } else if (gatewayPoolId && gatewayPoolId !== domain.gatewayPoolId) {await gatewayPoolService.resolveAttachableGatewayFromPool({poolId: gatewayPoolId,orgId: actor.orgId,diff --git a/backend/src/ee/services/pam-domain/pam-domain-types.ts b/backend/src/ee/services/pam-domain/pam-domain-types.tsindex e320bc5978..92b181b088 100644--- a/backend/src/ee/services/pam-domain/pam-domain-types.ts+++ b/backend/src/ee/services/pam-domain/pam-domain-types.ts@@ -6,6 +6,7 @@ import { TResourceMetadataDALFactory } from "@app/services/resource-metadata/resimport { ResourceMetadataNonEncryptionSchema } from "@app/services/resource-metadata/resource-metadata-schema";import { TGatewayPoolServiceFactory } from "../gateway-pool/gateway-pool-service";+import { TGatewayV2DALFactory } from "../gateway-v2/gateway-v2-dal";import { TGatewayV2ServiceFactory } from "../gateway-v2/gateway-v2-service";import { TPamResourceDALFactory } from "../pam-resource/pam-resource-dal";import { TPostRotateContext } from "../pam-resource/pam-resource-types";@@ -68,6 +69,7 @@ export type TPamDomainServiceFactoryDep = {pamResourceDAL: Pick<TPamResourceDALFactory, "find" | "findById">;permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;+ gatewayV2DAL: Pick<TGatewayV2DALFactory, "findOne">;gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;gatewayPoolService: Pick<TGatewayPoolServiceFactory,diff --git a/backend/src/ee/services/pam-resource/pam-resource-service.ts b/backend/src/ee/services/pam-resource/pam-resource-service.tsindex 02b6f534b7..6162abd5fd 100644--- a/backend/src/ee/services/pam-resource/pam-resource-service.ts+++ b/backend/src/ee/services/pam-resource/pam-resource-service.ts@@ -24,6 +24,7 @@ import { TUsageMeteringServiceFactory } from "@app/services/license-client/usageimport { TResourceMetadataDALFactory } from "@app/services/resource-metadata/resource-metadata-dal";import { TGatewayPoolServiceFactory } from "../gateway-pool/gateway-pool-service";+import { TGatewayV2DALFactory } from "../gateway-v2/gateway-v2-dal";import { TGatewayV2ServiceFactory } from "../gateway-v2/gateway-v2-service";import { TPamAccountDALFactory } from "../pam-account/pam-account-dal";import { PamAccountView } from "../pam-account/pam-account-enums";@@ -61,6 +62,7 @@ type TPamResourceServiceFactoryDep = {TGatewayV2ServiceFactory,"getPAMConnectionDetails" | "getPlatformConnectionDetailsByGatewayId">;+ gatewayV2DAL: Pick<TGatewayV2DALFactory, "findOne">;gatewayPoolService: Pick<TGatewayPoolServiceFactory,"resolveEffectiveGatewayId" | "resolveAttachableGatewayFromPool"@@ -82,6 +84,7 @@ export const pamResourceServiceFactory = ({pamAccountDAL,permissionService,kmsService,+ gatewayV2DAL,gatewayV2Service,gatewayPoolService,resourceMetadataDAL,@@ -209,7 +212,12 @@ export const pamResourceServiceFactory = ({}));- if (gatewayPoolId) {+ if (gatewayId) {+ const gateway = await gatewayV2DAL.findOne({ id: gatewayId, orgId: actor.orgId });+ if (!gateway) {+ throw new NotFoundError({ message: "Gateway not found or does not belong to this organization" });+ }+ } else if (gatewayPoolId) {await gatewayPoolService.resolveAttachableGatewayFromPool({poolId: gatewayPoolId,orgId: actor.orgId,@@ -363,7 +371,12 @@ export const pamResourceServiceFactory = ({);}- if (gatewayPoolId && gatewayPoolId !== resource.gatewayPoolId) {+ if (gatewayId && gatewayId !== resource.gatewayId) {+ const gateway = await gatewayV2DAL.findOne({ id: gatewayId, orgId: actor.orgId });+ if (!gateway) {+ throw new NotFoundError({ message: "Gateway not found or does not belong to this organization" });+ }+ } else if (gatewayPoolId && gatewayPoolId !== resource.gatewayPoolId) {await gatewayPoolService.resolveAttachableGatewayFromPool({poolId: gatewayPoolId,orgId: actor.orgId,diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.tsindex 8eec14bc63..15a0b5f381 100644--- a/backend/src/server/routes/index.ts+++ b/backend/src/server/routes/index.ts@@ -3427,6 +3427,7 @@ export const registerRoutes = async (pamAccountDAL,permissionService,kmsService,+ gatewayV2DAL,gatewayV2Service,gatewayPoolService,resourceMetadataDAL,@@ -3440,6 +3441,7 @@ export const registerRoutes = async (pamResourceDAL,permissionService,kmsService,+ gatewayV2DAL,gatewayV2Service,gatewayPoolService,resourceMetadataDAL