Skip to content

fix(auth): pass preferredRedirectUrl through signInWithRedirect to ge… - #14870

Open
shivennn wants to merge 2 commits into
aws-amplify:mainfrom
shivennn:fix/auth-preferredRedirectUrl-passthrough
Open

fix(auth): pass preferredRedirectUrl through signInWithRedirect to ge…#14870
shivennn wants to merge 2 commits into
aws-amplify:mainfrom
shivennn:fix/auth-preferredRedirectUrl-passthrough

Conversation

@shivennn

@shivennn shivennn commented Jul 8, 2026

Copy link
Copy Markdown

The preferredRedirectUrl option was accepted by signInWithRedirect() but never passed through the internal call chain to getRedirectUrl(). This made it impossible to use HTTPS App Links/Universal Links as OAuth redirect URIs on React Native, forcing apps to use custom URL schemes which are vulnerable to authorization code interception.

Changes:

  • Add preferredRedirectUrl to AuthSignInWithRedirectInput options type
  • Pass preferredRedirectUrl from signInWithRedirect → oauthSignIn → getRedirectUrl
  • Add unit tests verifying preferredRedirectUrl is used in the authorization URL

Description of changes

preferredRedirectUrl is accepted by signInWithRedirect() options but never passed through the internal call chain to getRedirectUrl(). The parameter is always undefined when it reaches getRedirectUrl.native.ts, making it impossible to use HTTPS App Links/Universal Links as OAuth redirect URIs on React Native.

This forces apps to use custom URL schemes (e.g., myapp://auth/callback) which are vulnerable to authorization code interception on Android — any malicious app can register the same scheme and steal auth codes via the disambiguation dialog (see RFC 8252 §8.2).

Fix (3 lines of functional code):

  1. packages/auth/src/types/inputs.ts — Added preferredRedirectUrl?: string to AuthSignInWithRedirectInput.options
  2. packages/auth/src/providers/cognito/apis/signInWithRedirect.ts — Pass preferredRedirectUrl through signInWithRedirect()oauthSignIn()getRedirectUrl()

getRedirectUrl.native.ts already has the logic to handle preferredRedirectUrl — it simply never received it.

Non-breaking: If preferredRedirectUrl is not passed, behavior is identical to before.

Issue #, if available

#14869

Description of how you validated changes

  • Unit tests added and passing (yarn test --scope @aws-amplify/auth)
  • Manually verified with a React Native app using HTTPS App Links as OAuth redirect on Android
  • Confirmed malicious app claiming the same HTTPS URL is rejected (SHA-256 mismatch in .well-known/assetlinks.json) while legitimate app receives the redirect

Checklist

  • PR description included
  • yarn test passes
  • Unit Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

…tRedirectUrl

The preferredRedirectUrl option was accepted by signInWithRedirect() but never
passed through the internal call chain to getRedirectUrl(). This made it
impossible to use HTTPS App Links/Universal Links as OAuth redirect URIs on
React Native, forcing apps to use custom URL schemes which are vulnerable to
authorization code interception.

Changes:
- Add preferredRedirectUrl to AuthSignInWithRedirectInput options type
- Pass preferredRedirectUrl from signInWithRedirect → oauthSignIn → getRedirectUrl
- Add unit tests verifying preferredRedirectUrl is used in the authorization URL
@changeset-bot

changeset-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: da70c52

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@osama-rizk

Copy link
Copy Markdown
Contributor

Thanks for the PR, @shivennn! We'll review it soon and follow up with feedback.

@bobbor bobbor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution @shivennn
tested and commented. LGTM. Approved

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants