fix(login): persist Amazon session by forcing rememberMe#14
Merged
Conversation
`roomieorder login --provider amazon` reported success but the worker kept hitting the sign-in wall. Amazon issues its auth cookies (at-main/x-main/sess-at-main) as *session* cookies unless "Keep me signed in" is set, and Chrome never flushes session cookies to the on-disk profile — so the next launch (the worker) reloaded logged-out. The checkbox is just UI for the server-side rememberMe=true param on POST /ap/signin, and Amazon A/B-tests it away on some flows. Force the param during the hand-login instead of depending on the checkbox: a login-only init script ticks an existing rememberMe control or injects a hidden rememberMe=true into the sign-in form (immediate + DOMContentLoaded + MutationObserver, so a late/SPA form is still caught). Amazon then issues *persistent* at-main/x-main cookies that Chrome stores the normal way — like Costco's SSO cookie. Verified live: at-main/x-main now carry a +1y expiry and a fresh-launch dry-run reaches a logged-in Secure checkout. The script is scoped to the login context only; buy/dump never inject JS into the store's Akamai-fronted pages. `verify_session()` relaunches a fresh context and reports persistence honestly (a logged-in reload proves the cookies were written). Tests: init-script presence (base None / Amazon drives rememberMe) and real-DOM-engine tests replaying ensureRememberMe() against synthetic sign-in markup (tick existing box / inject when absent / no-op without a form), plus a skip-slot drift net for a real /ap/signin capture.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
roomieorder login --provider amazonreported success but the worker kept hitting the sign-in wall. Confirmed from the saved cookie jar: Amazon issues its auth cookies (at-main/x-main/sess-at-main) as session cookies unless "Keep me signed in" is set, and Chrome never flushes session cookies to the on-disk profile — so the next launch (the worker) reloaded logged-out. Costco doesn't hit this because it keeps a persistent SSO cookie that survives the reload.The "Keep me signed in" checkbox is just UI for the server-side
rememberMe=trueparam onPOST /ap/signin, and Amazon A/B-tests it away on some flows (the operator's flow never rendered it).Fix
Force the param during the hand-login instead of depending on the checkbox:
AmazonPurchaser._login_init_script) runsensureRememberMe(): tick an existingrememberMecontrol, else inject a hiddenrememberMe=trueintoform[name="signIn"]. Fires immediately + onDOMContentLoaded+ via aMutationObserver, so a late/SPA-rendered form is still caught.at-main/x-maincookies that Chrome stores the normal way, like Costco's SSO cookie. No cookie juggling, rolling lifetime of months.verify_session()relaunches a fresh context and reports persistence honestly (a logged-in reload proves the cookies were written).Replaces an earlier cookie capture/re-inject band-aid (never committed) that only survived browser restarts, not Amazon's short server-side token TTL.
Verified live
at-main/x-main/sess-at-maincarry a +1y expiry (notSESSION).dry-run --provider amazonreaches a logged-in Secure checkout with the real name/address and a "Place your order" button.Tests
None; Amazon drivesrememberMe.@pytest.mark.browser) tests replayensureRememberMe()against synthetic sign-in markup: ticks an existing box / injects when absent / no-ops without a form./ap/signincapture (amazon_signin_form.html), mirroring the standing checkout-fixture pattern.pytest -q: 159 passed, 3 skipped.ruff+mypyclean.Not covered (standing caveat)
The real Place Order click + confirmation scrape (
TODO(amazon)) are only reachable past a live order — unchanged AGENTS.md §1 caveat, not introduced here.