Repository navigation
fix(settings): validate info.relay_url is a usable absolute URL - #825
Merged
Merged
Conversation
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 detectedLatest commit: 15a97d3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
[Medium impact] The PR appears safe to merge.
|
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.
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #824
Problem
A
info.relay_urlthat is not a valid absolute URL (e.g.nostream.example.com, no scheme) passedvalidateSettings()untouched, then broke every HTTP request: the CSP middleware insrc/factories/web-app-factory.tsrunsnew URL(settings.info.relay_url)uncaught on every request, so/,/healthz,/readyzand the whole Admin Console returned500 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 arelay_urlthat:new URL()throws),localhost:8008—new URLtreatslocalhost:as the scheme and leaves the host empty), orws:/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:8008reports "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:wss://,ws://with port,https://,http://localhost:8008nostream.example.com→ "must be a valid absolute URL"localhost:8008→ "must include a valid host"ftp://nostream.example.com→ "must use ws, wss, http, or https protocol"Full unit suite green: 2187 passing (incl. the pre-existing
settings-configandcli/configspecs).biome lintclean,build:checkclean.