Bug 1253958 - Make getHSTSPreloadList.js and genHPKPStaticPins.js gracefully handle trailing whitespace in URL entries. draft
authorCykesiopka <cykesiopka.bmo@gmail.com>
Sun, 06 Mar 2016 16:02:52 -0800
changeset 337286 fe9f7fc374192ea9ed985fab8e67680260a53da1
parent 337285 2f67bfe42f63fd0a870b6373795bd35d12e83977
child 515615 a49d69b3f894a9b665d7ee44f0d0b21bf24b0ca5
push id12305
push usercykesiopka.bmo@gmail.com
push dateMon, 07 Mar 2016 00:05:02 +0000
bugs1253958
milestone47.0a1
Bug 1253958 - Make getHSTSPreloadList.js and genHPKPStaticPins.js gracefully handle trailing whitespace in URL entries. MozReview-Commit-ID: Kyc7JzxVEo0
security/manager/tools/genHPKPStaticPins.js
security/manager/tools/getHSTSPreloadList.js
--- a/security/manager/tools/genHPKPStaticPins.js
+++ b/security/manager/tools/genHPKPStaticPins.js
@@ -361,16 +361,21 @@ function downloadAndParseChromePins(file
     // HSTS entry only
     if (!entry.pins) {
       return;
     }
     let pinsetName = cData.substitute_pinsets[entry.pins];
     if (!pinsetName) {
       pinsetName = entry.pins;
     }
+
+    // We trim the entry name here to avoid breaking hostname comparisons in the
+    // HPKP implementation.
+    entry.name = entry.name.trim();
+
     let isProductionDomain =
       (cData.production_domains.indexOf(entry.name) != -1);
     let isProductionPinset =
       (cData.production_pinsets.indexOf(pinsetName) != -1);
     let excludeDomain =
       (cData.exclude_domains.indexOf(entry.name) != -1);
     let isTestMode = !isProductionPinset && !isProductionDomain;
     if (entry.pins && !excludeDomain && chromeImportedPinsets[entry.pins]) {
--- a/security/manager/tools/getHSTSPreloadList.js
+++ b/security/manager/tools/getHSTSPreloadList.js
@@ -92,19 +92,22 @@ function download() {
 function getHosts(rawdata) {
   var hosts = [];
 
   if (!rawdata || !rawdata.entries) {
     throw new Error("ERROR: source data not formatted correctly: 'entries' " +
                     "not found");
   }
 
-  for (entry of rawdata.entries) {
+  for (let entry of rawdata.entries) {
     if (entry.mode && entry.mode == "force-https") {
       if (entry.name) {
+        // We trim the entry name here to avoid malformed URI exceptions when we
+        // later try to connect to the domain.
+        entry.name = entry.name.trim();
         entry.retries = MAX_RETRIES;
         entry.originalIncludeSubdomains = entry.include_subdomains;
         hosts.push(entry);
       } else {
         throw new Error("ERROR: entry not formatted correctly: no name found");
       }
     }
   }