Skip to content

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

validate signing key, stack name and aws region

Matheus Nogueira89441ec1a7b8
diff --git a/backend/src/ee/services/honey-token/honey-token-types.ts b/backend/src/ee/services/honey-token/honey-token-types.ts
index b4223369c5..bd67f30520 100644
--- a/backend/src/ee/services/honey-token/honey-token-types.ts
+++ b/backend/src/ee/services/honey-token/honey-token-types.ts
@@ -1,5 +1,7 @@
import { z } from "zod";
+import { isValidAwsRegion } from "@app/lib/aws/region";
+
import { HoneyTokenEventType, HoneyTokenType } from "./honey-token-enums";
export const AwsHoneyTokenEventMetadataSchema = z.object({
@@ -32,9 +34,24 @@ export type THoneyTokenEventMetadata = z.infer<typeof HoneyTokenEventMetadataSch
// --- Config schemas (typed shape for the encrypted config blob per provider) ---
export const AwsHoneyTokenConfigSchema = z.object({
- webhookSigningKey: z.string().min(1),
- stackName: z.string().min(1).max(128).default("infisical-honey-tokens"),
- awsRegion: z.string().min(1).default("us-east-1")
+ webhookSigningKey: z
+ .string()
+ .min(1)
+ .regex(/^[a-fA-F0-9]+$/, "Signing key must be a hex string"),
+ stackName: z
+ .string()
+ .min(1)
+ .max(128)
+ .regex(
+ /^[a-zA-Z][a-zA-Z0-9-]*$/,
+ "Stack name must start with a letter and contain only letters, numbers, and hyphens"
+ )
+ .default("infisical-honey-tokens"),
+ awsRegion: z
+ .string()
+ .min(1)
+ .default("us-east-1")
+ .refine(isValidAwsRegion, "Invalid AWS region")
});
export type TAwsHoneyTokenConfig = z.infer<typeof AwsHoneyTokenConfigSchema>;
diff --git a/backend/src/ee/services/resource-auth-method/aws-auth-fns.ts b/backend/src/ee/services/resource-auth-method/aws-auth-fns.ts
index 3c7b5e8d23..f7a0865c2b 100644
--- a/backend/src/ee/services/resource-auth-method/aws-auth-fns.ts
+++ b/backend/src/ee/services/resource-auth-method/aws-auth-fns.ts
@@ -1,5 +1,6 @@
import RE2 from "re2";
+import { isValidAwsRegion } from "@app/lib/aws/region";
import { request } from "@app/lib/config/request";
import { UnauthorizedError } from "@app/lib/errors";
import { logger } from "@app/lib/logger";
@@ -27,13 +28,6 @@ const awsRegionFromHeader = (authorizationHeader: string): string | null => {
return null;
};
-const validRegionPattern = new RE2("^[a-z0-9-]+$");
-
-const isValidAwsRegion = (region: string | null): boolean => {
- if (typeof region !== "string" || region.length === 0 || region.length > 20) return false;
- return validRegionPattern.test(region);
-};
-
type TVerifyStsCallerInput = {
iamHttpRequestMethod: string;
iamRequestBody: string;
diff --git a/backend/src/lib/aws/region.ts b/backend/src/lib/aws/region.ts
new file mode 100644
index 0000000000..f9db2167ee
--- /dev/null
+++ b/backend/src/lib/aws/region.ts
@@ -0,0 +1,8 @@
+import RE2 from "re2";
+
+const validRegionPattern = new RE2("^[a-z0-9-]+$");
+
+export const isValidAwsRegion = (region: string | null): boolean => {
+ if (typeof region !== "string" || region.length === 0 || region.length > 20) return false;
+ return validRegionPattern.test(region);
+};
diff --git a/frontend/src/pages/organization/SettingsPage/components/OrgProductSettingsTab/HoneyTokenModal.tsx b/frontend/src/pages/organization/SettingsPage/components/OrgProductSettingsTab/HoneyTokenModal.tsx
index dea7f2c4ec..3008f097b3 100644
--- a/frontend/src/pages/organization/SettingsPage/components/OrgProductSettingsTab/HoneyTokenModal.tsx
+++ b/frontend/src/pages/organization/SettingsPage/components/OrgProductSettingsTab/HoneyTokenModal.tsx
@@ -26,6 +26,7 @@ import {
Input
} from "@app/components/v3";
import { OrgPermissionHoneyTokenActions, OrgPermissionSubjects } from "@app/context";
+import { AWS_REGIONS } from "@app/helpers/appConnections";
import { useTimedReset, useToggle } from "@app/hooks";
import { AppConnection } from "@app/hooks/api/appConnections/enums";
import { useListAppConnections } from "@app/hooks/api/appConnections/queries";
@@ -43,11 +44,30 @@ const DEFAULT_STACK_NAME = "infisical-honey-tokens";
const DEFAULT_AWS_REGION = "us-east-1";
const WEBHOOK_SIGNING_KEY_BYTES = 32;
+const validAwsRegionSlugs = new Set(AWS_REGIONS.map((r) => r.slug));
+
+const isValidAwsRegion = (region: string) => validAwsRegionSlugs.has(region);
+
const schema = z.object({
connectionId: z.string().min(1, "AWS Connection is required"),
- webhookSigningKey: z.string().min(1, "Webhook Signing Key is required"),
- stackName: z.string().trim().min(1, "Stack name is required").max(128),
- awsRegion: z.string().trim().min(1, "AWS region is required")
+ webhookSigningKey: z
+ .string()
+ .min(1, "Webhook Signing Key is required")
+ .regex(/^[a-fA-F0-9]+$/, "Signing key must be a hex string"),
+ stackName: z
+ .string()
+ .trim()
+ .min(1, "Stack name is required")
+ .max(128)
+ .regex(
+ /^[a-zA-Z][a-zA-Z0-9-]*$/,
+ "Stack name must start with a letter and contain only letters, numbers, and hyphens"
+ ),
+ awsRegion: z
+ .string()
+ .trim()
+ .min(1, "AWS region is required")
+ .refine(isValidAwsRegion, "Invalid AWS region")
});
type FormData = z.infer<typeof schema>;
@@ -131,13 +151,13 @@ export const HoneyTokenModal = ({ isOpen, onOpenChange }: Props) => {
() =>
[
"aws cloudformation create-stack \\",
- ` --region ${awsRegion || DEFAULT_AWS_REGION} \\`,
- ` --stack-name ${stackName || DEFAULT_STACK_NAME} \\`,
- ` --template-url ${CF_TEMPLATE_URL} \\`,
+ ` --region '${awsRegion || DEFAULT_AWS_REGION}' \\`,
+ ` --stack-name '${stackName || DEFAULT_STACK_NAME}' \\`,
+ ` --template-url '${CF_TEMPLATE_URL}' \\`,
" --capabilities CAPABILITY_NAMED_IAM \\",
" --parameters \\",
- ` ParameterKey=WebhookUrl,ParameterValue=${webhookUrl} \\`,
- ` ParameterKey=WebhookSigningKey,ParameterValue=${webhookSigningKey}`
+ ` ParameterKey=WebhookUrl,ParameterValue='${webhookUrl}' \\`,
+ ` ParameterKey=WebhookSigningKey,ParameterValue='${webhookSigningKey}'`
].join("\n"),
[awsRegion, stackName, webhookSigningKey, webhookUrl]
);