Skip to content

Conversation

@RalfBarkow
Copy link

@RalfBarkow RalfBarkow commented Sep 18, 2025

This PR should fix longstanding issues when running a wiki with IPv6 neighbors (e.g. http://[::1]:4000) on Ubuntu and other systems with IPv6 enabled.

Motivation

  • Without brackets, raw ::1:4000 hosts caused Invalid URL errors in browsers and curl.
  • Proxy paths were unsafe because raw IPv6 literals were embedded directly in /proxy/... without encoding.
  • Localhost detection only matched "localhost", not ::1 or [::1].
  • Cache keys in localForage (routes, withCredentials) were inconsistent: ::1:3000 vs [::1]:3000.
  • Some functions (getURL, getDirectURL, journal fixups) did brittle string surgery with substring(7).

Changes

  • Add helpers:

    • normalizeSite, siteKey → ensure canonical bracketed form
    • httpOriginFor, httpsOriginFor, proxyPathFor (encoded)
    • isLoopbackSite detection (supports ::1, [::1], IPv4, localhost)
  • Update findAdapterQ:

    • Prefer direct http://[::1]:port/... for loopback
    • Use proxy path for HTTPS origins
    • Fallback to HTTPS direct if proxy fails
  • Replace protocol-relative URLs (//host/...) with explicit schemes.

  • Replace string hacks with base reconstruction logic.

  • Canonicalize keys in routeStore and withCredsStore.

  • Clean up findAdapter (proper arrow body).

  • Use template strings for flag replacement consistently.

Testing

  • Local Test Farm setup with two wiki instances (ports 3000, 4000).

  • On Ubuntu with IPv6:

    • curl http://[::1]:4000/favicon.png returns 200
    • curl http://localhost:3000/proxy/%5B::1%5D:4000/favicon.png returns 200
  • Browser tests:

    • On HTTP pages → direct bracketed URLs
    • On HTTPS pages → proxy paths with encoded IPv6
  • Verified flag replacement and journal/fork links resolve correctly.

Related

  • Closes issue(s): IPv6 proxy/localhost troubleshooting reported on Ubuntu.

Checklist

  • Bracket IPv6 hosts, preserve ports
  • Encode proxy path segments safely
  • Canonicalize cache keys
  • Fix broken findAdapter syntax
  • Tested on Ubuntu with IPv6 loopback

journal fixups

* bracket IPv6 + preserve port; canonicalize cache key
* prefer http direct for loopback; proxy on https origins
* replace protocol-relative/substring hacks with base reconstruction
* fix arrow-function body, duplicate `let`, and closing parens
* use template strings for realFlag consistently
* replace invalid arrow form (`=> const key ...`) with block body
* add missing closing brace to balance function
* removes leftover commented debug log
* ensures valid syntax and consistent style in siteAdapter.js
Copy link
Member

@paul90 paul90 left a comment

Choose a reason for hiding this comment

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

From just an initial cursory glance.

These changes will also have an impact server side, and anywhere wiki names are used. A quick test shows it does not work with a server running in farm mode.


// IPv6/localhost-safe URL helpers -------------------------------------------
const isLoopbackHost = h =>
h === 'localhost' || h === '127.0.0.1' || h === '::1' || h === '[::1]';
Copy link
Member

Choose a reason for hiding this comment

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

This needs to cater for localhost subdomains.

Which is what if (site.split('.').at(-1).split(':')[0] === 'localhost') { is part of.

- Expand isLoopbackHost to properly recognize IPv6 addresses (::1 and [::1])
- Add support for 127/8 subnet and .localhost domains in loopback detection
- Update test environment with proper DOM mocking using jsdom
- Add comprehensive tests for favicon URL generation across different host types
- Include fake-indexeddb and jsdom-global dev dependencies for testing
- Fix asynchronous test timing issues with proper callback handling

The IPv6 address handling now correctly identifies loopback addresses
and generates appropriate HTTP URLs instead of scheme-relative URLs
for local development.
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