RE2 for regex + input limits

This commit is contained in:
x032205
2025-05-30 18:01:49 -04:00
parent b5da1d7a6c
commit 79ebfc92e9

View File

@@ -16,12 +16,14 @@ const HCVaultSyncDestinationConfigSchema = z.object({
.string()
.trim()
.min(1, "Secrets Engine Mount required")
.max(128)
.describe(SecretSyncs.DESTINATION_CONFIG.HC_VAULT.mount),
path: z
.string()
.trim()
.min(1, "Path required")
.transform((val) => val.replace(/^\/+|\/+$/g, "")) // removes leading/trailing slashes
.max(128)
.transform((val) => new RE2("^/+|/+$", "g").replace(val, "")) // removes leading/trailing slashes
.refine((val) => new RE2("^([a-zA-Z0-9._-]+/)*[a-zA-Z0-9._-]+$").test(val), {
message:
"Invalid Vault path format. Use alphanumerics, dots, dashes, underscores, and single slashes between segments."