Skip to content

fix: never send the API key along a redirect to another host or to plain http - #357

Merged
2 commits merged into
mainfrom
fix/api-key-does-not-follow-redirects
Nov 13, 2026
Merged

2 commits merged into
mainfrom
fix/api-key-does-not-follow-redirects

Conversation

@nofuturekid

@nofuturekid nofuturekid commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #354

What changed

  • The foreground clients (build, buildLongRunning, and the WebSocket client derived from the base client) no longer follow redirects. OkHttp keeps x-api-key when it follows one, so a 3xx used to move the key to the Location host or from https down to http; for the WebSocket the handshake was followed and the key then went out in connection_init to the new host.
  • New failure reason ErrorReason.Redirected with the text "The server redirects to scheme://host[:port]. Edit the server and enter that address." Only the origin is shown (no path, query or user:password@). It is no connection problem, so the pill does not say Offline. The same text reaches the Array/Docker/VMs tabs (title "The address needs to change"), the Add server sheet's Test (through classifyResponse, no change to testConnection or AddEditServerSheet) and the action snackbar.
  • ADR-0051 records the facts and the decision. From unraid/webgui rc.nginx (commit 99e39027fb): with SSL Yes the http port answers every request with return 302 https://$host:$PORTSSL...; with Strict it is a 302 to lan-ip.hash.myunraid.net, a different host name. So the realistic case is a user who typed an http address or a bare IP; the redirect names the address to enter. "Follow only same-host http-to-https upgrades" was rejected: the first request already sent the key over http, and a followed 302 POST becomes a body-less GET.
  • CHANGELOG (Fixed), one README sentence in the Add server steps.
  • Tests: new KeyedClientRedirectTest (key never reaches a second server for 301/302/303/307/308 on both HTTP clients; the redirect arrives as Redirected with the target; a server without redirect is unchanged; the OkHttp switches; the WebSocket handshake is not followed), classifier, reason, pill and rendering tests. Without the client change four of the five KeyedClientRedirectTest tests fail (run before the fix). The old guard "the foreground still follows redirects" in BackgroundClientRedirectTest now pins the opposite and that cleartext stays allowed in the foreground.

Shared files touched: ApolloClientFactory.kt (base and long-running client builders, two internal modifiers), ResponseClassifier.kt (new redirectMessage, three call sites), DomainState.kt (the new enum entry), SnapshotStates.kt (its text in errorTexts).

Left out on purpose

  • Following same-host http-to-https redirects (ADR-0051, decision 2).
  • A reason on the WebSocket streams: they keep their generic error text; the polling tabs and Test carry the reason.
  • The background check and certificate handling are unchanged.
  • The https-to-http direction is not staged in a test (no TLS peer in the test setup); the two OkHttp switches are pinned instead.
  • OkHttp's 302-POST-becomes-GET behaviour is cited from its documented behaviour, not run here.

./scripts/local-ci.sh green on the rebased branch (592 unit tests, 0 failed, 0 skipped).

🤖 Generated with Claude Code

@nofuturekid nofuturekid added this to the 0.1.49 milestone Nov 13, 2026
nofuturekid and others added 2 commits November 13, 2026 22:31
The Resume button on a paused container sent the start mutation, which
Docker refuses ("cannot start a paused container, try unpause instead"),
so the container stayed paused. A paused container now gets the existing
UnpauseContainer mutation (docker.unpause, available since API 4.29.0, so
on every supported server and without a capability floor); a stopped
container still gets start.

The choice is made once, in UnraidRepository.startContainer(client, id,
paused), the same seam as restartContainer. The Docker tab row and the
container sheet both go through MainViewModel.startContainer(Container).

The demo follows the repository surface: UnraidGateway.startContainer
takes the same flag, and the demo model refuses start on a paused
container like Docker does, so the demo no longer hides the bug.

Closes #345
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ain http

The foreground clients followed redirects, and OkHttp keeps the x-api-key
header when it does, so a 3xx answer moved the key to whatever Location
named: another host, or http after the user entered https. For the
WebSocket the handshake was followed and the key then went out in
connection_init to the new host.

No client that carries the key follows a redirect any more (ADR-0051).
A redirect is reported as the new reason Redirected, naming the target
origin ("The server redirects to https://... Edit the server and enter
that address."), in the tabs, in the Add server sheet's Test and in the
action message. It is no connection problem, so the pill does not say
Offline. Unraid answers http requests with 302 when SSL is Yes or Strict.

Closes #354

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@nofuturekid
nofuturekid force-pushed the fix/api-key-does-not-follow-redirects branch from 879ab1e to a6e20ae Compare November 13, 2026 21:43
@nofuturekid nofuturekid closed this pull request by merging all changes into main in deded38 Nov 13, 2026
@nofuturekid
nofuturekid deleted the fix/api-key-does-not-follow-redirects branch November 13, 2026 22:21
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.

The API key is sent along when a server answers with a redirect

1 participant