Skip to content

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

addressed greptile reviews

x032205513ebdba3f4f
diff --git a/backend/src/ee/routes/v1/pam-resource-routers/pam-resource-rotation-rules-router.ts b/backend/src/ee/routes/v1/pam-resource-routers/pam-resource-rotation-rules-router.ts
index f54a74e574..94aef7ceaa 100644
--- a/backend/src/ee/routes/v1/pam-resource-routers/pam-resource-rotation-rules-router.ts
+++ b/backend/src/ee/routes/v1/pam-resource-routers/pam-resource-rotation-rules-router.ts
@@ -112,6 +112,7 @@ export const registerPamResourceRotationRulesRouter = async (server: FastifyZodP
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
const rule = await server.services.pamResourceRotationRules.updateById(
+ req.params.resourceId,
req.params.ruleId,
req.body,
req.permission
@@ -142,7 +143,11 @@ export const registerPamResourceRotationRulesRouter = async (server: FastifyZodP
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
- const rule = await server.services.pamResourceRotationRules.deleteById(req.params.ruleId, req.permission);
+ const rule = await server.services.pamResourceRotationRules.deleteById(
+ req.params.resourceId,
+ req.params.ruleId,
+ req.permission
+ );
return { rule };
}
diff --git a/backend/src/ee/services/pam-account/pam-account-service.ts b/backend/src/ee/services/pam-account/pam-account-service.ts
index 2399fcdf5e..efdeac071d 100644
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@ -1124,7 +1124,13 @@ export const pamAccountServiceFactory = ({
// Read resource
const resource = await pamResourceDAL.findById(account.resourceId);
- if (!resource || !resource.encryptedRotationAccountCredentials) return;
+ if (!resource || !resource.encryptedRotationAccountCredentials) {
+ logger.warn(
+ `[Rotation] Resource or rotation credentials missing for account [accountId=${account.id}], releasing lock`
+ );
+ await pamAccountDAL.updateById(account.id, { rotationStatus: PamAccountRotationStatus.Failed });
+ return;
+ }
logResourceType = resource.resourceType;
const { connectionDetails, rotationAccountCredentials, gatewayId, resourceType } = await decryptResource(
@@ -1132,7 +1138,13 @@ export const pamAccountServiceFactory = ({
account.projectId,
kmsService
);
- if (!rotationAccountCredentials) return;
+ if (!rotationAccountCredentials) {
+ logger.warn(
+ `[Rotation] Decrypted rotation credentials missing for account [accountId=${account.id}], releasing lock`
+ );
+ await pamAccountDAL.updateById(account.id, { rotationStatus: PamAccountRotationStatus.Failed });
+ return;
+ }
// Perform rotation
const accountCredentials = await decryptAccountCredentials({
diff --git a/backend/src/ee/services/pam-resource/pam-resource-rotation-rules-service.ts b/backend/src/ee/services/pam-resource/pam-resource-rotation-rules-service.ts
index 8b1d6193e3..bba2c7060e 100644
--- a/backend/src/ee/services/pam-resource/pam-resource-rotation-rules-service.ts
+++ b/backend/src/ee/services/pam-resource/pam-resource-rotation-rules-service.ts
@@ -94,19 +94,25 @@ export const pamResourceRotationRulesServiceFactory = ({
throw new BadRequestError({ message: `Invalid glob pattern: ${namePattern}` });
}
- const maxPriority = await pamResourceRotationRulesDAL.getMaxPriority(resourceId);
-
- return pamResourceRotationRulesDAL.create({
- resourceId,
- name: name ?? null,
- namePattern,
- enabled,
- intervalSeconds: intervalSeconds ?? null,
- priority: maxPriority + 1
+ return pamResourceRotationRulesDAL.transaction(async (tx) => {
+ const maxPriority = await pamResourceRotationRulesDAL.getMaxPriority(resourceId, tx);
+
+ return pamResourceRotationRulesDAL.create(
+ {
+ resourceId,
+ name: name ?? null,
+ namePattern,
+ enabled,
+ intervalSeconds: intervalSeconds ?? null,
+ priority: maxPriority + 1
+ },
+ tx
+ );
});
};
const updateById = async (
+ resourceId: string,
ruleId: string,
updates: {
name?: string | null;
@@ -119,6 +125,10 @@ export const pamResourceRotationRulesServiceFactory = ({
const rule = await pamResourceRotationRulesDAL.findById(ruleId);
if (!rule) throw new NotFoundError({ message: `Rotation rule with ID '${ruleId}' not found` });
+ if (rule.resourceId !== resourceId) {
+ throw new BadRequestError({ message: `Rule '${ruleId}' does not belong to resource '${resourceId}'` });
+ }
+
await ensureEditPermission(rule.resourceId, actor);
const finalEnabled = updates.enabled ?? rule.enabled;
@@ -139,10 +149,14 @@ export const pamResourceRotationRulesServiceFactory = ({
return pamResourceRotationRulesDAL.updateById(ruleId, updates);
};
- const deleteById = async (ruleId: string, actor: OrgServiceActor) => {
+ const deleteById = async (resourceId: string, ruleId: string, actor: OrgServiceActor) => {
const rule = await pamResourceRotationRulesDAL.findById(ruleId);
if (!rule) throw new NotFoundError({ message: `Rotation rule with ID '${ruleId}' not found` });
+ if (rule.resourceId !== resourceId) {
+ throw new BadRequestError({ message: `Rule '${ruleId}' does not belong to resource '${resourceId}'` });
+ }
+
await ensureEditPermission(rule.resourceId, actor);
return pamResourceRotationRulesDAL.deleteById(ruleId);
@@ -153,6 +167,11 @@ export const pamResourceRotationRulesServiceFactory = ({
const existingRules = await pamResourceRotationRulesDAL.findByResourceId(resourceId);
const existingIds = new Set(existingRules.map((r) => r.id));
+ const uniqueRuleIds = new Set(orderedRuleIds);
+
+ if (uniqueRuleIds.size !== orderedRuleIds.length) {
+ throw new BadRequestError({ message: "Duplicate rule IDs are not allowed" });
+ }
for (const id of orderedRuleIds) {
if (!existingIds.has(id)) {
diff --git a/backend/src/ee/services/pam-resource/shared/dependency-sync-fns.ts b/backend/src/ee/services/pam-resource/shared/dependency-sync-fns.ts
index 819698da22..6c6c7eebd2 100644
--- a/backend/src/ee/services/pam-resource/shared/dependency-sync-fns.ts
+++ b/backend/src/ee/services/pam-resource/shared/dependency-sync-fns.ts
@@ -17,8 +17,11 @@ import { TPostRotateContext } from "../pam-resource-types";
export const WINRM_DEFAULT_HTTP_PORT = 5985;
export const WINRM_DEFAULT_HTTPS_PORT = 5986;
-// Escape a string for use inside PowerShell single-quoted strings (doubles single quotes)
-export const escapePowershellSingleQuote = (value: string) => new RE2("'", "g").replace(value, "''");
+// Sanitize a string for safe use inside PowerShell single-quoted strings:
+// - doubles single quotes (PowerShell escape)
+// - strips newlines/carriage returns
+export const escapePowershellSingleQuote = (value: string) =>
+ new RE2("'", "g").replace(value, "''").replace(/[\r\n]/g, "");
export const buildDependencySyncScript = (
dep: TPamAccountDependencies,
diff --git a/backend/src/ee/services/permission/default-roles.ts b/backend/src/ee/services/permission/default-roles.ts
index d9f184ac64..4847784ce0 100644
--- a/backend/src/ee/services/permission/default-roles.ts
+++ b/backend/src/ee/services/permission/default-roles.ts
@@ -392,8 +392,7 @@ const buildAdminPermissionRules = () => {
ProjectPermissionPamAccountActions.Create,
ProjectPermissionPamAccountActions.Edit,
ProjectPermissionPamAccountActions.Delete,
- ProjectPermissionPamAccountActions.TriggerRotation,
- ProjectPermissionPamAccountActions.EditRotationConfig
+ ProjectPermissionPamAccountActions.TriggerRotation
],
ProjectPermissionSub.PamAccounts
);
diff --git a/backend/src/ee/services/permission/project-permission.ts b/backend/src/ee/services/permission/project-permission.ts
index 4e7db18e5d..c14fe6586f 100644
--- a/backend/src/ee/services/permission/project-permission.ts
+++ b/backend/src/ee/services/permission/project-permission.ts
@@ -254,8 +254,7 @@ export enum ProjectPermissionPamAccountActions {
Create = "create",
Edit = "edit",
Delete = "delete",
- TriggerRotation = "trigger-rotation",
- EditRotationConfig = "edit-rotation-config"
+ TriggerRotation = "trigger-rotation"
}
export enum ProjectPermissionPamSessionActions {
diff --git a/frontend/src/context/ProjectPermissionContext/types.ts b/frontend/src/context/ProjectPermissionContext/types.ts
index b875303243..c6f144623f 100644
--- a/frontend/src/context/ProjectPermissionContext/types.ts
+++ b/frontend/src/context/ProjectPermissionContext/types.ts
@@ -257,8 +257,7 @@ export enum ProjectPermissionPamAccountActions {
Create = "create",
Edit = "edit",
Delete = "delete",
- TriggerRotation = "trigger-rotation",
- EditRotationConfig = "edit-rotation-config"
+ TriggerRotation = "trigger-rotation"
}
export enum ProjectPermissionPamSessionActions {
diff --git a/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceRotationRulesSection.tsx b/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceRotationRulesSection.tsx
index ac2572a335..460eb32d69 100644
--- a/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceRotationRulesSection.tsx
+++ b/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceRotationRulesSection.tsx
@@ -22,8 +22,7 @@ import {
UnstableTableHeader,
UnstableTableRow
} from "@app/components/v3";
-import { ProjectPermissionSub } from "@app/context";
-import { ProjectPermissionPamAccountActions } from "@app/context/ProjectPermissionContext/types";
+import { ProjectPermissionActions, ProjectPermissionSub } from "@app/context";
import {
useCreatePamRotationRule,
useDeletePamRotationRule,
@@ -181,8 +180,8 @@ export const PamResourceRotationRulesSection = ({ resource }: Props) => {
</p>
</div>
<ProjectPermissionCan
- I={ProjectPermissionPamAccountActions.EditRotationConfig}
- a={ProjectPermissionSub.PamAccounts}
+ I={ProjectPermissionActions.Edit}
+ a={ProjectPermissionSub.PamResources}
>
{(isAllowed) => (
<Button size="xs" onClick={openCreateForm} isDisabled={!isAllowed}>