Bug 1467523 followup fix for case insensitive header name check, r=aswan,robwu
authorShane Caraveo <scaraveo@mozilla.com>
Wed, 10 Oct 2018 16:23:46 -0400
changeset 488877 203a8e58e64c86ba7b9cf8b66aec101b10eca3ec
parent 488876 43a51bc9a77dc2f59196a644798c1911a18615a3
child 488917 ca79a952c3905158d163f06a0132b69857901be2
push id246
push userfmarier@mozilla.com
push dateSat, 13 Oct 2018 00:15:40 +0000
reviewersaswan, robwu
bugs1467523
milestone64.0a1
Bug 1467523 followup fix for case insensitive header name check, r=aswan,robwu
toolkit/modules/addons/WebRequest.jsm
--- a/toolkit/modules/addons/WebRequest.jsm
+++ b/toolkit/modules/addons/WebRequest.jsm
@@ -131,17 +131,17 @@ class HeaderChanger {
         value = String.fromCharCode(...binaryValue);
       }
 
       let lowerCaseName = name.toLowerCase();
       let original = origHeaders.get(lowerCaseName);
 
       if (!original || value !== original.value) {
         let shouldMerge = headersAlreadySet.has(lowerCaseName);
-        this.setHeader(name, value, shouldMerge, opts);
+        this.setHeader(name, value, shouldMerge, opts, lowerCaseName);
       }
 
       headersAlreadySet.add(lowerCaseName);
     }
   }
 }
 
 const checkRestrictedHeaderValue = (value, opts = {}) => {
@@ -153,34 +153,34 @@ const checkRestrictedHeaderValue = (valu
   }
 
   if (WebExtensionPolicy.isRestrictedURI(uri)) {
     throw new Error(`Unable to set host header to restricted url.`);
   }
 };
 
 class RequestHeaderChanger extends HeaderChanger {
-  setHeader(name, value, merge, opts = {}) {
+  setHeader(name, value, merge, opts, lowerCaseName) {
     try {
-      if (name === "host") {
+      if (value && lowerCaseName === "host") {
         checkRestrictedHeaderValue(value, opts);
       }
       this.channel.setRequestHeader(name, value, merge);
     } catch (e) {
       Cu.reportError(new Error(`Error setting request header ${name}: ${e}`));
     }
   }
 
   readHeaders() {
     return this.channel.getRequestHeaders();
   }
 }
 
 class ResponseHeaderChanger extends HeaderChanger {
-  setHeader(name, value, merge, opts = {}) {
+  setHeader(name, value, merge, opts, lowerCaseName) {
     try {
       this.channel.setResponseHeader(name, value, merge);
     } catch (e) {
       Cu.reportError(new Error(`Error setting response header ${name}: ${e}`));
     }
   }
 
   readHeaders() {