Skip to content
This repository was archived by the owner on Jul 18, 2018. It is now read-only.

Commit 09b22d9

Browse files
yuki3Commit Bot
authored andcommitted
v8binding: Adds 'then' as one of special cross origin properties.
According to the discussion (and request) at whatwg/dom#536 this patch adds 'then' as a cross origin accessible property returning 'undefined'. HTML 7.2.3.3 CrossOriginGetOwnPropertyHelper ( O, P ) https://html.spec.whatwg.org/multipage/browsers.html#crossorigingetownpropertyhelper-(-o,-p-) is not yet updated, but it should be quite soon. The proposed change is at whatwg/html#3242 Bug: Change-Id: Icb72ba01ccf8eabaad607b61805411d1b4845f86 Reviewed-on: https://chromium-review.googlesource.com/779319 Reviewed-by: Kentaro Hara <haraken@chromium.org> Commit-Queue: Yuki Shiino <yukishiino@chromium.org> Cr-Commit-Position: refs/heads/master@{#518158}
1 parent 3b59ff7 commit 09b22d9

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<meta charset=utf-8>
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<iframe id="cross-origin-iframe" src="https://localhost:8000/security/resources/blank.html"></iframe>
6+
<!--
7+
HTML 7.2.3.3 CrossOriginGetOwnPropertyHelper ( O, P )
8+
https://html.spec.whatwg.org/multipage/browsers.html#crossorigingetownpropertyhelper-(-o,-p-)
9+
step 3. If P is "then", @@toStringTag, @@hasInstance, or @@isConcatSpreadable, then return PropertyDescriptor{ [[Value]]: undefined, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
10+
11+
Test that window.then and location.then return undefined in case of cross origin.
12+
-->
13+
<script>
14+
onload = function() {
15+
16+
test(function() {
17+
let iframe = document.getElementById('cross-origin-iframe');
18+
let w = iframe.contentWindow; // cross origin window
19+
assert_throws('SecurityError', function() { w.document; }, "The window 'w' must be cross origin.");
20+
assert_equals(w.then, undefined, "The value of 'then' must be undefined.");
21+
assert_equals(w.location.then, undefined, "The value of 'location.then' must be undefined.");
22+
23+
}, "Test that 'then' on cross origin window and location returns undefined.");
24+
25+
test(function() {
26+
let iframe = document.getElementById('cross-origin-iframe');
27+
let w = iframe.contentWindow; // cross origin window
28+
assert_throws('SecurityError', function() { w.document; }, "The window 'w' must be cross origin.");
29+
30+
// Make a child browsing context named 'then', which shouldn't be shadowed.
31+
let child_then_frame = document.createElement('iframe');
32+
child_then_frame.name = 'then';
33+
child_then_frame.src = 'https://localhost:8000/security/resources/blank.html';
34+
document.body.appendChild(child_then_frame);
35+
36+
assert_equals(typeof w.then, 'object', "The value of 'then' must be a WindowProxy.");
37+
assert_equals(w.location.then, undefined, "The value of 'location.then' must be undefined.");
38+
}, "Test that a child browsing context named 'then' is not shadowed.");
39+
40+
};
41+
</script>

third_party/WebKit/Source/bindings/core/v8/custom/V8WindowCustom.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,17 @@ void V8Window::namedPropertyGetterCustom(
346346
if (!BindingSecurity::ShouldAllowAccessTo(
347347
CurrentDOMWindow(info.GetIsolate()), window,
348348
BindingSecurity::ErrorReportOption::kDoNotReport)) {
349+
// HTML 7.2.3.3 CrossOriginGetOwnPropertyHelper ( O, P )
350+
// https://html.spec.whatwg.org/multipage/browsers.html#crossorigingetownpropertyhelper-(-o,-p-)
351+
// step 3. If P is "then", @@toStringTag, @@hasInstance, or
352+
// @@isConcatSpreadable, then return PropertyDescriptor{ [[Value]]:
353+
// undefined, [[Writable]]: false, [[Enumerable]]: false,
354+
// [[Configurable]]: true }.
355+
if (name == "then") {
356+
V8SetReturnValueFast(info, v8::Undefined(info.GetIsolate()), window);
357+
return;
358+
}
359+
349360
BindingSecurity::FailedAccessCheckFor(
350361
info.GetIsolate(), window->GetWrapperTypeInfo(), info.Holder());
351362
return;

third_party/WebKit/Source/bindings/templates/interface_base.cpp.tmpl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,17 @@ void {{v8_class_or_partial}}::crossOriginNamedGetter(v8::Local<v8::Name> name, c
282282
{{cpp_class}}V8Internal::namedPropertyGetter(propertyName, info);
283283
{% endif %}
284284
{% else %}
285+
// HTML 7.2.3.3 CrossOriginGetOwnPropertyHelper ( O, P )
286+
// https://html.spec.whatwg.org/multipage/browsers.html#crossorigingetownpropertyhelper-(-o,-p-)
287+
// step 3. If P is "then", @@toStringTag, @@hasInstance, or
288+
// @@isConcatSpreadable, then return PropertyDescriptor{ [[Value]]:
289+
// undefined, [[Writable]]: false, [[Enumerable]]: false,
290+
// [[Configurable]]: true }.
291+
if (propertyName == "then") {
292+
V8SetReturnValue(info, v8::Undefined(info.GetIsolate()));
293+
return;
294+
}
295+
285296
BindingSecurity::FailedAccessCheckFor(
286297
info.GetIsolate(),
287298
&{{v8_class}}::wrapperTypeInfo,

third_party/WebKit/Source/bindings/tests/results/core/V8TestInterfaceCheckSecurity.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,17 @@ void V8TestInterfaceCheckSecurity::crossOriginNamedGetter(v8::Local<v8::Name> na
492492
}
493493
}
494494

495+
// HTML 7.2.3.3 CrossOriginGetOwnPropertyHelper ( O, P )
496+
// https://html.spec.whatwg.org/multipage/browsers.html#crossorigingetownpropertyhelper-(-o,-p-)
497+
// step 3. If P is "then", @@toStringTag, @@hasInstance, or
498+
// @@isConcatSpreadable, then return PropertyDescriptor{ [[Value]]:
499+
// undefined, [[Writable]]: false, [[Enumerable]]: false,
500+
// [[Configurable]]: true }.
501+
if (propertyName == "then") {
502+
V8SetReturnValue(info, v8::Undefined(info.GetIsolate()));
503+
return;
504+
}
505+
495506
BindingSecurity::FailedAccessCheckFor(
496507
info.GetIsolate(),
497508
&V8TestInterfaceCheckSecurity::wrapperTypeInfo,

0 commit comments

Comments
 (0)