Bug 1542895 - Allow file URLs as origins. r=Felipe
authorMichael Kaply <mozilla@kaply.com>
Tue, 23 Apr 2019 21:09:47 +0000
changeset 470679 ec03fbaacace17f756ce2b675eb6f442feac1894
parent 470678 3000254ea670ca499bca1bc397807ab808734167
child 470680 44870572e85ad7b9c3d4e00d3012a3e7768d9a87
push id83904
push usermozilla@kaply.com
push dateWed, 24 Apr 2019 14:43:29 +0000
treeherderautoland@ec03fbaacace [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe
bugs1542895
milestone68.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 1542895 - Allow file URLs as origins. r=Felipe Differential Revision: https://phabricator.services.mozilla.com/D28348
toolkit/components/utils/JsonSchemaValidator.jsm
toolkit/components/utils/test/browser/browser_JsonSchemaValidator.js
--- a/toolkit/components/utils/JsonSchemaValidator.jsm
+++ b/toolkit/components/utils/JsonSchemaValidator.jsm
@@ -205,23 +205,31 @@ function validateAndParseSimpleParam(par
     case "origin":
       if (typeof(param) != "string") {
         break;
       }
 
       try {
         parsedParam = new URL(param);
 
-        let pathQueryRef = parsedParam.pathname + parsedParam.hash;
-        // Make sure that "origin" types won't accept full URLs.
-        if (pathQueryRef != "/" && pathQueryRef != "") {
-          log.error(`Ignoring parameter "${param}" - origin was expected but received full URL.`);
-          valid = false;
+        if (parsedParam.protocol == "file:") {
+          // Treat the entire file URL as an origin.
+          // Note this is stricter than the current Firefox policy,
+          // but consistent with Chrome.
+          // See https://bugzilla.mozilla.org/show_bug.cgi?id=803143
+          valid = true;
         } else {
-          valid = true;
+          let pathQueryRef = parsedParam.pathname + parsedParam.hash;
+          // Make sure that "origin" types won't accept full URLs.
+          if (pathQueryRef != "/" && pathQueryRef != "") {
+            log.error(`Ignoring parameter "${param}" - origin was expected but received full URL.`);
+            valid = false;
+          } else {
+            valid = true;
+          }
         }
       } catch (ex) {
         valid = false;
       }
       break;
 
     case "URL":
     case "URLorEmpty":
--- a/toolkit/components/utils/test/browser/browser_JsonSchemaValidator.js
+++ b/toolkit/components/utils/test/browser/browser_JsonSchemaValidator.js
@@ -142,16 +142,42 @@ add_task(async function test_origin_valu
   is(parsed.pathname + parsed.hash, "/", "pathname is corect");
 
   // Invalid values:
   ok(!JsonSchemaValidator.validateAndParseParameters("https://www.example.com/foobar", schema)[0], "Origin cannot contain a path part");
   ok(!JsonSchemaValidator.validateAndParseParameters("https://:!$%", schema)[0], "Invalid origin");
   ok(!JsonSchemaValidator.validateAndParseParameters({}, schema)[0], "Invalid value");
 });
 
+add_task(async function test_origin_file_values() {
+  // File URLs can also be origins
+  let schema = {
+    type: "origin",
+  };
+
+  let valid, parsed;
+  [valid, parsed] = JsonSchemaValidator.validateAndParseParameters("file:///foo/bar", schema);
+  ok(valid, "Origin is valid");
+  ok(parsed instanceof URL, "parsed is a nsIURI");
+  is(parsed.href, "file:///foo/bar", "Should get what we passed in");
+});
+
+add_task(async function test_origin_file_values() {
+  // File URLs can also be origins
+  let schema = {
+    type: "origin",
+  };
+
+  let valid, parsed;
+  [valid, parsed] = JsonSchemaValidator.validateAndParseParameters("file:///foo/bar/foobar.html", schema);
+  ok(valid, "Origin is valid");
+  ok(parsed instanceof URL, "parsed is a nsIURI");
+  is(parsed.href, "file:///foo/bar/foobar.html", "Should get what we passed in");
+});
+
 add_task(async function test_array_values() {
   // The types inside an array object must all be the same
   let schema = {
     type: "array",
     items: {
       type: "number",
     },
   };