Skip to content

Use browser headers on login POST and MFA verify#216

Merged
matin merged 1 commit intomatin:mainfrom
tobias-goertz:fix/consistent-login-ua
Mar 19, 2026
Merged

Use browser headers on login POST and MFA verify#216
matin merged 1 commit intomatin:mainfrom
tobias-goertz:fix/consistent-login-ua

Conversation

@tobias-goertz
Copy link
Copy Markdown
Contributor

@tobias-goertz tobias-goertz commented Mar 19, 2026

Summary

Cloudflare detects the User-Agent switch between the sign-in page (browser UA via SSO_PAGE_HEADERS) and the login POST (default GCM-iOS UA) and returns 429 Too Many Requests.

Pass SSO_PAGE_HEADERS on both the login POST and MFA verify call to keep the User-Agent consistent within the session.

Test plan

  • Without fix: instant 429 on login POST, even after hours of no activity
  • With fix: login succeeds (200 + ticket)
  • Verified locally with non-MFA account

Summary by CodeRabbit

  • Bug Fixes

    • Improved request handling for authentication and multi-factor authentication endpoints by including browser-like headers to enhance compatibility.
  • Chores

    • Bumped package version to 0.7.11.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 19, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 63bbf198-f61a-4b83-b3e5-544d5d16dcef

📥 Commits

Reviewing files that changed from the base of the PR and between fa6f2b6 and 464c1b5.

📒 Files selected for processing (2)
  • src/garth/sso.py
  • src/garth/version.py
✅ Files skipped from review due to trivial changes (1)
  • src/garth/version.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/garth/sso.py

Walkthrough

Added SSO_PAGE_HEADERS to two POST requests in login and handle_mfa so SSO authentication POSTs include predefined browser-like headers (User-Agent, Accept, Accept-Language, Sec-Fetch-*) instead of relying on default request headers; also bumped package version to 0.7.11.

Changes

Cohort / File(s) Summary
SSO Headers
src/garth/sso.py
Added headers=SSO_PAGE_HEADERS to client.post calls in login (/mobile/api/login) and handle_mfa (/mobile/api/mfa/verifyCode) to send browser-like SSO headers.
Version Bump
src/garth/version.py
Updated __version__ from "0.7.10" to "0.7.11".

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding browser headers to login POST and MFA verify requests to maintain User-Agent consistency and avoid Cloudflare 429 errors.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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 and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.91%. Comparing base (9760c41) to head (464c1b5).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #216   +/-   ##
=======================================
  Coverage   99.91%   99.91%           
=======================================
  Files          68       68           
  Lines        3569     3569           
=======================================
  Hits         3566     3566           
  Misses          3        3           
Flag Coverage Δ
unittests 99.91% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tobias-goertz
Copy link
Copy Markdown
Contributor Author

@matin PTAL, this should fix at least the 429 issues the people are observing

Cloudflare detects the User-Agent switch between the sign-in page
(browser UA) and the login POST (GCM-iOS UA) and returns 429.
Use SSO_PAGE_HEADERS on both API calls to stay consistent.
@tobias-goertz tobias-goertz force-pushed the fix/consistent-login-ua branch from fa6f2b6 to 464c1b5 Compare March 19, 2026 12:59
@matin matin merged commit 6c1b537 into matin:main Mar 19, 2026
23 checks passed
@jirinn
Copy link
Copy Markdown

jirinn commented Mar 19, 2026

@papedefer
Copy link
Copy Markdown

Thanks, instantly fixed the project withings-sync 🚀 !
🥇

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.

4 participants