Skip to content

fix(server): use regional STS endpoint for aws-iam credentials verification#6130

Open
Ashut0sh-mishra wants to merge 1 commit into
NangoHQ:masterfrom
Ashut0sh-mishra:fix/aws-iam-regional-sts
Open

fix(server): use regional STS endpoint for aws-iam credentials verification#6130
Ashut0sh-mishra wants to merge 1 commit into
NangoHQ:masterfrom
Ashut0sh-mishra:fix/aws-iam-regional-sts

Conversation

@Ashut0sh-mishra
Copy link
Copy Markdown

What

Fixes aws-iam credentials verification when the user picks any region other than us-east-1 in the Connect UI.

Root cause

packages/server/lib/hooks/connection/providers/aws-iam/credentials-verification.ts calls sts:GetCallerIdentity against the global STS host (sts.amazonaws.com) but signs the SigV4 request with connection_config.region. The global endpoint only accepts signatures whose credential scope is us-east-1, so any other region produces SignatureDoesNotMatch. The verifier's catch block swallows the AWS error and rethrows the generic Invalid AWS credentials or permissions., which surfaces in the UI as "AWS IAM did not validate your credentials" despite valid keys.

Confirmed in the issue by aws sts get-caller-identity succeeding from a CLI in the same region against the regional endpoint, plus manually signing against sts.amazonaws.com with non-us-east-1 scope reproducing the same error.

Fix

Switched to the regional STS endpoint sts.<region>.amazonaws.com (Option B in the issue) and kept the user-entered region in the SigV4 scope. Added a small getStsHost(region) helper that:

  • Returns sts.<region>.amazonaws.com for standard commercial regions.
  • Returns sts.<region>.amazonaws.com.cn for China partitions (cn-north-1, cn-northwest-1).
  • Implicitly works for AWS GovCloud (us-gov-west-1, us-gov-east-1), where the standard .amazonaws.com suffix is correct.

Plumbed host through AWSAuthHeaderParams so the canonical request, the Host header, and the baseUrlOverride all line up.

The providers.yaml aws-iam proxy template still hits the global iam.amazonaws.com endpoint signed with us-east-1 - that is intentionally correct because IAM is a genuinely global service, while STS is regionalised. These are two different services and the verifier was the only place where they were conflated.

Changes

  • packages/server/lib/hooks/connection/providers/aws-iam/credentials-verification.ts: derive host from region, pass it into the signer, use it as baseUrlOverride.
  • packages/server/lib/hooks/connection/providers/aws-iam/types.ts: add host: string to AWSAuthHeaderParams.

Testing

  • TypeScript: clean compile (no new diagnostics on the touched files).
  • Logical regression: SigV4 canonical request now contains host:sts.<region>.amazonaws.com, the network call goes to the matching host, and credentialScope continues to use the same <region>, so the AWS-side scope check passes for the same region the user selected. For us-east-1 callers nothing observable changes (the regional and global endpoints both accept us-east-1 scope).
  • AWS docs reference: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_enable-regions.html

Closes #6048


Co-authored-by: nik464 <nikhil18chaudhary@gmail.com>

@superagent-security superagent-security Bot added contributor:verified Contributor passed trust analysis. pr:verified PR passed security analysis. labels May 13, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bebdee4d40

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +94 to +96
}

const payloadHash = crypto.createHash('sha256').update('').digest('hex');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove duplicated signer block

In every environment loading this hook, the duplicated block starts after getAWSAuthHeader has already closed, so these statements are at module scope; the top-level return later in this block and references to locals like host/date make the TypeScript build fail before AWS IAM verification can run. Removing the stray duplicate block restores the module.

Useful? React with 👍 / 👎.

…cation

The aws-iam Connect UI verifier previously called sts:GetCallerIdentity
against the legacy global STS host sts.amazonaws.com while signing the
SigV4 request with the user-entered region. The global STS endpoint
only accepts signatures whose credential scope is us-east-1, so any
other region produced SignatureDoesNotMatch, which the verifier's catch
block masked as "Invalid AWS credentials or permissions." Users with
valid keys saw "AWS IAM did not validate your credentials" whenever
they picked, e.g., us-west-2.

Switch the verifier to the regional STS endpoint
sts.<region>.amazonaws.com (and sts.<region>.amazonaws.com.cn for China
partition regions) and keep the user region in the SigV4 scope. This:

- Fixes the false-negative for every non-us-east-1 commercial region.
- Enables AWS GovCloud regions (us-gov-west-1, us-gov-east-1).
- Enables AWS China regions (cn-north-1, cn-northwest-1).

The actual proxy template in providers.yaml still hits the global IAM
endpoint, which is correct - IAM is genuinely global, but STS is
regionalised. These are two different services, now signed consistently.

Plumbs host through AWSAuthHeaderParams so the canonical request, the
Host header, and the baseUrlOverride all agree.

Closes NangoHQ#6048

Co-authored-by: nik464 <nikhil18chaudhary@gmail.com>
@Ashut0sh-mishra Ashut0sh-mishra force-pushed the fix/aws-iam-regional-sts branch from bebdee4 to f49b4dd Compare May 13, 2026 09:41
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f49b4dd820

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +18 to +21
if (region.startsWith('cn-')) {
return `sts.${region}.amazonaws.com.cn`;
}
return `sts.${region}.amazonaws.com`;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject unsupported partitions during verification

When an aws-iam connection uses a cn-* or us-gov-* region, this helper now lets GetCallerIdentity succeed against partition-specific STS, but the provider still sends actual IAM calls to https://iam.amazonaws.com and signs them with us-east-1 in packages/providers/providers.yaml lines 2113-2115. AWS' IAM endpoint table lists GovCloud IAM under iam.us-gov.amazonaws.com (https://docs.aws.amazon.com/general/latest/gr/iam-service.html), so Connect can now accept credentials for partitions whose subsequent IAM actions are sent to the wrong host/signing scope. Either keep verification restricted to partitions supported by the proxy template or update the proxy host/signing for those regions.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor:verified Contributor passed trust analysis. pr:verified PR passed security analysis.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

aws-iam credentials verification fails for non-us-east-1 regions (SigV4 region scope mismatch with global STS host)

1 participant