Skip to content

fix(settings): validate info.relay_url is a usable absolute URL - #825

Merged
cameri merged 3 commits into
mainfrom
fix/relay-url-validation
Oct 15, 2026
Merged

cameri merged 3 commits into
mainfrom
fix/relay-url-validation

Conversation

@chappie-daemon

Copy link
Copy Markdown
Collaborator

Fixes #824

Problem

A info.relay_url that is not a valid absolute URL (e.g. nostream.example.com, no scheme) passed validateSettings() untouched, then broke every HTTP request: the CSP middleware in src/factories/web-app-factory.ts runs new URL(settings.info.relay_url) uncaught on every request, so /, /healthz, /readyz and the whole Admin Console returned 500 TypeError: Invalid URL — with no way to fix the setting from the UI.

Reported and diagnosed by @tarunagnihotri534 in #824 — the middleware omission and the new URL('localhost:8008') host quirk are his analysis. Thank you!

Fix

validateSettings() (src/utils/settings-config.ts) now rejects a relay_url that:

  • is not a valid absolute URL (new URL() throws),
  • parses with an empty host (scheme-only strings like localhost:8008 — new URL treats localhost: as the scheme and leaves the host empty), or
  • has a protocol other than ws: / wss: / http: / https:.

One deliberate deviation from the snippet proposed in #824: the host check runs before the protocol check. With the protocol check first, localhost:8008 reports "must use ws, wss, http, or https protocol" — misleading, since its real problem is the missing host. Checking the host first gives each malformed shape its accurate message.

Tests

Four new cases in test/unit/utils/settings-config.spec.ts:

  • accepts wss://, ws:// with port, https://, http://localhost:8008
  • rejects nostream.example.com → "must be a valid absolute URL"
  • rejects localhost:8008 → "must include a valid host"
  • rejects ftp://nostream.example.com → "must use ws, wss, http, or https protocol"

Full unit suite green: 2187 passing (incl. the pre-existing settings-config and cli/config specs). biome lint clean, build:check clean.

A relay_url like nostream.example.com (no scheme) passed
validateSettings(), then broke every HTTP request: the CSP middleware in
web-app-factory runs new URL(settings.info.relay_url) uncaught on every
request, so /, /healthz and the whole Admin Console returned 500
TypeError: Invalid URL — with no way to fix it from the UI.

validateSettings() now rejects a relay_url that is not a valid absolute
URL, has no host (scheme-only strings like localhost:8008 parse with an
empty host), or whose protocol is not ws/wss/http/https.

Found and diagnosed by @tarunagnihotri534 in #824; the middleware
omission and the new URL('localhost:8008') host quirk are his analysis.

Closes #824
@changeset-bot

changeset-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 15a97d3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
nostream Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@greptile-apps

greptile-apps Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Adds checks for info.relay_url in validateSettings.

  • Relay settings now reject URLs the web server cannot use.

No actionable issues were found.

Reviews (1) · Last reviewed commit: "fix(settings): validate info.relay_url i..." · Reviewed by Greptile

The accept test now exercises ws, wss, http and https each with and
without an explicit port, plus IPv6 and bare-IP hosts. The reject-protocol
test adds gopher (opaque port) and whttp (unknown scheme) so all four
allowed protocols are pinned against near-miss neighbours, not just one
counterexample.
@coveralls

coveralls commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 73.99% (+0.01%) from 73.979% — fix/relay-url-validation into main

@cameri
cameri merged commit 48fe9c4 into main Oct 15, 2026
15 of 16 checks passed
@cameri
cameri deleted the fix/relay-url-validation branch October 15, 2026 13:01
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.

[BUG]: Invalid info.relay_url passes validation but then breaks every HTTP request

3 participants