Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix: forged requests protection
Daniel6b23bf65fedf
diff --git a/backend/src/services/app-connection/aws/aws-connection-fns.ts b/backend/src/services/app-connection/aws/aws-connection-fns.tsindex dea205ae6f..3b0f222a43 100644--- a/backend/src/services/app-connection/aws/aws-connection-fns.ts+++ b/backend/src/services/app-connection/aws/aws-connection-fns.ts@@ -22,8 +22,13 @@ import { TAwsConnectionConfig } from "./aws-connection-types";// vpce-0abc.sts.eu-west-1.vpce.amazonaws.com), so parse it out of the host. Returns undefined for the// global endpoint (sts.amazonaws.com) and non-AWS hosts (e.g. LocalStack), where the caller's region// is used and region scoping isn't enforced.-const getStsSigningRegion = (stsEndpoint?: string): string | undefined => {- if (!stsEndpoint) return undefined;+const getStsSigningRegion = (stsEndpoint?: string) => {+ if (!stsEndpoint) {+ return {+ region: null,+ isValidEndpoint: false+ };+ }try {const { hostname } = new URL(stsEndpoint);@@ -33,9 +38,22 @@ const getStsSigningRegion = (stsEndpoint?: string): string | undefined => {const region = stsLabelIndex === -1 ? undefined : labels[stsLabelIndex + 1];// the global endpoint (sts.amazonaws.com) has the domain in the region position, not a region- return region === "amazonaws" ? undefined : region;+ if (region === "amazonaws") {+ return {+ region: null,+ isValidEndpoint: false+ };+ }++ return {+ region,+ isValidEndpoint: true+ };} catch {- return undefined;+ return {+ region: null,+ isValidEndpoint: false+ };}};@@ -61,12 +79,14 @@ export const getAwsConnectionConfig = async (appConnection: TAwsConnectionConfigswitch (method) {case AwsConnectionMethod.AssumeRole: {+ const stsRegion = getStsSigningRegion(credentials.stsEndpoint);+const client = new STSClient({- region: getStsSigningRegion(credentials.stsEndpoint) ?? region,+ region: stsRegion.region || region,sha256: CustomAWSHasher,// only override the endpoint when explicitly set; otherwise preserve the SDK's// default region/FIPS endpoint resolution so existing connections are unaffected- ...(credentials.stsEndpoint+ ...(credentials.stsEndpoint && stsRegion.isValidEndpoint? { endpoint: credentials.stsEndpoint }: {useFipsEndpoint: crypto.isFipsModeEnabled()@@ -139,7 +159,7 @@ export const validateAwsConnectionCredentials = async (appConnection: TAwsConnecappConnection.method === AwsConnectionMethod.AssumeRole ? appConnection.credentials.stsEndpoint : undefined;const stsRegion = getStsSigningRegion(stsEndpoint);- if (stsEndpoint && (!stsRegion || !(Object.values(AWSRegion) as string[]).includes(stsRegion))) {+ if (stsEndpoint && (!stsRegion.region || !(Object.values(AWSRegion) as string[]).includes(stsRegion.region))) {throw new BadRequestError({message: `STS endpoint must target a supported AWS region. "${stsEndpoint}" does not resolve to a supported region.`});@@ -149,9 +169,9 @@ export const validateAwsConnectionCredentials = async (appConnection: TAwsConnecconst awsConfig = await getAwsConnectionConfig(appConnection);const sts = new STSClient({- region: stsRegion ?? awsConfig.region,+ region: stsRegion.region ?? awsConfig.region,credentials: awsConfig.credentials,- ...(stsEndpoint ? { endpoint: stsEndpoint } : {})+ ...(stsEndpoint && stsRegion.isValidEndpoint ? { endpoint: stsEndpoint } : {})});await sts.send(new GetCallerIdentityCommand({}));@@ -229,7 +249,7 @@ export const awsSyncPreSaveTransformDestinationConfig: TPreSaveTransformDestinat});}- if (region !== stsRegion) {+ if (region !== stsRegion.region) {throw new BadRequestError({message: `Secret sync region "${region}" must match the AWS connection's STS endpoint region from the app connection. Update the sync region or the connection's STS endpoint.`});diff --git a/backend/src/services/app-connection/aws/aws-connection-schemas.ts b/backend/src/services/app-connection/aws/aws-connection-schemas.tsindex ebaa980652..baec59e5ac 100644--- a/backend/src/services/app-connection/aws/aws-connection-schemas.ts+++ b/backend/src/services/app-connection/aws/aws-connection-schemas.ts@@ -11,6 +11,22 @@ import {import { APP_CONNECTION_NAME_MAP } from "../app-connection-maps";import { AwsConnectionMethod } from "./aws-connection-enums";+// AWS-owned DNS suffixes permitted as STS endpoints. Covers all supported AWS partitions:+// commercial + FIPS + GovCloud + VPC PrivateLink all live under .amazonaws.com (GovCloud and+// FIPS differ only by region label / sts-fips prefix, not by domain suffix); China lives under+// .amazonaws.com.cn. The leading dot enforces the suffix as a real DNS boundary so a hostname+// like "amazonaws.com.attacker.com" cannot bypass the check.+const AWS_STS_ALLOWED_HOST_SUFFIXES = [".amazonaws.com", ".amazonaws.com.cn"] as const;++export const isAwsStsHostnameAllowed = (stsEndpoint: string): boolean => {+ try {+ const { hostname } = new URL(stsEndpoint);+ return AWS_STS_ALLOWED_HOST_SUFFIXES.some((suffix) => hostname.endsWith(suffix));+ } catch {+ return false;+ }+};+export const AwsConnectionAssumeRoleCredentialsSchema = z.object({roleArn: z.string().trim().min(1, "Role ARN required"),stsEndpoint: z@@ -18,6 +34,10 @@ export const AwsConnectionAssumeRoleCredentialsSchema = z.object({.trim().url("STS endpoint must be a valid URL").startsWith("https://", "STS endpoint must use HTTPS")+ .refine(+ isAwsStsHostnameAllowed,+ "STS endpoint hostname must be an AWS-owned domain (e.g. .amazonaws.com or .amazonaws.com.cn). Custom or third-party hosts are not permitted."+ ).optional().describe(AppConnections.CREATE(AppConnection.AWS).stsEndpoint)});