Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review and inject all DOM API and global dependencies #14003

Open
alexnj opened this issue May 13, 2022 · 4 comments
Open

Review and inject all DOM API and global dependencies #14003

alexnj opened this issue May 13, 2022 · 4 comments
Assignees
Labels

Comments

@alexnj
Copy link
Member

alexnj commented May 13, 2022

Similar to #14001, #6387 and #6283, there are more dependencies on DOM APIs that might make sense to inject, like this and this and more. This issue to track if we want to review and convert these into injected references in some generic way vs. whack-a-mole each time a conflict occurs?

@adamraine
Copy link
Member

adamraine commented May 14, 2022

Should we merge #13646 into this? I think saving Array.map + using isolated execution context in a few places might fix the site mentioned there.

@brendankenny
Copy link
Member

Should we merge #13646 into this?

Yeah, definitely seems like this should be step 1. We've been talking about doing that for years, just haven't gotten around to it. Gatherers should be safe from alterations by default unless they know they need access to the non-isolated space and can then opt out.

This issue to track if we want to review and convert these into injected references in some generic way vs. whack-a-mole each time a conflict occurs?

I don't think there's any general fix, unfortunately. There's always some site that will change something. We cache window.fetch, for instance, but a site could still override Response.prototype.json and break everything. The lengths we go to for performance.now, as another example of the lengths required to try to make things iron clad:

// Ensure the native `performance.now` is not overwritable.
const performance = window.performance;
const performanceNow = window.performance.now;
Object.defineProperty(performance, 'now', {
value: () => performanceNow.call(performance),
writable: false,
});

(if you ever want to confuse the DevTools console repl, just override Promise.prototype.then in it :)

On top of all this, caching doesn't happen in timespans because it only works on load of a new document.

ShadowRealms could help, but that will be a pain and would only help with a subset of DOM APIs (and is behind --harmony-shadow-realm for the foreseeable future).

So, default isolation seems like the best first step, and after that I think we just have to draw a line somewhere, dividing how much we're willing to take on for sites doing destructive things to their execution environment vs just replying to issues, sorry, looks like your sites overrides X, and Lighthouse can't complete that audit if it's overridden.

@brendankenny
Copy link
Member

From the eng sync today:

Follow up:

  • consider renaming the useIsolation option to noIsolation or runInPageContext or whatever for ergonomics of no option specified -> uses isolation

@adamraine
Copy link
Member

Merging #13646 into this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants