-
Notifications
You must be signed in to change notification settings - Fork 80
feat(harden): Introduce @endo/harden #3008
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
Draft
kriskowal
wants to merge
37
commits into
master
Choose a base branch
from
kriskowal-endo-harden-adopt-shallow
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes: #2978
Description
This change introduces an
@endo/hardenpackage that allows packages to be written for use in a JS or a HardenedJS environment without modification. The@endo/hardenmodule provides a behavior that depends on the environment and packaging conditions.Without any packaging conditions, in a HardenedJS environment,
@endo/hardenprovides the environment’s “volume freezing”harden, meaning that it freezes the closure over both dimensions: transitive properties and prototypes.Also without any packaging conditions, if the environment does not provide a
harden,@endo/hardenprovides a “surface freezing”harden, meaning that it freezes the closure over only the one dimension: properties. This provides a modicum of immutability without interfering with shims or other mutations to shared, intrinsic prototypes.With the
hardenedcondition (node -C hardened,bundle-source -C hardened),@endo/hardenwill not retain an implementation ofhardenand will assert thathardenexisted asObject[Symbol.for('harden')]orglobalThis.hardenin the environment and vend out thatharden. This is useful to minimize the size of bundles that can safely presume that they will run in a HardenedJS environment.With the
noop-hardencondition (node -C noop-harden),@endo/hardenwill provide a version ofhardenthat returns its argument unaltered.With these new modes, we expect to deprecate the
lockdownoption for"unsafe"hardenTamingwhich goes further and replacesisExtensible,isFrozen, andisSealedwith versions that misreporttruefor extensible, unfrozen, or unsealed objects respectively. We hope that the new default behavior of surface hardening will suffice, but we leave thenoop-hardencondition as an option since that should have performance parity with unsafe harden taming for environments that need it.As a side-effect, every kind of
hardenwill install itself on first use atObject[Symbol.for('harden')]as a non-configurable property such that the first@endo/hardenimplementation used wins the race to define the hardening behavior of the realm. SES will install the same property at time oflockdown, but if it loses the race, will throw an exception indicating that the realm cannot be locked down because of unsafe usage ofhardenbeforelockdown, and render up the stack of the first use for diagnostic purposes.Security Considerations
The
@endo/hardenprovides a new mode of usage that is less safe thanlockdownfor environments in whichlockdownis not practical. We do not expect safety to regress in lockdown environments as a consequence.This change strengthens one safety guarantee: going forward, hardened modules using
@endo/hardenwill not be vulnerable to hosts that endow a compartment with a weakened version ofharden, because@endo/hardenalways favors theObject[Symbol.for('harden')]enshrined on a shared intrinsic hardened bylockdown.Scaling Considerations
Adopting
@endo/hardenwill increase the size of bundles, and since this change adopts@endo/hardenthroughout the Endo stack, this bundle size increase may become problematic for systems close to their bundle size limits. We provide the bundler conditionhardenedto mitigate this problem.Documentation Considerations
hardenedbundle condition to mitigate the bundle size increase.Testing Considerations
This change adds configurations to
sesAvaConfigswhere adopting@endo/hardenallows those packages to be used in more configurations. The salient configuration Endo with shims installed only, without calling Lockdown, in the cases where packages continue to rely on Assert or Eventual Send. We hope in time to test in the Base configuration, without any shims. Some packages are able to adopt the No-op mode of harden and are accordingly tested in that mode.Compatibility Considerations
This change is additive apart from the expected increase in bundle size, for which we provide a mitigation.
Upgrade Considerations
None.