Skip to content

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

refactor: enhance Windows local account password requirements schema to block dangerous characters and improve security

Victor Santos32c78075dbdf
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 f590ccfff8..14057589ba 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
@@ -34,6 +34,27 @@ const validateWindowsUsername = characterValidator([
CharacterType.Period
]);
+// Dangerous characters that could enable command/RPC injection in Windows/SMB context
+// These are blocked to prevent security issues when executing SMB/RPC commands:
+// - Command separators: ; | &
+// - Command substitution: ` $ ( )
+// - Newlines: \n \r (auth file directive injection)
+// - Null bytes: \0 (string termination attacks)
+const DANGEROUS_SMB_PASSWORD_CHARS = [";", "|", "&", "`", "$", "(", ")", "\n", "\r", "\0"];
+
+// Windows-specific password requirements schema that validates allowedSymbols
+// doesn't contain dangerous characters that could cause command injection
+const WindowsPasswordRequirementsSchema = PasswordRequirementsSchema.refine(
+ (data) => {
+ if (!data.allowedSymbols) return true;
+ return !DANGEROUS_SMB_PASSWORD_CHARS.some((char) => data.allowedSymbols?.includes(char));
+ },
+ {
+ message: "Allowed symbols cannot contain dangerous characters: ; | & ` $ ( )",
+ path: ["allowedSymbols"]
+ }
+);
+
const WindowsLocalAccountRotationParametersSchema = z.object({
username: z
.string()
@@ -47,7 +68,7 @@ const WindowsLocalAccountRotationParametersSchema = z.object({
message: "Username cannot start with a hyphen or period, and cannot end with a period"
})
.describe(SecretRotations.PARAMETERS.WINDOWS_LOCAL_ACCOUNT.username),
- passwordRequirements: PasswordRequirementsSchema.optional(),
+ passwordRequirements: WindowsPasswordRequirementsSchema.optional(),
rotationMethod: z
.nativeEnum(WindowsLocalAccountRotationMethod)
.optional()
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 ea7014ba07..8d73f18bac 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
@@ -6,10 +6,30 @@ import { SecretRotation } from "@app/hooks/api/secretRotationsV2";
import { WindowsLocalAccountRotationMethod } from "@app/hooks/api/secretRotationsV2/types/windows-local-account-rotation";
// Windows local account username validation:
-// - Must start with alphanumeric, underscore, or hyphen (not a period)
+// - Cannot start with a period or hyphen
+// - Cannot end with 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 WINDOWS_USERNAME_REGEX = /^[a-zA-Z0-9_][a-zA-Z0-9_.-]*$/;
+
+// Dangerous characters that could enable command/RPC injection in Windows/SMB context
+// - Command separators: ; | &
+// - Command substitution: ` $ ( )
+// - Newlines: \n \r (auth file directive injection)
+// - Null bytes: \0 (string termination attacks)
+const DANGEROUS_SMB_PASSWORD_CHARS = [";", "|", "&", "`", "$", "(", ")", "\n", "\r", "\0"];
+
+// Windows-specific password requirements schema that filters dangerous characters from allowedSymbols
+const WindowsPasswordRequirementsSchema = PasswordRequirementsSchema.refine(
+ (data) => {
+ if (!data.allowedSymbols) return true;
+ return !DANGEROUS_SMB_PASSWORD_CHARS.some((char) => data.allowedSymbols?.includes(char));
+ },
+ {
+ message: "Allowed symbols cannot contain the characters: ; | & ` $ ( ) or newlines",
+ path: ["allowedSymbols"]
+ }
+);
export const WindowsLocalAccountRotationSchema = z
.object({
@@ -20,11 +40,14 @@ export const WindowsLocalAccountRotationSchema = z
.trim()
.min(1, "Username required")
.max(20, "Username too long - Windows local accounts are limited to 20 characters")
- .refine(
- (val) => WINDOWS_USERNAME_REGEX.test(val),
- "Username must start with a letter, number, underscore, or hyphen"
- ),
- passwordRequirements: PasswordRequirementsSchema.optional(),
+ .refine((val) => WINDOWS_USERNAME_REGEX.test(val), {
+ message:
+ "Username can only contain alphanumeric characters, underscores, hyphens, and periods"
+ })
+ .refine((val) => !val.startsWith("-") && !val.startsWith(".") && !val.endsWith("."), {
+ message: "Username cannot start with a hyphen or period, and cannot end with a period"
+ }),
+ passwordRequirements: WindowsPasswordRequirementsSchema.optional(),
rotationMethod: z.nativeEnum(WindowsLocalAccountRotationMethod).optional()
}),
secretsMapping: z.object({