Skip to content

🐛 Fixed admin toolbar redirect loops on subdirectory sites - #29838

Merged
louisghost merged 7 commits into
mainfrom
fix-admin-toolbar-subdirectory
Aug 10, 2026
Merged

louisghost merged 7 commits into
mainfrom
fix-admin-toolbar-subdirectory

Conversation

@louisghost

@louisghost louisghost commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Activating the admin toolbar on a subdirectory site (e.g. https://ghost.org/changelog/?admin=1) can redirect-loop when a reverse proxy strips the subdirectory before forwarding the request. Ghost then cleaned the query and redirected to /, which bounced back to the public URL with admin=1 still attached.

Summary

  • Build the clean redirect with urlUtils.createUrl() so the configured subdirectory is restored when missing (and left alone when already present)
  • Add unit coverage for stripped paths, already-prefixed paths, retained query params, and the activation redirect

Test plan

  • pnpm test:single test/unit/frontend/web/middleware/admin-toolbar.test.js
  • Manually open /?admin=1 on a subdirectory install and confirm it redirects once to the public subdirectory path without looping

@nx-cloud

nx-cloud Bot commented Aug 10, 2026

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 0364c3d

Command Status Duration Result
nx run ghost:test:ci:integration ✅ Succeeded 2m 35s View ↗
nx run ghost:test:integration ✅ Succeeded 2m 57s View ↗
nx run ghost:test:legacy ✅ Succeeded 2m 54s View ↗
nx run ghost:test:e2e ✅ Succeeded 2m 33s View ↗
nx run @tryghost/admin:build ✅ Succeeded 1m 50s View ↗
nx run ghost-monorepo:lint:boundaries ✅ Succeeded 23s View ↗
nx run-many -t test:unit -p ghost ✅ Succeeded 30s View ↗
nx run-many -t lint -p ghost,ghost-monorepo ✅ Succeeded 21s View ↗
nx run-many --target=build --projects=tag:publi... ✅ Succeeded <1s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-08-10 18:31:37 UTC

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

getCleanRedirectUrl now uses urlUtils.createUrl to restore the configured site subdirectory. Query parameters and hash fragments remain unchanged. Tests cover proxy-stripped subdirectories, existing subdirectory paths, and toolbar activation redirects.

Possibly related PRs

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely identifies the fix for admin toolbar redirect loops on subdirectory sites.
Description check ✅ Passed The description directly explains the redirect-loop cause, implementation, test coverage, and manual test plan.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-admin-toolbar-subdirectory

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.

@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 75.41%. Comparing base (77f2685) to head (53b8631).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...core/core/frontend/web/middleware/admin-toolbar.js 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #29838      +/-   ##
==========================================
- Coverage   75.45%   75.41%   -0.04%     
==========================================
  Files        1605     1605              
  Lines      140458   140458              
  Branches    17424    17413      -11     
==========================================
- Hits       105988   105933      -55     
- Misses      33393    33477      +84     
+ Partials     1077     1048      -29     
Flag Coverage Δ
e2e-tests 77.56% <0.00%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@louisghost

Copy link
Copy Markdown
Contributor Author

Reference PR: #29412

@9larsons 9larsons left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be all good 👍

@louisghost
louisghost merged commit cbdf028 into main Aug 10, 2026
52 checks passed
@louisghost
louisghost deleted the fix-admin-toolbar-subdirectory branch August 10, 2026 19:24
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