Skip to content

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

feat: refine Windows local account username validation and update related schemas to enforce character limits

Victor Santosde77352cff99
diff --git a/backend/src/ee/services/secret-rotation-v2/windows-local-account-rotation/windows-local-account-rotation-schemas.ts b/backend/src/ee/services/secret-rotation-v2/windows-local-account-rotation/windows-local-account-rotation-schemas.ts
index 91317cb54c..f74f052170 100644
--- a/backend/src/ee/services/secret-rotation-v2/windows-local-account-rotation/windows-local-account-rotation-schemas.ts
+++ b/backend/src/ee/services/secret-rotation-v2/windows-local-account-rotation/windows-local-account-rotation-schemas.ts
@@ -25,17 +25,21 @@ export const WindowsLocalAccountRotationGeneratedCredentialsSchema = z
.min(1)
.max(2);
-const WINDOWS_USERNAME_REGEX = /^[a-zA-Z0-9_.-]+$/;
+// Windows local account username validation:
+// - Must start with alphanumeric, underscore, or hyphen (not a period)
+// - Can contain alphanumeric, underscore, hyphen, and period
+// - Max 20 characters for local accounts
+const WINDOWS_USERNAME_REGEX = /^[a-zA-Z0-9_-][a-zA-Z0-9_.-]*$/;
const WindowsLocalAccountRotationParametersSchema = z.object({
username: z
.string()
.trim()
.min(1, "Username required")
- .max(256, "Username too long")
+ .max(20, "Username too long - Windows local accounts are limited to 20 characters")
.refine(
(val) => WINDOWS_USERNAME_REGEX.test(val),
- "Username can only contain alphanumeric characters, underscores, hyphens, and periods"
+ "Username must start with a letter, number, underscore, or hyphen, and can only contain alphanumeric characters, underscores, hyphens, and periods"
)
.describe(SecretRotations.PARAMETERS.WINDOWS_LOCAL_ACCOUNT.username),
passwordRequirements: PasswordRequirementsSchema.optional(),
diff --git a/backend/src/lib/smb-rpc/smb-rpc-client.ts b/backend/src/lib/smb-rpc/smb-rpc-client.ts
index 621408c015..a27cccfd6b 100644
--- a/backend/src/lib/smb-rpc/smb-rpc-client.ts
+++ b/backend/src/lib/smb-rpc/smb-rpc-client.ts
@@ -161,12 +161,13 @@ const escapePasswordForRpc = (password: string): string => {
};
/**
- * Windows username validation regex
- * Allows alphanumeric, underscore, hyphen, and period
- * Windows usernames cannot contain: " / \ [ ] : ; | = , + * ? < >
+ * Windows local account username validation:
+ * - Must start with alphanumeric, underscore, or hyphen (not a period)
+ * - Can contain alphanumeric, underscore, hyphen, and period
+ * - Max 20 characters for local accounts
*/
-const WINDOWS_USERNAME_REGEX = /^[a-zA-Z0-9_.-]+$/;
-const MAX_USERNAME_LENGTH = 256;
+const WINDOWS_USERNAME_REGEX = /^[a-zA-Z0-9_-][a-zA-Z0-9_.-]*$/;
+const MAX_USERNAME_LENGTH = 20;
/**
* Validate that a username contains only safe characters to prevent command injection
diff --git a/frontend/src/components/secret-rotations-v2/forms/schemas/windows-local-account-rotation-schema.ts b/frontend/src/components/secret-rotations-v2/forms/schemas/windows-local-account-rotation-schema.ts
index 0f4e864b71..ea7014ba07 100644
--- a/frontend/src/components/secret-rotations-v2/forms/schemas/windows-local-account-rotation-schema.ts
+++ b/frontend/src/components/secret-rotations-v2/forms/schemas/windows-local-account-rotation-schema.ts
@@ -5,7 +5,11 @@ import { PasswordRequirementsSchema } from "@app/components/secret-rotations-v2/
import { SecretRotation } from "@app/hooks/api/secretRotationsV2";
import { WindowsLocalAccountRotationMethod } from "@app/hooks/api/secretRotationsV2/types/windows-local-account-rotation";
-const WINDOWS_USERNAME_REGEX = /^[a-zA-Z0-9_.-]+$/;
+// Windows local account username validation:
+// - Must start with alphanumeric, underscore, or hyphen (not a period)
+// - Can contain alphanumeric, underscore, hyphen, and period
+// - Max 20 characters for local accounts
+const WINDOWS_USERNAME_REGEX = /^[a-zA-Z0-9_-][a-zA-Z0-9_.-]*$/;
export const WindowsLocalAccountRotationSchema = z
.object({
@@ -15,10 +19,10 @@ export const WindowsLocalAccountRotationSchema = z
.string()
.trim()
.min(1, "Username required")
- .max(256, "Username too long")
+ .max(20, "Username too long - Windows local accounts are limited to 20 characters")
.refine(
(val) => WINDOWS_USERNAME_REGEX.test(val),
- "Username can only contain alphanumeric characters, underscores, hyphens, and periods"
+ "Username must start with a letter, number, underscore, or hyphen"
),
passwordRequirements: PasswordRequirementsSchema.optional(),
rotationMethod: z.nativeEnum(WindowsLocalAccountRotationMethod).optional()