-
Notifications
You must be signed in to change notification settings - Fork 74
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
feat(ses): Vetted shims #1705
feat(ses): Vetted shims #1705
Conversation
Developer log (draft): I’m attempting to make it clearer that In the course of doing this, it became clear that the
|
b049ea5
to
c619f09
Compare
I managed to getting vetted shims implemented without refactoring ambient types. Or rather, I managed to keep that work out of this pull request for purposes of limiting the scope of review and will submit that cleanup separately. |
For reviewers: I’ve created an initial commit that renames |
/** getThis returns globalThis in sloppy mode or undefined in strict mode. */ | ||
function getThis() { | ||
return this; | ||
} | ||
|
||
if (getThis()) { | ||
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_NO_SLOPPY.md | ||
throw TypeError(`SES failed to initialize, sloppy mode (SES_NO_SLOPPY)`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moves to a new assert-sloppy-mode.js
, as imported by lockdown-shim.js
to ensure it runs first and fails fast.
|
||
assign(globalThis, { | ||
lockdown, | ||
Compartment, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moves to compartment-shim.js
); | ||
|
||
assign(globalThis, { | ||
lockdown, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moves to lockdown-shim.js
assign(globalThis, { | ||
lockdown, | ||
Compartment, | ||
assert, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moves to assert-shim.js
const markVirtualizedNativeFunction = tameFunctionToString(); | ||
|
||
const Compartment = makeCompartmentConstructor( | ||
makeCompartmentConstructor, | ||
getGlobalIntrinsics(globalThis), | ||
markVirtualizedNativeFunction, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moves to compartment-shim.js
packages/ses/src/lockdown-shim.js
Outdated
globalThis.repairIntrinsics = options => { | ||
const hardenIntrinsics = repairIntrinsics(options); | ||
// Reveal hardenIntrinsics after repairs. | ||
globalThis.hardenIntrinsics = () => { | ||
// Reveal harden after hardenIntrinsics. | ||
// Harden is dangerous before hardenIntrinsics because hardening just | ||
// about anything will inadvertently render intrinsics irreparable. | ||
// Also, for modules that must work both before or after lockdown (code | ||
// that is portable between JS and SES), the existence of harden in global | ||
// scope signals whether such code should attempt to use harden in the | ||
// defense of its own API. | ||
// @ts-ignore harden not yet recognized on globalThis. | ||
globalThis.harden = hardenIntrinsics(); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve moved all of the globalThis
assignment behaviors into the shim to decontaminate the non-shim modules.
So, note that the global repairIntrinsics
doesn’t return hardenIntrinsics
and the global hardenIntrinsics
does not return harden
, but the internal versions perform this cascade.
hardenIntrinsics
did not previously return harden
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should update docs too right (mb better as follow-up)
- https://github.com/endojs/endo/blob/master/packages/ses/docs/guide.md
- https://github.com/endojs/endo/blob/master/packages/ses/docs/reference.md
so lockdown
and harden
relevant parts then add repair
section
can prob reuse bits from the well-written issue description too
db4a42e
to
fb969cb
Compare
I’ve added a commit with documentation changes and the update for the change log. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just doc comments so far. rest coming but will take longer.
hardenIntrinsics(); | ||
``` | ||
|
||
And, an application that choses to call these also has the option of running |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And, an application that choses to call these also has the option of running | |
An application that choses to call these also has the option of running |
I'll do things like a jarring initial "And, " when it adds enough meaning to be worth it. I don't think it is here.
packages/ses/docs/guide.md
Outdated
The globals in a child compartment include the shared intrinsics including | ||
`harden` and a batch of evaluators that run programs that will also be | ||
confined to the compartment including `eval`, `Function`, and `Compartment` | ||
itself. | ||
Compartments also load and confine modules. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to be explicit that this is the post-repairIntrinsics
behavior of Compartment
. In our system as it is now, or as it is as of this PR, what is the status of Compartment
before repairIntrinsics
? I'm probably happy with any answer for now, since I only really care about after repairIntrinsics
. But we should be explicit somewhere. If we are explicit elsewhere, can we link to it from here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compartment
exists before repairIntrinsics
and the only current difference is that the intrinsics are not hardened. Compartments
constructed before repairIntrinsics
do not guarantee confinement even after repairIntrinsics
.
packages/ses/docs/reference.md
Outdated
```js | ||
import './non-ses-code-before-lockdown.js'; | ||
import './ses-repair-intrinsics.js'; // calls repairIntrinsics. | ||
import './vetted-shim.js'; | ||
import './ses-harden-intrinsics.js'; // calls repairIntrinsics. | ||
import './ses-code-after-lockdown.js'; | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is even more important that this example import sequence appear in the guide. This is the use pattern we should generally encourage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about https://github.com/endojs/endo/blob/master/packages/ses/docs/lockdown.md ?
Should "Lockdown options" be renamed? What about LOCKDOWN_*
environment variables?
IMO the env vars do not need to be renamed. The doc should at least be clear about what these options mean in the new world.
In the type definition, I took the liberty of renaming |
Question for reviewers: do we need to tackle making On the question of necessity, a vetted shim could be divided into layers that run before and after I also don’t think repairing but not hardening intrinsics is coherent, but I might be forgetting something. |
How we want to bridge If we already have an issue where we're discussing that open design issue, we should link to it. |
Agreed with @erights. Let's not introduce some queuing behavior for To be clear: a world where shims explicitly |
Also fine with me. Even better because the diagnostic can help set expectations. My favorite word for such messages is "yet" ;) |
OTOH, absence would make feature testing pleasant. I'm ok either way. |
I’m settling on the current state: presence of |
Thank you! I was reviewing the overall differences until I got to one of those. I'm surprised that github diff loses the mv behavior for the overall diffs, but it does. Your separation is a lifesaver. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!!!!
I love that we can get this into the next endo release. Awesome!
@@ -36,6 +36,10 @@ export interface LockdownOptions { | |||
__hardenTaming__?: 'safe' | 'unsafe'; | |||
} | |||
|
|||
export type LockdownOptions = RepairOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please comment that we preserve LockdownOptions
only for legacy compat. Perhaps deprecate?
0069174
to
76787e7
Compare
- from (dist): endojs/endo#1705 - eslintignore unneeded since cjs not js
Closes #422
This change separates out the internal phases of
lockdown
:repairIntrinsics()
andhardenIntrinsics()
.