Open Bug 2088848 Opened 14 days ago Updated 14 days ago

Clearing data for a single site does not remove its Alt-Svc mappings

Categories

(Toolkit :: Data Sanitization, defect)

defect

Tracking

()

People

(Reporter: leggert, Unassigned)

References

Details

(Keywords: good-first-bug)

Attachments

(1 external file)

Alt-Svc mappings (in memory and in AlternateServices.bin) are only cleared when nsHttpHandler observes last-pb-context-exited or browser:purge-session-history, both of which call AltSvcCache::ClearAltServiceMappings() for all entries.

browser:purge-session-history is only notified by SessionHistoryCleaner.deleteAll and SessionHistoryCleaner.deleteByRange in ClearDataService.sys.mjs. The per-site paths (deleteByHost, deleteByPrincipal, deleteBySite) only notify browser:purge-session-history-for-domain and browser:purge-sessionStorage, which nsHttpHandler does not observe, and no cleaner covers Alt-Svc under CLEAR_COOKIES_AND_SITE_DATA.

As a result, "Forget About This Site" and other per-site or per-principal clearing leave the site's Alt-Svc mappings in place, so the site can still recognize the client on the next visit through an alternative service it advertised earlier. Conversely, deleteByRange drops every mapping regardless of the time range, because nsHttpHandler ignores the range passed with the notification.

Possible fix: add an Alt-Svc cleaner to ClearDataService.sys.mjs with deleteByHost / deleteByPrincipal / deleteBySite (backed by a host- and origin-attributes-scoped variant of ClearAltServiceMappings) and deleteAll, included in CLEAR_COOKIES_AND_SITE_DATA, and decide whether range-based clearing should keep clearing all mappings.

Keywords: good-first-bug

The analysis in comment 0 matches the code. nsHttpHandler.cpp only ever calls AltSvcCache::ClearAltServiceMappings(), which clears every mapping. In ClearDataService.sys.mjs, only SessionHistoryCleaner.deleteAll/deleteByRange reach that path, and no cleaner handles Alt-Svc for a single host, principal or site.

Some notes for whoever picks this up:

  • New XPCOM method. The only Alt-Svc API JS can reach today is the test-only altSvcCacheKeys in nsIHttpProtocolHandler.idl, so add the new methods there: a by-host one and a by-site one, both taking an OA-pattern JSON. Model the pattern plumbing (parent-process check, OriginAttributesPattern::Init) on nsISSLTokensCache's removeSSLTokensBy*AndOriginAttributesPattern in SSLTokensCache.cpp.
  • Storage loop. Base it on ClearAltServiceMappingsMatchingOA in AlternateServices.cpp, or on DeleteDecisionsByHost in nsClientAuthRemember.cpp. Rebuild each AltSvcMapping from the stored value, not the key, because the OA suffix can contain :. Then match OriginHost() and the OA, and Remove() with the entry's Private/Persistent type.
  • Lazy-init pitfall. mStorage is only set by EnsureStorageInited() (AlternateServices.cpp), and that only runs on the first GetAltServiceMapping. The existing clear methods return early when !mStorage, so a clear issued before any HTTP load in the session silently leaves AlternateServices.bin alone. The new methods, and ideally ClearAltServiceMappings, should call EnsureStorageInited() first.
  • Partitioned entries. Mappings carry partitionKey, so deleteBySite should also remove entries partitioned under the site, as hasSite()-based cleaners such as ClientAuthRememberCleaner do. Matching on host alone leaves those behind.
  • Flag. The simplest option is to add the new AltSvcCleaner (deleteByHost/deleteByPrincipal/deleteBySite/deleteAll) to FLAGS_MAP under CLEAR_TLS_TOKEN_CACHE. Its doc comment in nsIClearDataService.idl already describes this kind of server-set "recognize a returning client" connection state. It is already part of CLEAR_FORGET_ABOUT_SITE, CLEAR_COOKIES_AND_SITE_DATA and tracker purging, and it costs none of the few free bits. Without deleteByRange, range clears fall back to deleteAll, which is the same as today's behaviour.
  • Tests. Extend test_ssl_tokens_cache.js or add a sibling Alt-Svc test, seeding mappings the way test_freshconnection_origin_attributes.js does (x-altsvc header, check via altSvcCacheKeys). Cover host, site including a partitioned entry, principal, and an unrelated host that must survive.

Suggested severity: S3. After "Forget About This Site" or a per-site clear, a site that advertised Alt-Svc can still tell it was visited before, which is a privacy gap in data clearing, but there is no data loss or breakage, and clearing all history removes the mappings.


If you'd like to provide feedback on this comment, please use the 👍 or 👎 reaction.
If you want to categorize your feedback you can add one of the following tags: ai-triage-{wrong-file, wrong-cause, hallucination, out-of-scope, not-a-bug, wrong-fix, shallow-fix, wrong-severity}.

Needinfo hackbot@mozilla.tld to have a patch generated for this bug, include any questions or directions as needed in your comment.

See Also: → 2087972

Alt-Svc mappings were only cleared wholesale (purge-session-history / last-pb-context-exited), so per-host, per-principal and per-site clearing such as "Forget About This Site" left them in place.

  • AltSvcCache: add ClearAltServiceMappingsByHost / ClearAltServiceMappingsBySite (OriginAttributesPattern aware; by-site also removes mappings partitioned under the site), sharing one storage loop with ClearAltServiceMappingsMatchingOA. Entries are matched on the mapping rebuilt from the stored value, not the key.
  • Clear methods now call EnsureStorageInited() so clearing before the first HTTP load in a session still affects AlternateServices.bin.
  • nsIHttpProtocolHandler: expose clearAltSvcMappingsByHost / clearAltSvcMappingsBySite / clearAllAltSvcMappings (parent process only).
  • ClearDataService: new AltSvcCleaner under CLEAR_TLS_TOKEN_CACHE (server-set "recognize a returning client" connection state, already part of CLEAR_FORGET_ABOUT_SITE and CLEAR_COOKIES_AND_SITE_DATA). deleteByHost mirrors TlsTokenCacheCleaner (all containers, partitionKey propagated). Range clears fall back to deleteAll, as before.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: