varnishcache / varnish-devicedetect

VCL based device detection for Varnish Cache.
Other
300 stars 88 forks source link

iOS User-Agent used in OS process retrieving icons for “Add To Home Screen” not recognized as a mobile device. #17

Closed rasmusfrederiksen closed 10 years ago

rasmusfrederiksen commented 10 years ago

I just stumbled upon a piece of weird behaviour in the latest iOS release.

We are using varnish to redirect specific urls when accessing them with a smartphone. This works perfectly except when using the iOS “Add to Home Screen” option for bookmarking pages as icons on the app home screen. The bookmark works as expected, but the icon for the app (a link to which is defined in the source of the bookmarked html page) does not.

Safari “correctly” identifies itself using this User-Agent header:

Mozilla/5.0 (iPhone; CPU iPhone OS 7_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D167 Safari/9537.53

Which is caught by the Varnish devicedetect rule just fine, but when inspecting the requests coming out of the iPhone upon using “Add to Home Screen” the User-Agent header for the requests for the icons was:

MobileSafari/9537.53 CFNetwork/672.1.13 Darwin/13.1.0

Probably because the requests for the icons are handled by the OS rather than Safari (my guess), but the effect is that this evades the devicedetect rule altogether and causes the requests for the icons to 404.

serbanghita commented 10 years ago

@avector nice catch! Apparently I missed this too. You're right it's the application's web browser (WebView ?) which is producing these user-agents. Check https://gist.github.com/jabley/990596 I'll get back to the thread after some research. :+1:

lkarsten commented 10 years ago

I don't have the units to test this, but it sounds like something that should be added to the ruleset.

Is it always a cellphone with "MobileSafari", or can it be an ipad as well?

rasmusfrederiksen commented 10 years ago

Okay, I ran this through the simulator, these are the user-agent strings, it seems the only factor affecting the user-agent string is the version of iOS and it always comes back as “MobileSafari”.

iPhone        3.5"       6.1   MobileSafari/8536.25 CFNetwork/609.1.4 Darwin/13.2.0

iPhone Retina 3.5"       7.1   MobileSafari/9537.53 CFNetwork/672.1.13 Darwin/13.2.0
iPhone Retina 3.5"     7.0.3   MobileSafari/9537.53 CFNetwork/672.0.8 Darwin/13.2.0
iPhone Retina 3.5"       6.1   MobileSafari/8536.25 CFNetwork/609.1.4 Darwin/13.2.0

iPhone Retina            7.1   MobileSafari/9537.53 CFNetwork/672.1.13 Darwin/13.2.0
iPhone Retina          7.0.3   MobileSafari/9537.53 CFNetwork/672.0.8 Darwin/13.2.0
iPhone Retina            6.1   MobileSafari/8536.25 CFNetwork/609.1.4 Darwin/13.2.0

iPhone Retina 64-bit     7.1   MobileSafari/9537.53 CFNetwork/672.1.13 Darwin/13.2.0
iPhone Retina 64-bit   7.0.3   MobileSafari/9537.53 CFNetwork/672.0.8 Darwin/13.2.0

iPad                     7.1   MobileSafari/9537.53 CFNetwork/672.1.13 Darwin/13.2.0
iPad                   7.0.3   MobileSafari/9537.53 CFNetwork/672.0.8 Darwin/13.2.0
iPad                     6.1   MobileSafari/8536.25 CFNetwork/609.1.4 Darwin/13.2.0

iPad Retina              7.1   MobileSafari/9537.53 CFNetwork/672.1.13 Darwin/13.2.0
iPad Retina            7.0.3   MobileSafari/9537.53 CFNetwork/672.0.8 Darwin/13.2.0
iPad Retina              6.1   MobileSafari/8536.25 CFNetwork/609.1.4 Darwin/13.2.0

iPad Retina   64-bit     7.1   MobileSafari/9537.53 CFNetwork/672.1.13 Darwin/13.2.0
iPad Retina   64-bit   7.0.3   MobileSafari/9537.53 CFNetwork/672.0.8 Darwin/13.2.0
lkarsten commented 10 years ago

From what I read out of this, we can't differ between an iPad and an iPhone using this string. Is this correct? If that is the case, we're kind of out of luck.

rasmusfrederiksen commented 10 years ago

I agree. It is impossible to differentiate between devices based on this...

lkarsten commented 10 years ago

Ok. I guess those interested can make an "generic-apple" class/grouping for this, shouldn't be hard and solve your immediate problem.

The ruleset is meant to be concise and easy to use, without aiming for completeness.

I won't add this currently. If it becomes a bigger issue later down the road, I'm open to reconsidering it.