Bug 1594053 - Add XTCO Telemetry r=ckerschb
authorSebastian Streich <sstreich@mozilla.com>
Mon, 18 Nov 2019 15:21:59 +0000
changeset 502424 c2ec766b798c413c44928968edd783fd454be8da
parent 502423 67de1c204ffb433aa8d8cc1c2799d17b10548b36
child 502425 f75d3d0846627e3d47efad9e61701f41491fa4be
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb
bugs1594053
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1594053 - Add XTCO Telemetry r=ckerschb Differential Revision: https://phabricator.services.mozilla.com/D51848
netwerk/base/nsNetUtil.cpp
netwerk/streamconv/converters/nsUnknownDecoder.cpp
netwerk/streamconv/converters/nsUnknownDecoder.h
toolkit/components/telemetry/Histograms.json
--- a/netwerk/base/nsNetUtil.cpp
+++ b/netwerk/base/nsNetUtil.cpp
@@ -2731,16 +2731,19 @@ void NS_SniffContent(const char* aSniffe
        * We also dont't skip sniffing if the currentContentType is empty
        * because of legacy page compatibility issues.
        */
       nsAutoCString currentContentType;
       channel->GetContentType(currentContentType);
       if (!currentContentType.IsEmpty() &&
           !StringBeginsWith(currentContentType,
                             NS_LITERAL_CSTRING("application/"))) {
+        Telemetry::AccumulateCategorical(
+            mozilla::Telemetry::LABELS_XCTO_NOSNIFF_TOPLEVEL_NAV_EXCEPTIONS::
+                NoException);
         return;
       }
     }
   }
   nsCOMArray<nsIContentSniffer> sniffers;
   cache->GetEntries(sniffers);
   for (int32_t i = 0; i < sniffers.Count(); ++i) {
     nsresult rv = sniffers[i]->GetMIMETypeFromContent(aRequest, aData, aLength,
--- a/netwerk/streamconv/converters/nsUnknownDecoder.cpp
+++ b/netwerk/streamconv/converters/nsUnknownDecoder.cpp
@@ -278,16 +278,39 @@ nsUnknownDecoder::OnStopRequest(nsIReque
 
   //
   // The total amount of data is less than the size of the sniffer buffer.
   // Analyze the buffer now...
   //
   if (contentTypeEmpty) {
     DetermineContentType(request);
 
+    /*
+     * In Case we did Sniff Unknown Content with XTCO: nosniff enabled,
+     * add an Telemetry-Entry whether the sniffed content is able to
+     * execute Script.
+     */
+    nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
+    if (channel) {
+      nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
+      if (loadInfo->GetSkipContentSniffing()) {
+        if (mContentType.EqualsLiteral("text/html") ||
+            mContentType.EqualsLiteral("text/xml") ||
+            mContentType.EqualsLiteral("aplication/pdf")) {
+          Telemetry::AccumulateCategorical(
+              mozilla::Telemetry::LABELS_XCTO_NOSNIFF_TOPLEVEL_NAV_EXCEPTIONS::
+                  ExceptionScriptable);
+        } else {
+          Telemetry::AccumulateCategorical(
+              mozilla::Telemetry::LABELS_XCTO_NOSNIFF_TOPLEVEL_NAV_EXCEPTIONS::
+                  Exception);
+        }
+      }
+    }
+
     // Make sure channel listeners see channel as pending while we call
     // OnStartRequest/OnDataAvailable, even though the underlying channel
     // has already hit OnStopRequest.
     nsCOMPtr<nsIForcePendingChannel> forcePendingChannel =
         do_QueryInterface(request);
     if (forcePendingChannel) {
       forcePendingChannel->ForcePending(true);
     }
--- a/netwerk/streamconv/converters/nsUnknownDecoder.h
+++ b/netwerk/streamconv/converters/nsUnknownDecoder.h
@@ -6,16 +6,17 @@
 #ifndef nsUnknownDecoder_h__
 #define nsUnknownDecoder_h__
 
 #include "nsIStreamConverter.h"
 #include "nsIThreadRetargetableStreamListener.h"
 #include "nsIContentSniffer.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/Atomics.h"
+#include "mozilla/Telemetry.h"
 
 #include "nsCOMPtr.h"
 #include "nsString.h"
 
 #define NS_UNKNOWNDECODER_CID                        \
   { /* 7d7008a0-c49a-11d3-9b22-0080c7cb1080 */       \
     0x7d7008a0, 0xc49a, 0x11d3, {                    \
       0x9b, 0x22, 0x00, 0x80, 0xc7, 0xcb, 0x10, 0x80 \
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -10772,16 +10772,29 @@
   "MIXED_CONTENT_UNBLOCK_COUNTER": {
     "record_in_processes": ["main", "content"],
     "products": ["firefox", "fennec", "geckoview"],
     "expires_in_version": "never",
     "kind": "enumerated",
     "n_values": 3,
     "description": "A simple counter of daily mixed-content unblock operations and top documents loaded"
   },
+  "XCTO_NOSNIFF_TOPLEVEL_NAV_EXCEPTIONS" : {
+    "record_in_processes": ["main","content"],
+    "products": ["firefox"],
+    "alert_emails": ["seceng-telemetry@mozilla.com", "sstreich@mozilla.com"],
+    "bug_numbers": [1428473],
+    "expires_in_version": "80",
+    "kind": "categorical",
+    "labels": [
+      "NoException",
+      "Exception",
+      "ExceptionScriptable"],
+    "description": "Page Navigations (top-level, iframe loads) setting 'XCTO: nosniff' without a Content-Type"
+  },
   "MIXED_CONTENT_HSTS": {
     "record_in_processes": ["main", "content"],
     "products": ["firefox", "fennec", "geckoview"],
     "alert_emails": ["seceng-telemetry@mozilla.com"],
     "expires_in_version": "never",
     "kind": "enumerated",
     "n_values": 10,
     "description": "How often would blocked mixed content be allowed if HSTS upgrades were allowed? 0=display/no-HSTS, 1=display/HSTS, 2=active/no-HSTS, 3=active/HSTS"