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
misc: security hardening for pam credential fetch
Sheen Capadngan7227d43673bf
diff --git a/backend/src/ee/services/pam-account/pam-account-service.ts b/backend/src/ee/services/pam-account/pam-account-service.tsindex 76fcfdd54f..e9ea76e8cb 100644--- a/backend/src/ee/services/pam-account/pam-account-service.ts+++ b/backend/src/ee/services/pam-account/pam-account-service.ts@@ -490,6 +490,12 @@ export const pamAccountServiceFactory = ({const resource = await pamResourceDAL.findById(account.resourceId);if (!resource) throw new NotFoundError({ message: `Resource with ID '${account.resourceId}' not found` });+ if (resource.gatewayIdentityId !== actor.id) {+ throw new ForbiddenRequestError({+ message: "Identity does not have access to fetch the PAM session credentials"+ });+ }+const decryptedAccount = await decryptAccount(account, session.projectId, kmsService);const decryptedResource = await decryptResource(resource, session.projectId, kmsService);diff --git a/backend/src/ee/services/pam-resource/pam-resource-dal.ts b/backend/src/ee/services/pam-resource/pam-resource-dal.tsindex 939e56f272..1a408ca27a 100644--- a/backend/src/ee/services/pam-resource/pam-resource-dal.ts+++ b/backend/src/ee/services/pam-resource/pam-resource-dal.ts@@ -1,9 +1,24 @@+import { Knex } from "knex";+import { TDbClient } from "@app/db";import { TableName } from "@app/db/schemas";-import { ormify } from "@app/lib/knex";+import { ormify, selectAllTableCols } from "@app/lib/knex";export type TPamResourceDALFactory = ReturnType<typeof pamResourceDALFactory>;export const pamResourceDALFactory = (db: TDbClient) => {const orm = ormify(db, TableName.PamResource);- return { ...orm };++ const findById = async (id: string, tx?: Knex) => {+ const doc = await (tx || db.replicaNode())(TableName.PamResource)+ .join(TableName.GatewayV2, `${TableName.PamResource}.gatewayId`, `${TableName.GatewayV2}.id`)+ .select(selectAllTableCols(TableName.PamResource))+ .select(db.ref("name").withSchema(TableName.GatewayV2).as("gatewayName"))+ .select(db.ref("identityId").withSchema(TableName.GatewayV2).as("gatewayIdentityId"))+ .where(`${TableName.PamResource}.id`, id)+ .first();++ return doc;+ };++ return { ...orm, findById };};