Skip to content

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

fix: add policy type on method

adilson3ffe799ee4dc
diff --git a/backend/e2e-test/routes/v1/access-approval-policy.spec.ts b/backend/e2e-test/routes/v1/access-approval-policy.spec.ts
index f38658cb8d..3b7b8e7a96 100644
--- a/backend/e2e-test/routes/v1/access-approval-policy.spec.ts
+++ b/backend/e2e-test/routes/v1/access-approval-policy.spec.ts
@@ -319,11 +319,11 @@ describe("Access approval policy router", async () => {
const asMember = await deletePolicyThroughGenericEndpoint(policy.id, member.token);
expect(asMember.statusCode).toBe(403);
- expect(asMember.json().message).not.toContain("secret access policy");
+ expect(asMember.json().message).not.toContain("secret-access");
const asAdmin = await deletePolicyThroughGenericEndpoint(policy.id, jwtAuthToken);
expect(asAdmin.statusCode).toBe(400);
- expect(asAdmin.json().message).toContain("secret access policy");
+ expect(asAdmin.json().message).toContain("expected pam-access, got secret-access");
const stillThere = await db(TableName.ApprovalPolicies).where({ id: policy.id }).first();
expect(stillThere).toBeDefined();
diff --git a/backend/src/server/routes/v1/approval-policy-routers/approval-policy-endpoints.ts b/backend/src/server/routes/v1/approval-policy-routers/approval-policy-endpoints.ts
index b21c84ab5c..d7e3541c8a 100644
--- a/backend/src/server/routes/v1/approval-policy-routers/approval-policy-endpoints.ts
+++ b/backend/src/server/routes/v1/approval-policy-routers/approval-policy-endpoints.ts
@@ -202,7 +202,11 @@ export const registerApprovalPolicyEndpoints = ({
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
- const { policy } = await server.services.approvalPolicy.getById(req.params.policyId, req.permission);
+ const { policy } = await server.services.approvalPolicy.getById(
+ req.params.policyId,
+ req.permission,
+ policyType
+ );
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
@@ -246,7 +250,8 @@ export const registerApprovalPolicyEndpoints = ({
const { policy } = await server.services.approvalPolicy.updateById(
req.params.policyId,
req.body as TUpdatePolicyDTO,
- req.permission
+ req.permission,
+ policyType
);
await server.services.auditLog.createAuditLog({
@@ -302,7 +307,8 @@ export const registerApprovalPolicyEndpoints = ({
handler: async (req) => {
const { policyId, projectId } = await server.services.approvalPolicy.deleteById(
req.params.policyId,
- req.permission
+ req.permission,
+ policyType
);
await server.services.auditLog.createAuditLog({
diff --git a/backend/src/services/approval-policy/approval-policy-service.ts b/backend/src/services/approval-policy/approval-policy-service.ts
index de9b2994ae..6aae054f0c 100644
--- a/backend/src/services/approval-policy/approval-policy-service.ts
+++ b/backend/src/services/approval-policy/approval-policy-service.ts
@@ -758,7 +758,7 @@ export const approvalPolicyServiceFactory = ({
return { policies, projectId };
};
- const getById = async (policyId: string, actor: TApprovalActor) => {
+ const getById = async (policyId: string, actor: TApprovalActor, policyType: ApprovalPolicyType) => {
const policy = await approvalPolicyDAL.findById(policyId);
if (!policy) {
throw new ForbiddenRequestError({ message: "Policy not found" });
@@ -773,9 +773,9 @@ export const approvalPolicyServiceFactory = ({
policy.type as ApprovalPolicyType
);
- if (policy.type === ApprovalPolicyType.SecretAccess) {
+ if (policy.type !== policyType) {
throw new BadRequestError({
- message: "This is a secret access policy. Get it from the access approval endpoint instead."
+ message: `Policy type mismatch: expected ${policyType}, got ${policy.type}`
});
}
@@ -799,7 +799,8 @@ export const approvalPolicyServiceFactory = ({
enforcementLevel,
bypassers
}: TUpdatePolicyDTO,
- actor: TApprovalActor
+ actor: TApprovalActor,
+ policyType: ApprovalPolicyType
) => {
const policy = await approvalPolicyDAL.findById(policyId);
if (!policy) {
@@ -818,9 +819,9 @@ export const approvalPolicyServiceFactory = ({
policy.type as ApprovalPolicyType
);
- if (policy.type === ApprovalPolicyType.SecretAccess) {
+ if (policy.type !== policyType) {
throw new BadRequestError({
- message: "This is a secret access policy. Update it from the access approval policies instead."
+ message: `Policy type mismatch: expected ${policyType}, got ${policy.type}`
});
}
@@ -940,7 +941,7 @@ export const approvalPolicyServiceFactory = ({
};
};
- const deleteById = async (policyId: string, actor: TApprovalActor) => {
+ const deleteById = async (policyId: string, actor: TApprovalActor, policyType: ApprovalPolicyType) => {
const policy = await approvalPolicyDAL.findById(policyId);
if (!policy) {
throw new ForbiddenRequestError({ message: "Policy not found" });
@@ -955,9 +956,9 @@ export const approvalPolicyServiceFactory = ({
policy.type as ApprovalPolicyType
);
- if (policy.type === ApprovalPolicyType.SecretAccess) {
+ if (policy.type !== policyType) {
throw new BadRequestError({
- message: "This is a secret access policy. Delete it from the access approval policies instead."
+ message: `Policy type mismatch: expected ${policyType}, got ${policy.type}`
});
}
@@ -2387,7 +2388,7 @@ export const approvalPolicyServiceFactory = ({
const hasApprovers = steps.some((step) => step.approvers.length > 0);
if (!hasApprovers) {
- if (existing) await deleteById(existing.id, actor);
+ if (existing) await deleteById(existing.id, actor, policyType);
return { policyId: existing?.id ?? null };
}
@@ -2395,7 +2396,7 @@ export const approvalPolicyServiceFactory = ({
const bypassFields = bypassers ? { bypassers } : {};
if (existing) {
- const { policy } = await updateById(existing.id, { steps: policySteps, ...bypassFields }, actor);
+ const { policy } = await updateById(existing.id, { steps: policySteps, ...bypassFields }, actor, policyType);
return { policyId: policy.id };
}