Repository navigation
fix(MyAnonaMouse): persist refreshed mam_id so sessions don't expire after 30 days - #308
Open
director-mouse wants to merge 2 commits into
Open
director-mouse wants to merge 2 commits into
director-mouse wants to merge 2 commits into
Conversation
Save rotated mam_id values from successful account-status responses in indexer settings so the existing refresh service persists them. This prevents requests from continually reusing the original session cookie until it expires.
Verify that a rotated mam_id is sent on the next account-status request and saved by the refresh service, that missing or blank cookies keep the current value, and that failed refreshes save nothing.
director-mouse
marked this pull request as ready for review
October 10, 2026 22:14
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.
My MAM indexer has been losing auth on the 1st of every month for a while now, and after pulling the logs it turned out to be exactly 30 days after each session was created, to within the granularity of the hourly
MyAnonaMouseAccountStatusServicerefresh. Two consecutive cycles lined up: a session created 2026-07-02 ~03:00 UTC died 2026-08-01 between 02:51 and 03:03 UTC, and the replacement created 2026-08-02 ~03:03 UTC died 2026-09-01 between 02:32 and 02:56 UTC. In both cases MAM started answering403withError, you are not signed inon bothjsonLoad.php?snatch_summaryandloadSearchJSONbasic.php, with no network changes on my side.MAM rotates the
mam_idcookie viaSet-Cookie, and the comment above theStoreResponseCookielines inMyAnonaMouse.cssays the intent is to keep the "updated mam_id from MAM". The code never manages that, though. Every request setsrequest.Cookies["mam_id"] = Settings.MamId, andInitializeRequestCookiesinHttpClient.csletsrequest.Cookiesoverwrite whatever the persistent container holds (and withStoreRequestCookie = trueit writes the stale value back into the container as well). So Chaptarr only ever presents the original cookie, and the original cookie has an absolute expiry of roughly 30 days.This PR fixes that in the one place that already has the right plumbing.
RefreshAccountStatus()runs hourly andMyAnonaMouseAccountStatusServicealready calls_indexerFactory.Update(definition)right after it to persistUserClass,IsVipand the unsatisfied counters. If the response carries amam_idthat differs fromSettings.MamId, we write it intoSettings.MamIdand the existing persistence call saves it. Nothing else changes: the search and download paths keep overriding the jar withSettings.MamId, which is fine once that value is kept current, and the up-to-one-hour lag between MAM rotating and Chaptarr persisting is a non-issue given the old cookie stays valid for a month.One thing worth knowing is that this only does anything while the status refresh succeeds. Because
ProviderFactoryreloads definitions from the DB on every call, a rotatedmam_idwritten intoSettingsis thrown away ifRefreshAccountStatus()throws before_indexerFactory.Update(definition)runs, and Chaptarr keeps presenting the last one that was saved. That's what happened between MAM'ssnatch_summaryresponse change on 2026-09-23 and #189 (#189), which is inv0.9.965, so this PR has no other dependencies now.A couple of things I'm not 100% sure about and would appreciate a second pair of eyes on:
mam_idon everyjsonLoad.php?snatch_summaryresponse as far as I can tell, withMax-Age=1296000(15 days) on the new cookie, and older values keep working after newer ones are issued. I don't know whether that's guaranteed behavior on MAM's side or just what it happens to do today.TestConnection()callsRefreshAccountStatus()on a throwaway definition, so a rotated value there won't be persisted, which I think is the correct behavior but worth calling out.I've been running this patch since 2026-09-07 05:25 UTC, on a fresh session created at the same time (on
v0.9.958plus #189, and now onv0.9.965). That session's old 30 day mark was 2026-10-07 05:25 UTC, and it went straight past it with no403s, withMAM issued a refreshed mam_idandUpdated MAM account statuslogged on every hourly refresh. The patch applies cleanly tov0.9.965.I've also added regression tests to
MyAnonaMouseWedgeFixture: a rotatedmam_idis sent on the next status request and saved by the refresh service, a missing or blank cookie keeps the current value, and a failed refresh (HTTP error or invalid summary) saves nothing. The two rotation tests fail without the fix.dotnet test src/Chaptarr.Core.Test/Chaptarr.Core.Test.csprojpasses (3,043 tests), though locally I had to add-p:WarningsNotAsErrors=NU1902%3BNU1903because restore currently fails on the existingSixLabors.ImageSharp3.1.12 vulnerability warnings.