Skip to content

fix(connection): probe /api/v1/health without credentials - #357

Merged
Quick104 merged 1 commit into
mainfrom
apiv2-stack/09-unauthenticated-health-probe
Sep 23, 2026
Merged

Quick104 merged 1 commit into
mainfrom
apiv2-stack/09-unauthenticated-health-probe

Conversation

@Quick104

Copy link
Copy Markdown
Contributor

The connection monitor's health probe no longer sends the bearer or profile headers, and it can no longer start a token refresh, even if something in front of the server answers it with 401.

Problem

ConnectionMonitor.probeServer() called HTTPClient.shared.get("/api/v1/health"). That is the authenticated path: it attached Authorization, X-Profile-Id and X-Profile-Token, and it answered a 401 by refreshing the token. The endpoint is public, so a reachability check sent credentials it never needed.

This did not cause a visible bug against the stock server. At 84ed9e596 the server registers GET /api/v1/health directly in r.Route("/api/v1") (router.go:2641-2642), outside every RequireAuth group, so it never answers 401 there. Any HTTP response, a 401 included, already marked the server reachable (HTTPClient.perform calls noteServerResponded()); only a transport failure marks it unreachable. The refresh risk was real only if a proxy in front of the server, or a future server, answered the probe with 401: the probe would then start a refresh, and a failed refresh could end the session.

Solution

  • Add HTTPClient.getUnauthenticatedFromActiveServer(_:). It reads a public endpoint of the active server with no bearer or profile headers and no refresh. Unlike getUnauthenticated(serverURL:…), it reports the outcome to ConnectionMonitor, because the response comes from the server every other request goes to. It captures the dispatch revision before it reads the server URL, so a server switch in between rejects the probe instead of recording the old server's reachability against the new one.
  • ConnectionMonitor.probeServer(using:) uses it. The client is injectable for tests and defaults to .shared. GET /api/v1/health stays because it is the retained unversioned probe: the server registers it outside v2 and outside the v1 tombstone (router.go at 84ed9e596). The path now lives in ConnectionMonitor.healthPath.
  • Update the doc comments on ConnectionMonitor, probeServer and the HTTPClient type to match.

Android's HealthApi.kt:23 calls a root /health, which the server does not register. Apple does not copy that.

Validation

  • iOS, tvOS and macOS builds all passed.
  • iOS tests (SiloTests/ConnectionMonitorProbeTests SiloTests/SettingValuesAPITests/testCandidateProbeDoesNotChangeActiveServerReachability SiloTests/RefreshSessionV2Tests) passed: 8 tests, 0 failures.
  • tvOS tests (SiloTVTests/ConnectionMonitorProbeTests SiloTVTests/RefreshSessionV2Tests) passed: 7 tests, 0 failures.
  • scripts/ci/check-no-api-v1.sh passed. The v1 match count in ConnectionMonitor.swift dropped from 2 to 1: the class doc comment no longer names the path, so only static let healthPath matches. The allowlist entry stays at 2 (scripts/ci/api-v1-allowlist.txt), which the ceiling check accepts; --exact would fail until Z1 sets that entry to 1. The new test uses ConnectionMonitor.healthPath instead of a literal.
  • The new ConnectionMonitorProbeTests stores a session and then probes. The first test's stub answers 401 to any request that carries Authorization, standing in for a proxy that rejects credentials. It checks that the probe sends exactly one request, with no Authorization, X-Profile-Id or X-Profile-Token header and no refresh, and that it moves the monitor from unreachable to reachable. The second checks that a transport failure marks the server unreachable.
  • Not run: the manual offline and online toggle on a device.
  • Final stack: with all 50 PRs applied, the full iOS suite (1981 tests) and tvOS suite (1792 tests) passed with 0 failures, the macOS build passed, and the v1 path guard passed. Every branch in the stack, this one included, builds on its own.

Risks and follow-ups

  • Low risk. The probe's return value and its reachability side effects do not change for callers: the path-regained handler, the reprobe loop and ItemDetailView.
  • The ServerIdentity health-name fallback (D8) is out of scope. W1-B deletes it.
  • Z1 must set the guard allowlist entry for ConnectionMonitor.swift to 1. Per the stack rules this PR does not edit the allowlist.

AI disclosure

Code and description written by Claude Opus 5.5 (claude-opus-5-5) agents in Claude Code (T3 Code), orchestrated by a Claude Code workflow.


Part 9 of 50 in the Apple API v2 stack. Base: apiv2-stack/08-refresh-through-v2. Merge in order from the bottom of the stack. The plan and full index are in PR 01.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 9 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 4e0ee6bc-da00-49fb-86cd-d0890c0cce3f

📥 Commits

Reviewing files that changed from the base of the PR and between 178e9a0 and fa2ad8e.

📒 Files selected for processing (3)
  • iosApp/Tests/ConnectionMonitorProbeTests.swift
  • iosApp/iosApp/Networking/ConnectionMonitor.swift
  • iosApp/iosApp/Networking/HTTPClient.swift

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-23T13:35:13.008108Z fa2ad8e New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Quick104

Copy link
Copy Markdown
Contributor Author

Code review summary

Reviewed head: e7cd7ccb (apiv2-stack/09-unauthenticated-health-probe).

Process: an adversarial review of this PR's diff with each candidate finding independently verified before any fix, a simplify pass for medium and larger PRs, and a whole-stack review across contract conformance, authority and failure handling, data integrity, user-visible behavior and cross-PR integration.

Verified findings, all fixed on this branch:

  • minor: PR body misstates the v1 guard count for ConnectionMonitor.swift
  • minor: PR body says a dead session could make a live server look unreachable, which the code and server do not support

Validation: this branch builds on its own for iOS, tvOS and macOS, and its focused tests passed. The completed stack passed the full iOS suite (1981 tests) and tvOS suite (1792 tests) with 0 failures, the macOS build and the v1 path guard. The final stack was also exercised on iOS and tvOS simulators against a v1/v2 bridge server: sign-in (password and QR), restore, browse, search, detail, favorites and watchlist, playback (direct play, transcode, subtitles, stop), audiobooks, downloads with offline playback, settings, requests, profiles, push registration and diagnostics. Server logs showed no /api/v1 request from the new builds except the retained health probe.

Remaining: no open verified findings. Merge in stack order.

Mergeability: 8/10 — conditional. The approach holds up and every verified finding is fixed. Conditions: this PR's CI must pass (it was pending at review time), and the owner still plans a physical-device check of the completed stack.

Review by Claude Opus 5.5 (claude-opus-5-5) agents in Claude Code (T3 Code).

@Quick104
Quick104 force-pushed the apiv2-stack/09-unauthenticated-health-probe branch from e7cd7cc to 6665e5e Compare September 23, 2026 13:19
@Quick104
Quick104 force-pushed the apiv2-stack/08-refresh-through-v2 branch from 0def986 to d31bdc5 Compare September 23, 2026 13:31
Base automatically changed from apiv2-stack/08-refresh-through-v2 to main September 23, 2026 13:31
The reachability probe went through the authenticated HTTPClient.get, so
it carried the bearer and profile headers. With an expired or revoked
session the public health endpoint could answer 401, and the probe then
started a token refresh and could end the session, all to learn whether
the server was up.

The probe now reads the active server's health endpoint through a new
HTTPClient.getUnauthenticatedFromActiveServer, which attaches no
credentials, never refreshes, and still reports the outcome to
ConnectionMonitor. ConnectionMonitor keeps GET /api/v1/health as the
retained unversioned probe; the doc comments now say it is sent without
credentials.

Stack-PR: W1-H
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Quick104
Quick104 force-pushed the apiv2-stack/09-unauthenticated-health-probe branch from 6665e5e to fa2ad8e Compare September 23, 2026 13:31
@Quick104
Quick104 merged commit 00dba12 into main Sep 23, 2026
3 of 6 checks passed
@Quick104
Quick104 deleted the apiv2-stack/09-unauthenticated-health-probe branch September 23, 2026 13:31
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