Skip to content

fix: respect redirect_to parameter after login - #965

Merged
kishore7snehil merged 3 commits into
6.xfrom
fix/login-redirect-to
Sep 23, 2026
Merged

kishore7snehil merged 3 commits into
6.xfrom
fix/login-redirect-to

Conversation

@kishore7snehil

Copy link
Copy Markdown
Contributor

Description

After a successful Auth0 login, the plugin was unconditionally redirecting to / and ignoring the redirect_to parameter that WordPress passes on the login URL. This is standard WordPress behavior - when a logged-out user visits a protected page, WordPress appends ?redirect_to=<destination> to the login URL so they end up back where they started after authenticating. The behavior was present in v4 and dropped in v5.

The destination is now captured at login initiation, stored in a WordPress transient keyed by a hash of the OAuth state nonce, and retrieved after the token exchange completes. wp_validate_redirect() is applied before storing to block off-site redirect attempts. The transient has a 10-minute TTL and is deleted immediately on use.

References

Closes #962

Testing

Tested manually against the Docker environment (auth0-PHP 9.3.0, WordPress 7.0, PHP 8.4):

  • redirect_to=/wp-admin/: after login, browser lands at /wp-admin/. Pass.
  • No redirect_to param: after login, browser lands at /. Fallback correct. Pass.
  • redirect_to=https://evil.com: wp_validate_redirect() blocks the external URL, browser lands at /. Pass.

Also verified end-to-end with Redis Object Cache active - transient routes through Redis (SETEX on login initiation, GET + DEL on callback).

Checklist

  • I have added documentation for new/changed functionality in this PR or in auth0.com/docs
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not the default branch

@kishore7snehil
kishore7snehil requested a review from a team as a code owner September 22, 2026 10:38
Comment thread src/Actions/Authentication.php
Comment thread src/Actions/Authentication.php Outdated
Comment thread src/Actions/Authentication.php
…y-authenticated path

- Add is_string() check before esc_url_raw() to prevent a PHP 8 fatal
  when redirect_to is submitted as an array (redirect_to[]=x)
- Delete the redirect transient in the already-authenticated early-return
  path so it does not linger until TTL expiry
- Align the already-authenticated redirect with get_site_url() for
  Multisite subdirectory installs
- Note redirect_to support in README
@kishore7snehil
kishore7snehil merged commit 1b0644e into 6.x Sep 23, 2026
1 check passed
@kishore7snehil
kishore7snehil deleted the fix/login-redirect-to branch September 23, 2026 18:41
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.

2 participants