Skip to content

fix(garminauth): stop headless login on an error status from the signin page - #341

Merged
bpauli merged 2 commits into
mainfrom
fix/headless-signin-status
Nov 11, 2026
Merged

bpauli merged 2 commits into
mainfrom
fix/headless-signin-status

Conversation

@bpauli

@bpauli bpauli commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Why

A headless login failed with CSRF token not found in HTML while Garmin was refusing the sign-in page (#340). gccli never checked the status of that page, so it hid the real answer. The login now stops on any status other than 200 and names it.

What changed

  • loginHeadless returns sso signin page returned <status> (title="<page title>") when GET /sso/signin is not 200, before it parses the page.
  • A test serves a 427 sign-in page and checks the message and that no credentials are posted.

Scope

  • Only the sign-in page GET. The credentials POST still treats a 427 as a normal answer. Nothing has shown that path failing, so it stays as is.
  • No retry. A block lasts longer than any retry gccli could wait out, and more requests could extend it.

Blast Radius

Only auth login --headless when Garmin refuses the sign-in page. The exit code stays 1 and the --json error code stays error. Only the message changes. A successful login is unchanged.

Verification

  • Built base and head and ran auth login --headless against a local HTTPS mock that answers the sign-in page with 427, with HOME and XDG_CONFIG_HOME on temp directories. Base printed login: extract CSRF: CSRF token not found in HTML. Head printed login: sso signin page returned 427 (title="Access denied"). Both exit 1.
  • TestLoginHeadless_SigninPageBlocked fails on the test commit and passes with the fix.
  • make fmt-check, make lint, go vet -tags e2e ./... and make test pass.

Fixes #340.

@bpauli

bpauli commented Nov 11, 2026

Copy link
Copy Markdown
Owner Author

Independent verification: PASS+NOTES

Head 7b8bdbe52cde97d8d74d307d8a7857e5826466a2, base e93f879. Linux, Go 1.27.3 (GOTOOLCHAIN=go1.26.0 for make tools / make lint). Every test and binary run used temp HOME and XDG_CONFIG_HOME. No live Garmin calls.

  1. Worktrees: head and base checked out at the exact SHAs. Pass.
  2. make tools in both worktrees. Pass.
  3. Gate on head: make fmt-check ok, make lint 0 issues, go vet -tags e2e ./... ok, make test exit 0, no failures. Pass.
  4. Both binaries run against a local HTTPS mock (CONNECT proxy, self-signed sso.garmin.com), with GCCLI_KEYRING_BACKEND=file and the password typed on a pty. The mock got no requests for any other host or path.
    • a. GET /sso/signin → 427 <title>Access denied</title>. The only change is the message line. stdout is empty and the exit code is 1 in both. Head sent 0 POST /sso/signin (base also sent 0).
      base:        login: extract CSRF: CSRF token not found in HTML
      head:        login: sso signin page returned 427 (title="Access denied")
      base --json: {"error":{"code":"error","message":"login: extract CSRF: CSRF token not found in HTML"}}
      head --json: {"error":{"code":"error","message":"login: sso signin page returned 427 (title=\"Access denied\")"}}
      
    • b. Sign-in page 200 with _csrf, then the POST returns GARMIN > Error. stdout, stderr and exit code match base byte for byte, with and without --json (login: authentication failed (title="GARMIN > Error"): service ticket not found in response, exit 1, 1 POST each). Pass.
  5. Defect injection: I removed the status check in a scratch copy, which makes the file identical to 04a7b95's. TestLoginHeadless_SigninPageBlocked then fails (error = "extract CSRF: CSRF token not found in HTML"). With the check restored, it passes. Pass.
  6. PR Verification claims rerun: the mock comparison, the test failing on the test commit and passing with the fix, and the gate. All hold. Pass.
  7. CI on head: conformance, darwin-cgo-build and test all pass.

Note: the test's posts != 0 assertion cannot fail against the pre-fix code. The 427 page has no CSRF token, so the old code also stops before the POST. The message assertion is what catches the missing check. The no-POST guarantee holds; this only limits what that assertion proves.

@bpauli
bpauli merged commit 7d4fefc into main Nov 11, 2026
3 checks passed
@bpauli
bpauli deleted the fix/headless-signin-status branch November 11, 2026 16:57
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.

auth login --headless reports a missing CSRF token when Garmin refuses the sign-in page

1 participant