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

Remove Object.prototype.__proto__ #4341

Merged
merged 5 commits into from
Mar 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cli/js/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,12 @@ function bootstrapWasmCompilerRuntime(): void {
globalThis.onmessage = wasmCompilerOnMessage;
}

// Removes the `__proto__` for security reasons. This intentionally makes
// Deno non compliant with ECMA-262 Annex B.2.2.1
//
// eslint-disable-next-line @typescript-eslint/no-explicit-any
delete (Object.prototype as any).__proto__;

Object.defineProperties(globalThis, {
bootstrapWasmCompilerRuntime: {
value: bootstrapWasmCompilerRuntime,
Expand Down
6 changes: 6 additions & 0 deletions cli/js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
import { bootstrapMainRuntime } from "./runtime_main.ts";
import { bootstrapWorkerRuntime } from "./runtime_worker.ts";

// Removes the `__proto__` for security reasons. This intentionally makes
// Deno non compliant with ECMA-262 Annex B.2.2.1
//
// eslint-disable-next-line @typescript-eslint/no-explicit-any
delete (Object.prototype as any).__proto__;

Copy link
Member

Choose a reason for hiding this comment

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

👍

Object.defineProperties(globalThis, {
bootstrapMainRuntime: {
value: bootstrapMainRuntime,
Expand Down
5 changes: 5 additions & 0 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,11 @@ itest!(fix_js_imports {
output: "fix_js_imports.ts.out",
});

itest!(proto_exploit {
args: "run proto_exploit.js",
output: "proto_exploit.js.out",
});

#[test]
fn cafile_fetch() {
use deno::http_cache::url_to_filename;
Expand Down
5 changes: 5 additions & 0 deletions cli/tests/proto_exploit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const payload = `{ "__proto__": null }`;
const obj = {};
console.log("Before: " + obj);
Object.assign(obj, JSON.parse(payload));
console.log("After: " + obj);
2 changes: 2 additions & 0 deletions cli/tests/proto_exploit.js.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Before: [object Object]
After: [object Object]