Skip to content

Commit 01b8e7c

Browse files
verwaestCommit bot
authored andcommitted
Throw TypeError when reading global references through a JSProxy
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}
1 parent 879b21a commit 01b8e7c

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/messages.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ class CallSite {
269269
T(ProxyTrapReturnedFalsish, "'%' on proxy: trap returned falsish") \
270270
T(ProxyTrapReturnedFalsishFor, \
271271
"'%' on proxy: trap returned falsish for property '%'") \
272+
T(ReadGlobalReferenceThroughProxy, "Trying to access '%' through proxy") \
272273
T(RedefineDisallowed, "Cannot redefine property: %") \
273274
T(RedefineExternalArray, \
274275
"Cannot redefine a property of an object with external array elements") \

src/objects.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,13 @@ MaybeHandle<Object> JSProxy::GetProperty(Isolate* isolate,
828828
Handle<Name> name,
829829
Handle<Object> receiver,
830830
LanguageMode language_mode) {
831+
if (receiver->IsJSGlobalObject()) {
832+
THROW_NEW_ERROR(
833+
isolate,
834+
NewTypeError(MessageTemplate::kReadGlobalReferenceThroughProxy, name),
835+
Object);
836+
}
837+
831838
STACK_CHECK(MaybeHandle<Object>());
832839
Handle<Name> trap_name = isolate->factory()->get_string();
833840
// 1. Assert: IsPropertyKey(P) is true.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2015 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// Flags: --harmony-proxies
6+
7+
var failing_proxy = new Proxy({}, new Proxy({}, {
8+
get() { throw "No trap should fire" }}));
9+
10+
Object.setPrototypeOf(Object.prototype, failing_proxy);
11+
assertThrows(()=>a, TypeError);
12+
13+
Object.setPrototypeOf(this, failing_proxy);
14+
assertThrows(()=>a, TypeError);

0 commit comments

Comments
 (0)