Skip to content

Commit

Permalink
Throw TypeError when reading global references through a JSProxy
Browse files Browse the repository at this point in the history
Allowing global references to be read through a proxy results in cross-origin information leaks. The ES6 spec currently does not mitigate this in any way. This CL adds a workaround that's easy for V8: throw whenever an unresolved reference would result in a proxy trap to be fired. I'm landing this so we can move forwards with staging proxies without putting users of --harmony at risk.

BUG=chromium:399951
LOG=n

Review URL: https://codereview.chromium.org/1529303003

Cr-Commit-Position: refs/heads/master@{#32949}
  • Loading branch information
verwaest authored and Commit bot committed Dec 17, 2015
1 parent 879b21a commit 01b8e7c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ class CallSite {
T(ProxyTrapReturnedFalsish, "'%' on proxy: trap returned falsish") \
T(ProxyTrapReturnedFalsishFor, \
"'%' on proxy: trap returned falsish for property '%'") \
T(ReadGlobalReferenceThroughProxy, "Trying to access '%' through proxy") \
T(RedefineDisallowed, "Cannot redefine property: %") \
T(RedefineExternalArray, \
"Cannot redefine a property of an object with external array elements") \
Expand Down
7 changes: 7 additions & 0 deletions src/objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,13 @@ MaybeHandle<Object> JSProxy::GetProperty(Isolate* isolate,
Handle<Name> name,
Handle<Object> receiver,
LanguageMode language_mode) {
if (receiver->IsJSGlobalObject()) {
THROW_NEW_ERROR(
isolate,
NewTypeError(MessageTemplate::kReadGlobalReferenceThroughProxy, name),
Object);
}

STACK_CHECK(MaybeHandle<Object>());
Handle<Name> trap_name = isolate->factory()->get_string();
// 1. Assert: IsPropertyKey(P) is true.
Expand Down
14 changes: 14 additions & 0 deletions test/mjsunit/harmony/proxies-global-reference.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --harmony-proxies

var failing_proxy = new Proxy({}, new Proxy({}, {
get() { throw "No trap should fire" }}));

Object.setPrototypeOf(Object.prototype, failing_proxy);
assertThrows(()=>a, TypeError);

Object.setPrototypeOf(this, failing_proxy);
assertThrows(()=>a, TypeError);

0 comments on commit 01b8e7c

Please sign in to comment.