From bcf94942f9895d824c7e5c64d4e4ba3e676b22e5 Mon Sep 17 00:00:00 2001 From: Dan Stillman <dstillman@zotero.org> Date: Wed, 15 Aug 2018 22:06:51 -0400 Subject: [PATCH] Don't include "Zotero" in User-Agent sent to non-Zotero sites --- chrome/content/zotero/xpcom/zotero.js | 14 ++++---------- test/tests/zoteroTest.js | 15 +++++++++++---- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 4c555ba76c..9b3e84394b 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -2627,8 +2627,7 @@ Zotero.VersionHeader = { }, /** - * Add Firefox/[version] to the default user agent and replace Zotero/[version] with - * Zotero/[major.minor] (except for requests to zotero.org, where we include the full version) + * Replace Zotero/[version] with Firefox/[version] in the default user agent * * @param {String} domain * @param {String} ua - User Agent @@ -2640,17 +2639,12 @@ Zotero.VersionHeader = { var appName = testAppName || info.name; var pos = ua.indexOf(appName + '/'); + var appPart = ua.substr(pos); - // Default UA + // Default UA (not a faked UA from the connector if (pos != -1) { - ua = ua.slice(0, pos) + `Firefox/${info.platformVersion.match(/^\d+/)[0]}.0 ` - + appName + '/'; + ua = ua.slice(0, pos) + `Firefox/${info.platformVersion.match(/^\d+/)[0]}.0` } - // Fake UA from connector - else { - ua += ' ' + appName + '/'; - } - ua += Zotero.version.replace(/(\d+\.\d+).*/, '$1'); return ua; }, diff --git a/test/tests/zoteroTest.js b/test/tests/zoteroTest.js index 22bf74969a..f95cf47a92 100644 --- a/test/tests/zoteroTest.js +++ b/test/tests/zoteroTest.js @@ -36,14 +36,21 @@ describe("Zotero", function() { majorMinorVersion = Zotero.version.replace(/(\d+\.\d+).*/, '$1'); }); - it("should add Zotero/[major.minor] to Chrome user agent", function () { + it("should replace app name with Firefox", function () { + var platformVersion = Services.appinfo.platformVersion.match(/^\d+/)[0] + '.0'; + var ua1 = `Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 ${Zotero.clientName}/${Zotero.version}`; + var ua2 = `Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Firefox/${platformVersion}`; + assert.equal(Zotero.VersionHeader.update('example.com', ua1, ZOTERO_CONFIG.CLIENT_NAME), ua2); + }); + + it("should show Chrome user agent unchanged", function () { var ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36'; - assert.equal(Zotero.VersionHeader.update('example.com', ua, ZOTERO_CONFIG.CLIENT_NAME), ua + ` Zotero/${majorMinorVersion}`); + assert.equal(Zotero.VersionHeader.update('example.com', ua, ZOTERO_CONFIG.CLIENT_NAME), ua); }); - it("should add Zotero/[major.minor] to Firefox user agent", function () { + it("should show Firefox user agent unchanged", function () { var ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Firefox/60.0'; - assert.equal(Zotero.VersionHeader.update('example.com', ua, ZOTERO_CONFIG.CLIENT_NAME), ua + ` Zotero/${majorMinorVersion}`); + assert.equal(Zotero.VersionHeader.update('example.com', ua, ZOTERO_CONFIG.CLIENT_NAME), ua); }); }); });