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

refactor: introduce primordials #10939

Merged
merged 4 commits into from
Jul 2, 2021
Merged

Conversation

lucacasonato
Copy link
Member

This commit introduces primordials to deno_core. Primordials are a
frozen set of all intrinsic objects in the runtime. They are not
vulnerable to prototype pollution.

This commit just migrates deno_core to use primordials. Followup commits can
introduce primordials to the rest of the runtime.

Node has a eslint plugin that validates that all globals that are used in a
given script use primordials. We should consider adding a plugin for this to
dlint too. See https://github.com/nodejs/node/blob/master/tools/eslint-rules/prefer-primordials.js

Towards #10756

This commit introduces primordials to deno_core. Primordials are a
frozen set of all intrinsic objects in the runtime. They are not
vulnerable to prototype pollution.
@benjamingr
Copy link
Contributor

For what it's worth this is one of the ugliest things we have in the Node.js codebase and I'd caution against relying on primordials for security.

Please be very mindful when you consider taking this sort of burden upon yourself as a platform.

@lucacasonato
Copy link
Member Author

lucacasonato commented Jun 13, 2021

@benjamingr I don't disagree, but there are some web platform tests we can not get to pass without using primordials or re-architechting the entire system to use only native v8 bindins. Example of a failing test: https://staging.wpt.fyi/results/fetch/api/response/response-stream-with-broken-then.any.html?product=deno&product=chrome.

The issue is that the glue between our native code (the ops) and our runtime internals are implemented completely as JS. They need to behave as if they are native objects however, because that is what happens in the browser.

We do not intend to use primordials for security - all our access control is and still will be managed by native code, and we do now and will continue to consider all JS code untrusted.

@benjamingr
Copy link
Contributor

That's unfortunate, reasonable and fair.

As far as I know attempts to solve this (better) at the platform level were stopped - so I'm not sure what else you can do.

@@ -1732,7 +1732,8 @@ pub mod tests {

#[test]
fn test_heap_limits() {
let create_params = v8::Isolate::create_params().heap_limits(0, 20 * 1024);
let create_params =
v8::Isolate::create_params().heap_limits(0, 3 * 1024 * 1024);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: required startup heap limits have increased.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Increased a lot 😬

Copy link
Member Author

@lucacasonato lucacasonato Jun 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

V8 is really inefficient on first startup (because of the interpreter). You can see in the benchmarks that the snapshot (so baseline heap size of Deno) has not really increased.

@bartlomieju bartlomieju added this to the 1.12.0 milestone Jun 29, 2021
@bartlomieju
Copy link
Member

Node has a eslint plugin that validates that all globals that are used in a
given script use primordials. We should consider adding a plugin for this to
dlint too.

@magurotuna how involved would be adding a lint rule like this to dlint?

@bartlomieju
Copy link
Member

@bnoordhuis do you have any objections to this PR?

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lucacasonato could you later open an issue for tracking using primordials in extensions and runtime/js so we can share migration work?

Copy link
Member

@piscisaureus piscisaureus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@magurotuna
Copy link
Member

@bartlomieju

how involved would be adding a lint rule like this to dlint?

Looks like rather complicated but not impossible. Let me try to implement it :)

Copy link
Contributor

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and, for the record, I think it's a good idea.

@benjamingr
Copy link
Contributor

LGTM and, for the record, I think it's a good idea.

@bnoordhuis why?

@lucacasonato lucacasonato merged commit c9204c4 into denoland:main Jul 2, 2021
@lucacasonato lucacasonato deleted the primordials branch July 2, 2021 10:18
@lucacasonato lucacasonato mentioned this pull request Jul 2, 2021
67 tasks
@bnoordhuis
Copy link
Contributor

@benjamingr Robustness in the presence of monkey patching. Same reason it was a good idea in Node. :-)

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

Successfully merging this pull request may close these issues.

6 participants