Page MenuHomeMiraheze

Some pages load in mobile mode by default
Closed, InvalidPublic

Description

It seems possible that various pages are cached in mobile mode, and a valid desktop user-agent is recognized as a mobile user. The result is that Varnish returns the mobile version of a page to a desktop user.

Event Timeline

Only appears to be happening when logged out

I have tried that on PC (while logged out) and still do not get any issue.

Must just be me, and besides, no longer seems to happen

Southparkfan renamed this task from Miraheze meta loads in mobile mode by default to Some pages load in mobile mode by default.Aug 27 2016, 21:56
Southparkfan reopened this task as Open.
Southparkfan triaged this task as High priority.
Southparkfan updated the task description. (Show Details)

Just got an e-mail to staff[at]mh.o that a page is cached in the mobile version. I confirmed that cp2 seems to have the mobile version cached, and is serving that to desktop users.

Since it is rare/hard to reproduce, I don't know what the exact cause is. Still investigating.

I want this snippet in the config:

sub identify_device {
        # Used in vcl_backend_fetch and vcl_hash
        set req.http.X-Device = "desktop";

        # If the User-Agent matches the regex (this is the official regex used in MobileFrontend for automatic device detection),
        # and the cookie does NOT explicitly state the user does not want the mobile version, we
        # set X-Device to phone-tablet. This will force the mobile version on the backend.
        if (req.http.User-Agent ~ "(?i)(mobi|240x240|240x320|320x320|alcatel|android|audiovox|bada|benq|blackberry|cdm-|compal-|docomo|ericsson|hiptop|htc[-_]|huawei|ipod|kddi-|
kindle|meego|midp|mitsu|mmp\/|mot-|motor|ngm_|nintendo|opera.m|palm|panasonic|philips|phone|playstation|portalmmm|sagem-|samsung|sanyo|sec-|semc-browser|sendo|sharp|silk|softban
k|symbian|teleca|up.browser|vodafone|webos)" && req.http.Cookie !~ "(stopMobileRedirect=true|mf_useformat=desktop)") {
                set req.http.X-Device = "phone-tablet";
        }

        if (req.http.Cookie ~ "mf_useformat=true" || req.url ~ "useformat=mobile") {
                set req.http.X-Device = "phone-tablet";
        }

        set req.http.Cookie = regsuball(req.http.Cookie, "(^|(?<=; )) *mf_useformat=[^;]+;? *", "\1");
        set req.http.Cookie = regsuball(req.http.Cookie, "(^|(?<=; )) *stopMobileRedirect=[^;]+;? *", "\1");

        if (req.http.X-Device == "phone-tablet") {
                set req.http.Cookie = regsub(req.http.Cookie, "^(.+)$", "\1; mf_useformat=true");
        } else {
                set req.http.Cookie = regsub(req.http.Cookie, "^(.+)$", "\1; mf_useformat=desktop");
        }
}

The goal:

  • If the client is considered as a mobile user, just force the mobile version via a cookie
  • If the client is considered as a desktop user, just force the desktop version via a cookie

Less hassle than the previous config, although the regex is ugly, and doesn't seem to work now....

Southparkfan lowered the priority of this task from High to Normal.Sep 21 2016, 15:02

Fix blocked by upgrade to stretch/packaging a deb with Varnish 4.1)..

I would love https://github.com/varnish/varnish-modules/blob/master/docs/vmod_cookie.rst, but we need Varnish 4.1 for it. Packaging a Varnish 4.1 deb with all varnish modules for use in our own apt repository (https://wiki.debian.org/SettingUpSignedAptRepositoryWithReprepro) is a possibility.

A simple static site hosting debs is also possible, and is easier than maintaining an apt repository, but it isn't compatible with the package { 'packagename': } wrapper. If we want to go with an apt repository, we should make a goal (Goal-2017-Jan-Jun) of that.

Just go with the static deb for now.

An apt repo is cool but has maintenance costs with it, adds something else for us to watch and keep up and painfully can add to our capacity crunch depending on usage and co.

Maybe we shouldn't only blame ourselves, it just happened for me while trying to access MW.org.

But it's still us because we run varnish 100%.

We have upgraded cp2, cp4 and cp5 to stretch which has varnish 5 now.

I used to experience this but now I don't. No seems to be reporting it either and the interest in this seems now to be rather null given the upgrade work done 2 months ago.