Page MenuHomePhabricator

Requests for /static get an invalid WMF-Last-Access cookie for wikipedia.org on non-Wikipedia requests
Closed, DuplicatePublic

Description

Visiting https://commons.wikimedia.org/wiki/Main_Page in Firefox 80.0 causes Cookie “WMF-Last-Access-Global” has been rejected for invalid domain. warnings in the Firefox developer console.

This issue occurs on all Commons pages.
The issue occurs with ?safemode=true.
The warnings come from loading https://commons.wikimedia.org/static/apple-touch/commons.png and https://commons.wikimedia.org/static/favicon/commons.ico.

User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0

commons.png response headers
HTTP/2 200 OK
date: Tue, 01 Sep 2020 13:12:12 GMT
etag: "fbb-5a6b046455e42"
expires: Tue, 31 Aug 2021 17:46:54 GMT
cache-control: max-age=31536000
server: ATS/8.0.8
last-modified: Thu, 28 May 2020 07:28:26 GMT
content-length: 4027
access-control-allow-origin: *
content-type: image/png
age: 33418
x-cache: cp2039 hit, cp2027 hit/5423
x-cache-status: hit-front
server-timing: cache;desc="hit-front"
strict-transport-security: max-age=106384710; includeSubDomains; preload
set-cookie: WMF-Last-Access-Global=01-Sep-2020;Path=/;Domain=.wikipedia.org;HttpOnly;secure;Expires=Sat, 03 Oct 2020 12:00:00 GMT
x-client-ip: ***
accept-ranges: bytes
X-Firefox-Spdy: h2
commons.ico response headers
HTTP/2 200 OK
date: Tue, 01 Sep 2020 18:00:31 GMT
expires: Wed, 01 Sep 2021 17:42:25 GMT
cache-control: max-age=31536000
server: ATS/8.0.8
etag: W/"f19-565d6d96e382b"
last-modified: Fri, 23 Feb 2018 01:12:08 GMT
access-control-allow-origin: *
content-type: image/vnd.microsoft.icon
content-encoding: gzip
vary: Accept-Encoding
age: 16118
x-cache: cp2039 hit, cp2027 hit/8188
x-cache-status: hit-front
server-timing: cache;desc="hit-front"
strict-transport-security: max-age=106384710; includeSubDomains; preload
set-cookie: WMF-Last-Access-Global=01-Sep-2020;Path=/;Domain=.wikipedia.org;HttpOnly;secure;Expires=Sat, 03 Oct 2020 12:00:00 GMT
x-client-ip: ***
accept-ranges: bytes
content-length: 3853
X-Firefox-Spdy: h2

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
colewhite triaged this task as Medium priority.Sep 1 2020, 10:45 PM
Krinkle renamed this task from Cookie “WMF-Last-Access-Global” has been rejected for invalid domain. to Requests for /static get an invalid WMF-Last-Access cookie for wikipedia.org on non-Wikipedia requests.Apr 2 2021, 9:15 PM
Krinkle added a subscriber: RolandUnger.

This happens because our traffic layer shares the caches for /static across all domains. However, it seems the way we do that confuses the code creating the stat cookie.

$ curl -I 'https://commons.wikimedia.org/static/favicon/commons.ico'
HTTP/2 200 
date: Fri, 02 Apr 2021 01:59:21 GMT
expires: Fri, 01 Apr 2022 06:06:51 GMT
cache-control: max-age=31536000
server: ATS/8.0.8
etag: W/"f19-565d6d96e382b"
last-modified: Fri, 23 Feb 2018 01:12:08 GMT

set-cookie: WMF-Last-Access-Global=02-Apr-2021;Path=/;Domain=.wikipedia.org;HttpOnly;secure;Expires=Tue, 04 May 2021 12:00:00 GMT

It's not just /static, JavaScript and CSS files loaded with ?debug=1 like https://commons.wikimedia.org/w/extensions/Echo/modules/api/mw.echo.api.NetworkHandler.js?6dc51 and https://commons.wikimedia.org/w/skins/Vector/skinStyles/jquery.ui/jquery.ui.accordion.css?464c7 also cause the same warning (though I expect it's the same cause).
https://commons.wikimedia.org/wiki/Main_Page?debug=1&safemode=1 causes 72 of these warnings, and that's after Firefox removed all the duplicates (almost every request). This combined with T293109 make trying to debug actual JavaScript problems more difficult.

cap.png (2,665×1,093 px, 274 KB)

The URLs that use w/extensions, w/skins, and w/resources are also used outside debug mode, such as for background images referenced in minified stylesheets. These are served by WMF's static.php entrypoint, and cached in Varnish using the same hostname agnostic rules as for /static.

They can be fixed the same way indeed and are all part of the same logic that is largely characterised as "static" (/static, and misc things that map to /w/static.php).

Rather than excluding /static, perhaps it would make more sense to invert this logic and explicitly limit the cookie logic to text/html responses and/or /wiki requests. It seems like that should suffice in order to make sure this cookie is initiatlised during a session, and updated at least once on any subsequent day where a client device is active on a wiki. It doesn't need to be re-evaluated on every subresource request, and it most certainly doesn't need to be set on cross-origin requests from Wikipedia to upload.wikimedia.org, or meta.wikimedia, or login.wikimedia etc since browser reject those anyway. And even if they weren't rejected, it seems like that would only serve to skew the data wrongly to suggest a device was visiting that wiki when in actuality it wasn't. Anyway, I imagine Meta-Wiki isn't the most analysed wiki for these stats, and either way this bug was implicitly fixed once browsers rejected cross-origin cookies.

@Milimetric Who should we talk to to check whether this (minor) change would cause issues with the instrumentation?

This is still a problem today, and it makes for a distraction when debugging other cookie problems.

I second @Krinkle's idea from 2021 that the best solution for this might be to only set the cookie on HTML responses or if the path starts with /wiki.

Yeah, the wider issue here is that setting the cookie on cross-site subresource requests is probably harmful. Browsers apply all kinds of restrictions to cookies on such requests (e.g. can write but cannot read, or can read and write but the expiration will be different from what you set, or you see different cookie values for each parent domain you are making the cross-site request from) which will probably mess up the stats.

See also T375256: Cookie % has been rejected because it is foreign and does not have the "Partitioned" attribute for the Chrome equivalent.

Merged into T376384: Cookie “WMF-Last-Access-Global” has been rejected for invalid domain. which has since been resolved.

We generally prefer merging newer tasks into older ones, not the other way around. I'm doing it for this one, because the technical discussion and patches that resolve the issue, ended up at T376384.