🐛 Added config sanitization to strip /ghost from admin:url#26877
🐛 Added config sanitization to strip /ghost from admin:url#26877
Conversation
admin:url should be the base URL (e.g. https://admin.example.com) without /ghost — urlFor adds that automatically. If /ghost is present in the config value, all callers of urlFor("admin", true) produce a doubled path like /ghost/ghost/. - Added sanitizeAdminUrl to config loader alongside existing sanitizers - Strips /ghost from the path and logs a warning at boot - Reverted getAdminUrl() workaround in update-local-template-options
WalkthroughThe pull request modifies admin URL handling across multiple files. It changes the theme engine middleware to derive the admin URL directly from 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@ghost/core/core/shared/config/utils.js`:
- Around line 99-101: The catch block swallowing errors for admin:url is
misleading because checkUrlProtocol only validates the main url, not admin:url;
update the comment in the catch block for the try that parses admin:url
(referencing checkUrlProtocol and urlFor('admin', true)) to state that invalid
admin:url values will be ignored here but not validated by checkUrlProtocol and
may cause downstream failures (e.g., urlFor('admin', true)), and optionally log
or rethrow the parse error if you want explicit validation rather than silent
ignore.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 6a620a58-be5f-475b-b60a-82280617b02a
📒 Files selected for processing (4)
ghost/core/core/frontend/services/theme-engine/middleware/update-local-template-options.jsghost/core/core/shared/config/loader.jsghost/core/core/shared/config/utils.jsghost/core/test/unit/shared/config/utils.test.js
| } catch (e) { | ||
| // invalid URL — checkUrlProtocol will catch this separately | ||
| } |
There was a problem hiding this comment.
Misleading comment: checkUrlProtocol validates main URL, not admin:url.
The comment suggests checkUrlProtocol will catch invalid admin:url values, but it only validates the main url config. An invalid admin:url (e.g., missing protocol) will fail silently here and may cause issues downstream when urlFor('admin', true) uses it.
Consider updating the comment to clarify:
} catch (e) {
- // invalid URL — checkUrlProtocol will catch this separately
+ // invalid URL — silently skip; urlFor will fail later if admin:url is malformed
}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@ghost/core/core/shared/config/utils.js` around lines 99 - 101, The catch
block swallowing errors for admin:url is misleading because checkUrlProtocol
only validates the main url, not admin:url; update the comment in the catch
block for the try that parses admin:url (referencing checkUrlProtocol and
urlFor('admin', true)) to state that invalid admin:url values will be ignored
here but not validated by checkUrlProtocol and may cause downstream failures
(e.g., urlFor('admin', true)), and optionally log or rethrow the parse error if
you want explicit validation rather than silent ignore.
Problem
admin:urlshould be a base URL likehttps://admin.example.com— Ghost appends/ghost/automatically viaurlFor('admin', true). If the config value already contains/ghost, every caller ofurlFor('admin', true)produces a doubled path like/ghost/ghost/.There are 22 call sites across the codebase that use
urlFor('admin', true), including password reset links, staff notification emails, invite links, CORS config, and comment notification URLs. All would produce broken links with a misconfiguredadmin:url.Fix
Added
sanitizeAdminUrlto the config loader (alongside the existingsanitizeDatabasePropertiesandcheckUrlProtocol). At boot, ifadmin:urlcontains/ghostin its path:admin:url should not contain /ghost — Ghost adds this automatically. Corrected to ...Also reverted a workaround in
update-local-template-options.jsthat was masking the issue by usinggetAdminUrl()instead ofurlFor.Testing
4 unit tests added to
config/utils.test.js.