Skip to content

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

greptile review fixes

x032205154db819a1e9
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 0d2c444c18..638ee48ffa 100644
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@ -1325,21 +1325,6 @@ export const pamAccountServiceFactory = ({
throw new BadRequestError({ message: "Account is already being rotated" });
}
- // Prevent the rotation account from rotating its own password
- const { rotationAccountCredentials } = await decryptResource(resource, account.projectId, kmsService);
- const accountCredentials = await decryptAccountCredentials({
- encryptedCredentials: account.encryptedCredentials,
- projectId: account.projectId,
- kmsService
- });
- const rotationUsername = (rotationAccountCredentials as { username?: string })?.username;
- const accountUsername = (accountCredentials as { username?: string })?.username;
- if (rotationUsername && accountUsername && rotationUsername.toLowerCase() === accountUsername.toLowerCase()) {
- throw new BadRequestError({
- message: "This account cannot be rotated because it is used as the rotation credentials"
- });
- }
-
void rotateAccount(account).catch((err) => {
logger.error(err, `Background rotation failed for account [accountId=${accountId}]`);
});
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 17de74feed..7e3f3367ca 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
@@ -19,7 +19,11 @@ export const WINRM_DEFAULT_HTTPS_PORT = 5986;
const SINGLE_QUOTE_RE = new RE2("'", "g");
const NEWLINE_RE = new RE2("[\\r\\n]", "g");
-const SAFE_WINDOWS_PATH_RE = new RE2("^[a-zA-Z0-9\\s\\\\_\\-.\\\\]+$");
+
+// Allow alphanumerics, spaces, single backslash, hyphen, underscore, dot, but NOT ".." sequences
+const SAFE_WINDOWS_NAME_RE = new RE2("^[a-zA-Z0-9 _\\-.]+$");
+const SAFE_WINDOWS_PATH_RE = new RE2("^[a-zA-Z0-9 _\\-.\\\\/]+$");
+const PATH_TRAVERSAL_RE = new RE2("\\.\\.");
// Sanitize a string for safe use inside PowerShell single-quoted strings:
// - doubles single quotes (PowerShell escape)
@@ -27,23 +31,29 @@ const SAFE_WINDOWS_PATH_RE = new RE2("^[a-zA-Z0-9\\s\\\\_\\-.\\\\]+$");
export const escapePowershellSingleQuote = (value: string) =>
NEWLINE_RE.replace(SINGLE_QUOTE_RE.replace(value, "''"), "");
-const validateWindowsPathValue = (value: string, label: string) => {
- if (!SAFE_WINDOWS_PATH_RE.test(value)) {
+const validateWindowsName = (value: string, label: string) => {
+ if (!SAFE_WINDOWS_NAME_RE.test(value)) {
throw new Error(`${label} contains invalid characters: ${value}`);
}
};
+const validateWindowsPath = (value: string, label: string) => {
+ if (!SAFE_WINDOWS_PATH_RE.test(value) || PATH_TRAVERSAL_RE.test(value)) {
+ throw new Error(`${label} contains invalid characters or path traversal: ${value}`);
+ }
+};
+
export const buildDependencySyncScript = (
dep: TPamAccountDependencies,
accountUsername: string,
newPassword: string
): string => {
- validateWindowsPathValue(dep.name, "Dependency name");
-
const escapedPassword = escapePowershellSingleQuote(newPassword);
const escapedName = escapePowershellSingleQuote(dep.name);
const escapedUsername = escapePowershellSingleQuote(accountUsername);
+ validateWindowsName(escapedName, "Dependency name");
+
switch (dep.dependencyType) {
case PamAccountDependencyType.WindowsService:
return [
@@ -54,8 +64,8 @@ export const buildDependencySyncScript = (
case PamAccountDependencyType.ScheduledTask: {
const taskData = dep.data as { TaskPath?: string } | null;
const taskPath = taskData?.TaskPath ?? "\\";
- validateWindowsPathValue(taskPath, "Task path");
const escapedPath = escapePowershellSingleQuote(taskPath);
+ validateWindowsPath(escapedPath, "Task path");
return `schtasks.exe /Change /TN '${escapedPath}${escapedName}' /RU '${escapedUsername}' /RP '${escapedPassword}'`;
}
@@ -126,11 +136,31 @@ export const syncDependenciesAfterRotation = async ({
return encryptor;
};
+ const failAllDeps = async (deps: typeof enabledDeps, msg: string) => {
+ let encryptedMsg: Buffer | null = null;
+ try {
+ const enc = await getEncryptor();
+ encryptedMsg = enc({ plainText: Buffer.from(msg) }).cipherTextBlob;
+ } catch (err) {
+ logger.error(err, `[DependencySync] Failed to encrypt error message`);
+ }
+ await Promise.all(
+ deps.map((dep) =>
+ ctx.pamAccountDependenciesDAL.updateById(dep.id, {
+ syncStatus: PamDependencySyncStatus.Failed,
+ encryptedLastSyncMessage: encryptedMsg
+ })
+ )
+ );
+ };
+
await Promise.all(
Object.entries(grouped).map(async ([resourceId, deps]) => {
const resource = resourceMap.get(resourceId);
if (!resource) {
- logger.warn(`[DependencySync] Resource ${resourceId} not found, skipping`);
+ const msg = `Resource ${resourceId} not found`;
+ logger.warn(`[DependencySync] ${msg}, skipping`);
+ await failAllDeps(deps, msg);
return;
}
@@ -142,11 +172,14 @@ export const syncDependenciesAfterRotation = async ({
hostname = connDetails.hostname ?? connDetails.domain ?? null;
} catch (err) {
logger.error(err, `[DependencySync] Failed to decrypt resource ${resourceId}`);
+ await failAllDeps(deps, `Failed to decrypt resource connection details`);
return;
}
if (!hostname) {
- logger.warn(`[DependencySync] No hostname found for resource ${resourceId}, skipping`);
+ const msg = `No hostname found for resource ${resourceId}`;
+ logger.warn(`[DependencySync] ${msg}, skipping`);
+ await failAllDeps(deps, msg);
return;
}
diff --git a/frontend/src/pages/pam/PamResourceByIDPage/components/PamRotationPolicyModal.tsx b/frontend/src/pages/pam/PamResourceByIDPage/components/PamRotationPolicyModal.tsx
index e81d370758..032b971e32 100644
--- a/frontend/src/pages/pam/PamResourceByIDPage/components/PamRotationPolicyModal.tsx
+++ b/frontend/src/pages/pam/PamResourceByIDPage/components/PamRotationPolicyModal.tsx
@@ -276,7 +276,7 @@ export const PamRotationPolicyModal = ({ isOpen, onOpenChange, resource }: Props
const serverRuleIds = new Set(rules.map((r) => r.id));
const newIdMap = new Map<string, string>();
- localRules.reduce((chain, local) => {
+ await localRules.reduce((chain, local) => {
if (local.id.startsWith(TEMP_ID_PREFIX)) {
return chain.then(async () => {
const created = await createRule.mutateAsync({