Skip to content

fix: resolve redirect loop and 403 when accessing subsite wp-admin#827

Merged
superdav42 merged 1 commit intomainfrom
fix/subsite-wp-admin-redirect-loop
Apr 13, 2026
Merged

fix: resolve redirect loop and 403 when accessing subsite wp-admin#827
superdav42 merged 1 commit intomainfrom
fix/subsite-wp-admin-redirect-loop

Conversation

@superdav42
Copy link
Copy Markdown
Collaborator

Summary

  • Fixes infinite redirect loop when accessing any subsite's wp-admin on subdirectory multisite with a centralized custom login page
  • Root cause: auth cookies (wordpress_sec_*) are path-scoped to /wp-admin during main-site login, but subsite wp-admin lives at /subsite/wp-admin/ — browsers don't send the cookie, causing auth_redirect() and maybe_redirect_to_admin_panel() to bounce the user back and forth indefinitely
  • Adds determine_current_user filter (priority 30) that falls back to the logged_in cookie (path /) so WordPress correctly identifies the user on any subsite's wp-admin
  • Adds logged_in cookie fallback in auth_redirect() before forcing a login redirect
  • maybe_redirect_to_admin_panel() now respects reauth=1 as a loop-breaking safety net

Test plan

  • Log in on the main site, then navigate to any subsite's /wp-admin/ — should load the dashboard (previously: infinite redirect loop)
  • Access a subsite's /wp-admin/ while not logged in — should redirect once to the login page and show the form
  • Main site /wp-admin/ still works normally for logged-in users
  • Super admin can access any subsite's wp-admin
  • Non-admin users without subsite access get a proper 403, not a redirect loop

🤖 Generated with Claude Code

On subdirectory multisite with a centralized custom login page, accessing
any subsite's wp-admin (e.g. /subsite/wp-admin/) caused an infinite
redirect loop between auth_redirect() and maybe_redirect_to_admin_panel().

Root cause: auth cookies (wordpress_sec_*) are set with path=/wp-admin
during main-site login, but subsite wp-admin lives at /subsite/wp-admin/ —
browsers don't send the cookie because the path doesn't match.  The
logged_in cookie (path=/) is always available but wasn't being used.

Three fixes:

1. determine_current_user filter (priority 30) in auth-functions.php —
   falls back to the logged_in cookie when auth cookies aren't present,
   so WordPress correctly identifies the user on subsite wp-admin pages.

2. auth_redirect() fallback in auth-functions.php — also tries the
   logged_in cookie before forcing a login redirect.

3. maybe_redirect_to_admin_panel() in class-checkout-pages.php — respects
   reauth=1 to prevent auto-redirecting logged-in users back to the
   target that just rejected them, breaking any potential loop.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 13, 2026

Warning

Rate limit exceeded

@superdav42 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 21 minutes and 7 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 21 minutes and 7 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eaa0c216-71e4-4e0f-b94a-db1c8cd16560

📥 Commits

Reviewing files that changed from the base of the PR and between 175714f and 4d8407b.

📒 Files selected for processing (2)
  • inc/checkout/class-checkout-pages.php
  • inc/sso/auth-functions.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/subsite-wp-admin-redirect-loop

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@github-actions
Copy link
Copy Markdown

Performance Test Results

Performance test results for f4a40d3 are in 🛎️!

Note: the numbers in parentheses show the difference to the previous (baseline) test run. Differences below 2% or 0.5 in absolute values are not shown.

URL: /

Run DB Queries Memory Before Template Template WP Total LCP TTFB LCP - TTFB
0 40 (-1 / -3% ) 37.78 MB 830.00 ms (-48.00 ms / -6% ) 147.50 ms (-9.50 ms / -6% ) 1073.00 ms (+35.50 ms / +3% ) 1978.00 ms (-60.00 ms / -3% ) 1896.25 ms (-39.55 ms / -2% ) 84.80 ms (-3.05 ms / -4% )
1 56 49.02 MB 956.00 ms 143.00 ms (+3.50 ms / +2% ) 1098.00 ms 2120.00 ms 2039.20 ms 78.85 ms

@superdav42 superdav42 merged commit e6629f5 into main Apr 13, 2026
11 checks passed
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.

1 participant