otsukare Thoughts after a day of work

Subtle Modifications to the UA, Big Consequences

It always start with a very simple bug report. In this case the tester went through a sequence of tests and explains a bug. An additional person testing can't confirm the bug. They don't see the same effects. Temporary glitch from the site? Device Capabilities? Or… User Agent Sniffing.

The bug description gives the steps for reproducing the issue. The second tester before trying to contact the site owner tries to reproduce on Firefox OS 1.3 without success. The first tester seems to receive a mobile site, when the second one receives a desktop site.

So I decided to try myself with the normal Firefox OS User-Agent Mozilla/5.0 (Mobile; rv:28.0) Gecko/28.0 Firefox/28.0

GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate, compress
Host: www.baidu.com
User-Agent: Mozilla/5.0 (Mobile; rv:28.0) Gecko/28.0 Firefox/28.0

HTTP/1.1 200 OK
BDPAGETYPE: 1
BDQID: 0x8507592e000011f5
BDUSERID: 0
Cache-Control: private
Connection: Keep-Alive
Content-Encoding: gzip
Content-Type: text/html; charset=utf-8
Date: Tue, 27 May 2014 02:11:58 GMT
Expires: Tue, 27 May 2014 02:11:21 GMT
P3P: CP=" OTI DSP COR IVA OUR IND COM "
Server: BWS/1.1
Set-Cookie: BAIDUID=7AE87596241FD318F9262E1CFB77EA7D:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
Set-Cookie: BDSVRTM=0; path=/
Set-Cookie: H_PS_PSSID=6351_6552_1455_5223_6582_6478_4760_6017_6675_6697_6439_6771_6530_6450; path=/; domain=.baidu.com
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-Powered-By: HPHP

Nothing seems weird at first site, but indeed we receive the Desktop content.

screenshot of Desktop content for baidu

Let's use the Firefox for Android user agent string, Mozilla/5.0 (Android; Mobile; rv:28.0) Gecko/28.0 Firefox/28.0

GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate, compress
Host: www.baidu.com
User-Agent:  Mozilla/5.0 (Android; Mobile; rv:28.0) Gecko/28.0 Firefox/28.0

HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: Keep-Alive
Content-Encoding: gzip
Content-Type: text/html;charset=utf-8
Date: Tue, 27 May 2014 02:19:00 GMT
P3P: CP=" OTI DSP COR IVA OUR IND COM "
Server: nginx/1.2.4
Set-Cookie: BAIDUID=598A251DA68B3CD95209ABE496953EB8:FG=1; max-age=31536000; expires=Wed, 27-May-15 02:19:00 GMT; domain=.baidu.com; path=/; version=1
Set-Cookie: NBID=598A251DA68B3CD92D21226E95BCDA20:FG=1; max-age=2592000; expires=Thu, 26-Jun-14 02:19:00 GMT; domain=.baidu.com; path=/; version=1
Transfer-Encoding: chunked
Vary: Accept-Encoding

Interesting we can notice that we do not get the same site. The HTTP headers are different.

screenshot of Mobile content for baidu

The only difference in between the two strings is the keyword Android. But let's try further. The initial tester said further in the comment that the user agent string that was used is:

Mozilla/5.0 (Mobile;ALCATELOneTouch4019X/SVN 02001;rv:28.0)Gecko/28.0 Firefox /28.0

You will notice a few things:

* Missing spaces after `;`
* Introduction of `ALCATELOneTouch4019X/SVN 02001`
* An additional space in `Firefox /28.0`

When testing with this string.

GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate, compress
Host: www.baidu.com
User-Agent:  Mozilla/5.0 (Mobile;ALCATELOneTouch4019X/SVN 02001;rv:28.0)Gecko/28.0 Firefox/28.0

HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: Keep-Alive
Content-Encoding: gzip
Content-Type: text/html;charset=utf-8
Date: Tue, 27 May 2014 02:31:13 GMT
P3P: CP=" OTI DSP COR IVA OUR IND COM "
Server: nginx/1.2.4
Set-Cookie: BAIDUID=DA20BEF7ACDC0E6F05DB98261E04348B:FG=1; max-age=31536000; expires=Wed, 27-May-15 02:31:13 GMT; domain=.baidu.com; path=/; version=1
Set-Cookie: NBID=DA20BEF7ACDC0E6FFA525ADDCD080DDB:FG=1; max-age=2592000; expires=Thu, 26-Jun-14 02:31:13 GMT; domain=.baidu.com; path=/; version=1
Transfer-Encoding: chunked
Vary: Accept-Encoding

We receive something which looks like the Android version for the HTTP headers but the layout is this time, a third version which looks like it has been made for low capabilities mobile devices. It reminds us of yesterday's post about nginx and Chinese Web sites.

screenshot of Mobile content for baidu

Let's try to "fix up" the bogus User Agent string by adding and removing the spaces in the string at the right place.

Mozilla/5.0 (Mobile; ALCATELOneTouch4019X/SVN 02001; rv:28.0)Gecko/28.0 Firefox/28.0

Fixing up the string that way doesn't change anything. We still get the simplified content. Removing the SVN 02001 doesn't change anything either. In fact by just doing User-Agent: ALCATELOneTouch4019X, we receive the simplified version of the content. In fact even by reintroducing Android, we still get the simplified version.

Android; ALCATELOneTouch4019X

or

Mozilla/5.0 (Android; Mobile; ALCATELOneTouch4019X/SVN 02001; rv:28.0)Gecko/28.0 Firefox/28.0

The simple presence of the token ALCATELOneTouch4019X cancels the more graphic version.

All of this was for the home page, when you start browsing from these home page with different user agent strings, you get different code paths and layouts.

All of that led me to propose to have in the bug report the precise User Agent strings which have been used.

Otsukare.