Skip to content

fix: setup wizard mangles the hostname and probes the wrong url - #759

Open
solracsf wants to merge 3 commits into
nextcloud:mainfrom
solracsf:fix/setup-wizard-base-url
Open

fix: setup wizard mangles the hostname and probes the wrong url#759
solracsf wants to merge 3 commits into
nextcloud:mainfrom
solracsf:fix/setup-wizard-base-url

Conversation

@solracsf

@solracsf solracsf commented Sep 7, 2026

Copy link
Copy Markdown
Member

ltrim($base, 'http://') passes a character list, not a prefix, so it also strips any
leading h, t or p of the host: http://push.example.com becomes
https://ush.example.com. That url is what gets saved as base_endpoint and handed to
clients.

The same method probed $base, the http url it already had, rather than the https one
it had just built, and returned $base from both branches of the try/catch. So the
https preference never applied on a first call, and a second call returned the cached
mangled url instead.

SetupWizardBaseUrlTest drives this through getProxiedBase() with a mocked client.
Four of its six assertions fail on master.

… url

`ltrim($base, 'http://')` passes a character list, not a prefix, so it strips
any leading h, t, p, : or / of whatever follows as well.
`http://push.example.com` came out as `https://ush.example.com`, and that url
is what gets saved as `base_endpoint` and handed to the clients.

The same method then probed `$base`, the plain http url it already had, rather
than the https one it had just built, and returned `$base` from both branches
of the try/catch. So the https preference the method exists for never applied
on a first call, and on a second call it returned the cached (mangled) https
url instead, making `getBaseUrl()` answer differently depending on how many
times it had been called within the same command.

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
`toHttps` was tested but `getBaseUrl` was not, which left the actual bug this
branch fixes, probing the wrong url and answering differently on a second call,
with no test pinning it. Drive it through `getProxiedBase()` with a mocked
client that records what it was asked for. Four of the six assertions fail
against master, including one that catches both halves at once: the first call
returns `http://push.example.com/push` and the second
`https://ush.example.com/push`.

`str_starts_with` is case sensitive, so `HTTP://host` fell through to the
default arm and came out as `https://HTTP://host`, and a protocol relative
`//host` became `https:////host`. Compare the scheme case insensitively and
give `//host` its own arm.

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
`toHttps` was four `str_starts_with` arms doing what an anchored optional
scheme group does in one line, and it now normalises an uppercase scheme rather
than passing it through, which is what the caller wanted anyway.

That also lets `getBaseUrl` drop its own `str_starts_with($base, 'https://')`:
comparing the converted url against the original says the same thing and stays
correct for a scheme in any case.

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
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