Skip to content

🐛 Fixed navigation icons failing to save on local installs - #30476

Open
acburdine wants to merge 1 commit into
mainfrom
claude/ghost-nav-icon-save-bug-93f29b
Open

🐛 Fixed navigation icons failing to save on local installs#30476
acburdine wants to merge 1 commit into
mainfrom
claude/ghost-nav-icon-save-bug-93f29b

Conversation

@acburdine

@acburdine acburdine commented Sep 2, 2026

Copy link
Copy Markdown
Member

ref https://forum.ghost.org/t/working-locally-on-navigation-and-cant-save-icons/63703

Why

Navigation items with icons could not be saved on a local install. Every save came back as a 422 Please enter a valid navigation item, with no indication of which field was at fault. The forum workaround was to run the site on 127.0.0.1:2368 instead of localhost:2368.

What

Navigation icon URLs are validated in core/server/api/endpoints/utils/validators/input/settings.js with validator.isURL, whose require_tld option defaults to true. Admin uploads an icon and gets back the absolute site URL, so on a local install the value sent is http://localhost:2368/content/images/...:

  • localhost has no TLD, so isURL returns false
  • iconUrlRegex only covers /... and __GHOST_URL__/..., so it doesn't rescue it
  • input validation runs before the input serializer's URL transform, so the validator always sees the raw absolute URL

The navigation url field was never affected because navUrlRegex (^(\/|#|[a-zA-Z0-9-]+:)) accepts anything with a scheme prefix. Icons had no equivalent escape hatch.

Dropping require_tld altogether would also start accepting arbitrary single-label hosts such as http://intranet/icon.svg on production sites, so instead the TLD requirement stays and a narrow fallback allows a parsed hostname of exactly localhost. The protocol allowlist still applies on that path, so ftp://localhost:2368/icon.svg remains invalid.

Notes for reviewers

The existing coverage passed because it builds the icon URL from config.get('url'), which in the test environment is http://127.0.0.1:2369 — an IP address, which isURL accepts. That is the same reason the forum workaround worked. The new tests hardcode a localhost:2368 icon URL so it can't drift back, and bound the exception from both sides.

Verified behaviour against the real validator:

icon result
http://localhost:2368/content/images/x.svg accepted
https://example.com/x.svg, http://127.0.0.1:2368/x.svg accepted
__GHOST_URL__/content/images/x.svg, /content/images/x.svg accepted
http://intranet/icon.svg rejected
ftp://localhost:2368/icon.svg rejected
mailto:, http://local host/x.svg rejected

The legacy suite needs MySQL on port 3306, which isn't available in this environment, so the new tests were not executed locally — CI will run them.

  • I've read and followed the Contributor Guide
  • I've explained my change
  • I've written an automated test to prove my change works

🤖 Generated with Claude Code

@nx-cloud

nx-cloud Bot commented Sep 2, 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 02964ed

Command Status Duration Result
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-09-02 20:55:28 UTC

@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: QUIET

Plan: Team

Run ID: 1c6a80a3-97ed-46c3-b7fc-33843ec47ece

📥 Commits

Reviewing files that changed from the base of the PR and between 0c0a94b and 02964ed.

📒 Files selected for processing (2)
  • ghost/core/core/server/api/endpoints/utils/validators/input/settings.js
  • ghost/core/test/legacy/api/admin/settings.test.js

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout. (11)
  • GitHub Check: Build Ghost-CLI archive
  • GitHub Check: Legacy tests (Node 22.23.1, mysql8)
  • GitHub Check: Unit tests (Node 22.23.1)
  • GitHub Check: Unit tests (Node 24.20.0)
  • GitHub Check: Legacy tests (Node 24.20.0, mysql8)
  • GitHub Check: Acceptance tests (Node 24.20.0, mysql8)
  • GitHub Check: Build Docker Images
  • GitHub Check: Acceptance tests (Node 22.23.1, mysql8)
  • GitHub Check: Lint
  • GitHub Check: Check app version bump
  • GitHub Check: Analyze (javascript-typescript)
🧰 Additional context used
📓 Path-based instructions (6)
Review API contract semantics: authentication and permissions, validation at untrusted boundaries, writable-field allowlists, accidental response-data exposure, stable error codes/statuses, pagination/filter consistency, cache invalidation,...

⚙️ CodeRabbit configuration file

Files:

  • ghost/core/core/server/api/endpoints/utils/validators/input/settings.js
Review whether tests prove changed behaviour, meaningful error/edge paths, and externally observable contracts without coupling to implementation details.

⚙️ CodeRabbit configuration file

Files:

  • ghost/core/test/legacy/api/admin/settings.test.js
New source files must be TypeScript: flag new JS files as a required change unless exempt (DB migrations, apps/ember-admin/, tool/config files, scripts/, docker/, generated code).

⚙️ CodeRabbit configuration file

Files:

  • ghost/core/test/legacy/api/admin/settings.test.js
  • ghost/core/core/server/api/endpoints/utils/validators/input/settings.js
Prioritise concrete correctness, security, data-integrity, compatibility, and regression risks.

⚙️ CodeRabbit configuration file

Files:

  • ghost/core/test/legacy/api/admin/settings.test.js
  • ghost/core/core/server/api/endpoints/utils/validators/input/settings.js
New files are TypeScript: Fail if the PR adds a new .js/.jsx/.cjs/.mjs source file, unless it is: a DB migration (ghost/core/core/server/data/migrations/), under apps/ember-admin/, a tool/config file, under scripts/ or docker/, or generated...

📄 CodeRabbit inference engine (Custom checks)

Files:

  • ghost/core/test/legacy/api/admin/settings.test.js
  • ghost/core/core/server/api/endpoints/utils/validators/input/settings.js
Always use `pnpm`, never npm or Yarn.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • ghost/core/test/legacy/api/admin/settings.test.js
  • ghost/core/core/server/api/endpoints/utils/validators/input/settings.js
🔇 Additional comments (5)
ghost/core/core/server/api/endpoints/utils/validators/input/settings.js (2)

46-56: LGTM!


58-64: LGTM!

ghost/core/test/legacy/api/admin/settings.test.js (3)

409-429: LGTM!


431-450: LGTM!


452-471: LGTM!


Walkthrough

The icon URL validator now accepts HTTP and HTTPS URLs with the hostname localhost. It continues to reject other TLD-less hosts and non-HTTP(S) localhost URLs. Tests verify persistence of valid localhost URLs and 422 responses for invalid URLs.

Suggested reviewers: 9larsons

Merge Risk: ⚪ Minimal · up to 02964

This localized change permits navigation icons hosted on localhost while preserving existing URL restrictions; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 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.
Type-Safe Boundaries ✅ Passed PASS. The PR adds runtime validation for the boundary icon string. isValidNavigationIcon first checks that the value is a string and has no whitespace. The new helper catches URL parsing failures,…
New Files Are Typescript ✅ Passed PASS. The pull request changes only two existing .js files: ghost/core/core/server/api/endpoints/utils/validators/input/settings.js and ghost/core/test/legacy/api/admin/settings.test.js. Both ex…
Description check ✅ Passed The description clearly explains the localhost navigation icon validation issue, the scoped fix, the preserved validation rules, and the regression tests.
Title check ✅ Passed The title clearly identifies the main change: fixing navigation icon saves on local installations.
Full details: Type-Safe Boundaries

Explanation

PASS. The PR adds runtime validation for the boundary icon string. isValidNavigationIcon first checks that the value is a string and has no whitespace. The new helper catches URL parsing failures, requires the hostname to be exactly localhost, and then applies validator.isURL with the existing HTTP/HTTPS allowlist. The diff adds no Zod-shape duplicate, any, unchecked cast, @ts-nocheck, or @ts-ignore. The only other changes are tests, which the check excludes.

Full details: New Files Are Typescript

Explanation

PASS. The pull request changes only two existing .js files: ghost/core/core/server/api/endpoints/utils/validators/input/settings.js and ghost/core/test/legacy/api/admin/settings.test.js. Both existed in the parent revision, and the diff contains no added .js, .jsx, .cjs, or .mjs files. The check does not fail for modifications to pre-existing JavaScript files.

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/ghost-nav-icon-save-bug-93f29b

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

@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.46%. Comparing base (c423f32) to head (02964ed).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...r/api/endpoints/utils/validators/input/settings.js 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #30476      +/-   ##
==========================================
- Coverage   67.47%   67.46%   -0.02%     
==========================================
  Files        1656     1656              
  Lines       59993    59997       +4     
  Branches    10379    10379              
==========================================
- Hits        40482    40476       -6     
- Misses      17223    17235      +12     
+ Partials     2288     2286       -2     
Flag Coverage Δ
e2e-tests 70.24% <0.00%> (-0.02%) ⬇️

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.

@acburdine

Copy link
Copy Markdown
Member Author

Could we keep the existing TLD requirement and make an exception for exactly localhost? Setting require_tld: false globally also accepts arbitrary single-label hosts such as http://intranet/icon.svg on production sites.

One option is to leave iconUrlOptions unchanged and add a fallback that checks the parsed hostname while retaining the existing protocol validation:

function isValidNavigationIcon(value) {
  if (!_.isString(value) || /\s/.test(value)) {
    return false;
  }

  if (validator.isURL(value, iconUrlOptions) || iconUrlRegex.test(value)) {
    return true;
  }

  try {
    return (
      new URL(value).hostname === 'localhost' &&
      validator.isURL(value, { ...iconUrlOptions, require_tld: false })
    );
  } catch {
    return false;
  }
}

This allows http://localhost:2368/icon.svg, keeps ordinary domains and IP addresses working, and continues to reject other TLD-less hosts. Tests covering localhost acceptance, rejection of another single-label host, and rejection of non-HTTP(S) localhost URLs would help lock down the intended scope.

ref https://forum.ghost.org/t/working-locally-on-navigation-and-cant-save-icons/63703

Navigation icon URLs are validated with `validator.isURL`, which defaults to
`require_tld: true`. Admin uploads an icon and sends back the absolute site URL,
so on a local install that is `http://localhost:2368/content/images/...`.
`localhost` has no TLD, the icon regex only covers `/...` and `__GHOST_URL__/...`,
and input validation runs before the URL transform in the serializer — so every
save was rejected with a 422 "Please enter a valid navigation item".

The navigation `url` field never hit this because its regex accepts any scheme
prefix. Rather than dropping `require_tld` altogether, which would also accept
arbitrary single-label hosts such as `http://intranet/icon.svg` on production
sites, the TLD requirement is kept and an exception is made for a parsed hostname
of exactly `localhost`. The protocol allowlist still applies, so
`ftp://localhost:2368/icon.svg` stays invalid.

The existing test passed because the test config URL is an IP address, which
`isURL` accepts — the same reason `127.0.0.1:2368` was the forum workaround. The
new tests use a literal localhost icon URL and lock down the scope of the
exception from both sides.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@acburdine
acburdine force-pushed the claude/ghost-nav-icon-save-bug-93f29b branch from 0c0a94b to 02964ed Compare September 2, 2026 20:22
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