Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Handlebars sandbox #612

Merged
merged 4 commits into from
Sep 19, 2020

Conversation

toasted-nutbread
Copy link
Collaborator

@toasted-nutbread toasted-nutbread commented Jun 17, 2020

Follow-up of #574. Implements a sandbox frame for rendering templates. The frame is currently created on the background page, but as with most things, this won't work with manifest v3. This is another intermediate step.

Another point is that apparently the sandboxing feature is not supported in Firefox WebExtensions. This means that in order to fully secure the default content_security_policy, there would need to be two versions of the extension: one for Firefox (which keeps the unsafe-eval permission on the default content_security_policy) and one for Chrome (which uses sandbox.content_security_policy).

https://developer.chrome.com/apps/sandboxingEval

  • Buttons don't appear grayed out when Anki isn't running.
  • Fields filled out incorrectly. To reproduce: Front: {expression}; Back: {screenshot}.

@toasted-nutbread
Copy link
Collaborator Author

One side effect of this change is that the handlebars sandbox can be used by non-Yomichan webpages since it is now a web_accessible_resources. However, this shouldn't have any negative side effects, since the webpage only responds to an input message and replies with an output message.

This may be able to be addressed by setting up a service worker to intercept and modify requests to the URL to have a secret, but there was difficulty and inconsistency setting that up. May be worth revisiting later.

@toasted-nutbread
Copy link
Collaborator Author

Technically it would also be doable by doing something similar to this:

const baseUrl = chrome.runtime.getURL('/bg/search.html');
const templateRendererUrl = chrome.runtime.getURL('/bg/template-renderer.html');
const callback = ({url}) => {
    if (url === templateRendererUrl) {
        const redirectUrl = `${url}?some-secret`;
        return {redirectUrl};
    }
    return {};
};
const filter = {urls: [baseUrl]};
chrome.webRequest.onBeforeRequest.addListener(callback, filter, ['blocking']);

But that would add a lot of complexity. I will leave that as a task for later, if necessary.

@toasted-nutbread toasted-nutbread merged commit 2f4adba into FooSoft:master Sep 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant