Bug 1452139 - Don't include cookies when posting Telemetry. r=gfritzsche, r=franziskus, a=jcristau
authorChris H-C <chutten@mozilla.com>
Tue, 10 Apr 2018 15:56:07 -0400
changeset 463325 ddcb312fc7dccfba94336c1a557ff4f63181fb9f
parent 463324 1d9217a70ada7598d37b73643e4ce8a83e924dea
child 463326 2055a42c5bf4059802cfb698984bb0f904ee4901
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfritzsche, franziskus, jcristau
bugs1452139
milestone60.0
Bug 1452139 - Don't include cookies when posting Telemetry. r=gfritzsche, r=franziskus, a=jcristau We don't need or want cookies sent to incoming.tmo. It just throws them on the floor, but we needn't waste clients' bandwidth on it. MozReview-Commit-ID: F9WjcDyKFGN
toolkit/components/telemetry/TelemetrySend.jsm
toolkit/components/telemetry/tests/unit/test_TelemetrySend.js
--- a/toolkit/components/telemetry/TelemetrySend.jsm
+++ b/toolkit/components/telemetry/TelemetrySend.jsm
@@ -1108,17 +1108,18 @@ var TelemetrySendImpl = {
       return Promise.reject();
     }
 
     this._log.trace("_doPing - server: " + this._server + ", persisted: " + isPersisted +
                     ", id: " + id);
 
     const url = this._buildSubmissionURL(ping);
 
-    let request = new ServiceRequest();
+    // Don't send cookies with these requests.
+    let request = new ServiceRequest({mozAnon: true});
     request.mozBackgroundRequest = true;
     request.timeout = Policy.pingSubmissionTimeout();
 
     request.open("POST", url, true);
     request.overrideMimeType("text/plain");
     request.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
     request.setRequestHeader("Date", Policy.now().toUTCString());
 
--- a/toolkit/components/telemetry/tests/unit/test_TelemetrySend.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySend.js
@@ -17,16 +17,18 @@ ChromeUtils.import("resource://gre/modul
 ChromeUtils.import("resource://gre/modules/osfile.jsm", this);
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", this);
 
 ChromeUtils.import("resource://gre/modules/TelemetryStopwatch.jsm", this);
 
 ChromeUtils.defineModuleGetter(this, "TelemetryHealthPing",
   "resource://gre/modules/TelemetryHealthPing.jsm");
 
+XPCOMUtils.defineLazyServiceGetter(Services, "cookies", "@mozilla.org/cookieService;1", "nsICookieService");
+
 const MS_IN_A_MINUTE = 60 * 1000;
 
 function countPingTypes(pings) {
   let countByType = new Map();
   for (let p of pings) {
     countByType.set(p.type, 1 + (countByType.get(p.type) || 0));
   }
   return countByType;
@@ -517,16 +519,32 @@ add_task(async function test_sendCheckOv
   const ping = await PingServer.promiseNextPing();
   Assert.equal(ping.type, TEST_PING_TYPE, "Must receive a ping of the expected type");
 
   // Restore the test mode and disable the override.
   TelemetrySend.setTestModeEnabled(true);
   Services.prefs.clearUserPref(TelemetryUtils.Preferences.OverrideOfficialCheck);
 });
 
+add_task(async function testCookies() {
+  const TEST_TYPE = "test-cookies";
+
+  await TelemetrySend.reset();
+  PingServer.clearRequests();
+
+  let uri = Services.io.newURI("http://localhost:" + PingServer.port);
+  Services.cookies.setCookieString(uri, null, "cookie-time=yes", null);
+
+  const id = await TelemetryController.submitExternalPing(TEST_TYPE, {});
+  let request = await PingServer.promiseNextRequest();
+  let ping = decodeRequestPayload(request);
+  Assert.equal(id, ping.id, "We're testing the right ping's request, right?");
+  Assert.equal(false, request.hasHeader("Cookie"), "Request should not have Cookie header");
+});
+
 add_task(async function test_measurePingsSize() {
   const TEST_TYPE = "test-measure-ping-size";
 
   let histSuccessPingSize = Telemetry.getHistogramById("TELEMETRY_SUCCESSFUL_SEND_PINGS_SIZE_KB");
   let histFailedPingSize = Telemetry.getHistogramById("TELEMETRY_FAILED_SEND_PINGS_SIZE_KB");
 
   for (let h of [histSuccessPingSize, histFailedPingSize]) {
     h.clear();