-
Notifications
You must be signed in to change notification settings - Fork 67
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
Editorial: stricter notes in HostInitializeSyntheticRealm #315
Conversation
This PR is pointing to the opposite direction of the issue we are trying to address here: #261 (comment). Adding internal state will just add more debate. I intend to discuss the referred issue at the TC39 plenary next week to explore a prose that attends that issue and the current goals described in the text. Please hold until TC39 finds a proper path for this. |
That's why SES removes Math.random right? |
I think we should discuss this PR in more details @leobalter. I don't see a problem here, also, I don't see the relationship with #261 , maybe I'm missing something. I believe this PR is about the HTML integration, and what APIs to be included, and how to filter those APIs to avoid issues, from less strict to more strict, which I'm always supportive of. cc @erights |
This PR seems reasonable to me. It feels like it's about clarifying the wording for something that we all agree on meaning-wise, so we can iterate on it after Stage 3. |
After discussions from the previous TC39 meeting in May 2021 and the SES meeting in June 2nd, we decided to relax the restrictions of this host hook to only require the global object must have only have configurable properties. @Jack-Works I understand this is not the most desirable, and it took some consideration. The fact is: this single requirement still allows virtualization as user code can configure a new realm after instantiation and this can be done effectively as it already reflects reality from what we do today in iframes. Having a new Realms fully ready for virtualization would be nice, but this is just about reusing user land code and we could explore more of it in the more configurable Compartments API or through extensions for the Realms API once it's shipping. I'm merging this PR and updating the spec text after it. |
Did you mean "require the global object to only have configurable properties" ? |
Yes, thanks for catching the typo |
What about authorities? They're allowed now? |
They are not blocked by this proposal. We really want to avoid such kind of APIs, but that's limited to the user land responsibility. We believe that, with configuration of a new instantiated realm, user land code can prevent execution of APIs with such effects. This is also not opening any new precedent, as it already happens today through other forms to use a different Realm. The workaround won't be a new experience. |
I don't think that's reasonable. The last TC39 meeting was about if we're going to strengthen the limit but the results into the limits are almost removed? That makes this proposal closer and closer to an unaudited iframe and seems much less useful than before. |
What's the reason behind this decision of regression? Aren't we want to have a clean and safe environment? |
The goal of this proposal is having sandboxing for code execution in a virtualized context. This goal meets the needs my goal that includes running multiple code scripts in the same web application without generating noise with other scripts and the base platform script. I understand the Realms API makes us all see much longer on what the future can and should provide us as developers. I believe and support this goal should still be pursued, but gradually. This proposal is not a full resolution of everything we aim for sandboxing. Talk about SES and you'll find much more in the plans. The current Realms API is only one step, there are many more we want to invest. Rome wasn't built in a day. Having an ordinary object global with all properties configurable makes this proposal already night and day different than iframes. Add the fact you would also be able to use it seamlessly in browsers, node, and any other platforms. Add the fact you can inject code both by string evaluation and through loading modules. This proposal is still powerful and unlocks a lot. This also unlocks opportunities for all of us to identify and capture another pain points related to using Realms. At some point, we would be able to explore the cost of configuring every new instantiated realm, removing unwanted properties. Maybe a better opportunity would be exploring what it means to proxy every global property for the virtualization, and finding a way to improve proxies. This is a speculation, but it's not the focus of this current proposal. Landing the current proposal to ECMAScript is not the end of the road, but an opportunity to explore what comes next. I'd love to get all of this energy you bring to TC39 and translate it in all the work we can do together to further improve. For now, we need to advance this one step. I'd really appreciate if I can count on you! |
But why gradually when you can make things right on the first try? |
Being able to resolve use cases makes things right. Expanding coverage to a better featured platform is the long term. We need to work everything with implementers and many others TC39 delegates who might not have specific usage for Realms. As I said, Rome wasn't built in a day. |
As a champion for SES, I can say it’s consistent with both the design of
the web and the design of SES that there be a Realm that the web and
vendors are free to extend and evolve as long as it remains possible to
shim a “lockdown” function that creates a “locked down realm”. This is
consistent with the design of SES which already accounts for the
distinction between a “function constructor” and a “lockded down function
constructor” or “compartment” (a module loader) and a “lockded down
compartment” (a module loader and an isolation boundary).
It stands to reason that the SES shim, by way of example, would be able to
create a confined Realm with the ability to create new confined Realms by
presenting only the locked-down Realm constructor to locked-down Realms. A
locked-down Realm can be created from any Realm and running the SES shim’s
lockdown in that Realm. Currently, the SES shim implements an emulation of
the Compartment module loader, which is sufficient to deny access to the
incubator realm’s module map, even through dynamic import.
To be able to shim Lockdown, it is sufficient for a “Realm” to guarantee
that every property of the global scope be configurable (and by virtue of
being defined as a regular object and expressly not a Proxy or host object,
deletable).
For any Lockdown shim to remain future compatible (particularly SES shim),
we also rely on the invariant that the language introduces no further
hidden intrinsics: intrinsics that are not discoverable by the transitive
closure of properties of the globalThis.
It is my hope that Jack finds this way of thinking compelling!
I presented this topic at the SES meeting with:
- slides
https://docs.google.com/presentation/d/1lVrxWFBMQUVVseyAW06hZU6pwI1Qg1LC_R7Lwi4b85s/
- recording https://youtu.be/V6k50joKxxk
|
Ok, I understand your point now. If we're not treating it as the lockdown realm (Note I didn't ask to freeze all primordials so my preferred version isn't a "lockdown" realm) I think it's ok. My last two defense: Conservatism
This is BN's opinion on Symbol as WeakMap key on May 2021. This argument also applies to the Realm (or maybe we can add options bag in the future?). Lockdown lib complexityThe lockdown lib must replace the Realms constructor to avoid the subrealm regain the authority. |
Yes! The idea is exploring and identifying all the pain points and using the current examples directly based on what we get as the implemented Realms. I believe an options bag is pretty doable as a follow up and it's something I'm looking forward to invest time investigating each opportunity of improvements.
The subclassing part is right, but I'm not sure if I understand the CSP issue here, I'll review this throughout the day see if I can give you a better answer. For what I understand there isn't any modification on CSP is applied here. |
Imagine there is a page with a very strict CSP constraint. The lockdown library was injected via WebView API by the native, or via a WebExtension (https://www.w3.org/TR/CSP3/#extensions), they will be able to do that. But when the lockdown lib tries to execute itself in the replaced realm constructor, it will fail due to the CSP. |
My take on this, which has been discussed extensibly over the years in SES forum. If CSP restricts eval (that can be detected), if they restrict modules, a blob url must be allowed in order to make it work. But that is not different from what you have to do today to achieve any of these. Basically, you have 3 things to be patched:
This is not hard, I can probably put together an example of this. Of course, for node, things are different, as it should be, from environment to environment, just like it is today. I will say that this it an improvement from where we are today by providing the ability to modify the environment entirely, which is not possible today. |
The current version allows the host to create a mutation of values that not shared across different realms. But IMO that also violates SES requirements.
Example:
I changed that to: