Bug 1845117 - re-introduce https and replacement character requirements for uriTemplates, r=mkaply

Differential Revision: https://phabricator.services.mozilla.com/D184381
This commit is contained in:
Gijs Kruitbosch 2023-07-24 15:54:16 +00:00
Родитель 763db72ed7
Коммит 57ba57f1a5
2 изменённых файлов: 61 добавлений и 0 удалений

Просмотреть файл

@ -158,6 +158,24 @@ HandlerService.prototype = {
}
let { handlers } = existingSchemeInfo;
for (let newHandler of localeHandlers.schemes[scheme].handlers) {
if (!newHandler.uriTemplate) {
console.error(
`Ignoring protocol handler for ${scheme} without a uriTemplate!`
);
continue;
}
if (!newHandler.uriTemplate.startsWith("https://")) {
console.error(
`Ignoring protocol handler for ${scheme} with insecure template URL ${newHandler.uriTemplate}.`
);
continue;
}
if (!newHandler.uriTemplate.toLowerCase().includes("%s")) {
console.error(
`Ignoring protocol handler for ${scheme} with invalid template URL ${newHandler.uriTemplate}.`
);
continue;
}
// If there is already a handler registered with the same template
// URL, ignore the new one:
let matchingTemplate = handler =>

Просмотреть файл

@ -157,3 +157,46 @@ add_task(async function test_migrations() {
);
await deleteHandlerStore();
});
/**
* Check that non-https templates or ones without a '%s' are ignored.
*/
add_task(async function invalid_handlers_are_rejected() {
let schemes = kHandlerList.default.schemes;
schemes.myfancyinvalidstuff = {
handlers: [
{
name: "No template at all",
},
{
name: "Not secure",
uriTemplate: "http://example.com/%s",
},
{
name: "No replacement percent-s bit",
uriTemplate: "https://example.com/",
},
{
name: "Actually valid",
uriTemplate: "https://example.com/%s",
},
],
};
gHandlerService.wrappedJSObject._injectDefaultProtocolHandlers();
// Now check the result:
let handler = gExternalProtocolService.getProtocolHandlerInfo(
"myfancyinvalidstuff"
);
let expectedURIs = ["https://example.com/%s"];
Assert.deepEqual(
Array.from(
handler.possibleApplicationHandlers.enumerate(Ci.nsIWebHandlerApp),
e => e.uriTemplate
),
expectedURIs,
"Should have seen only 1 handler added."
);
await deleteHandlerStore();
});