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

HTML: getSVGDocument() / contentDocument #20432

Merged
merged 5 commits into from
Dec 13, 2019
Merged

HTML: getSVGDocument() / contentDocument #20432

merged 5 commits into from
Dec 13, 2019

Conversation

annevk
Copy link
Member

@annevk annevk commented Nov 25, 2019

annevk added a commit to whatwg/html that referenced this pull request Nov 25, 2019
Additionally, make content document (also used by contentDocument) perform the same origin-domain comparison on the two documents involved.

Tests: web-platform-tests/wpt#20432.

Fixes #5094.
@annevk annevk requested a review from zcorpan December 9, 2019 08:57
@zcorpan zcorpan assigned domenic and unassigned zcorpan Dec 9, 2019
@zcorpan
Copy link
Member

zcorpan commented Dec 9, 2019

Reassigning to @domenic since he's reviewing whatwg/html#5109

@domenic
Copy link
Member

domenic commented Dec 9, 2019

This needs a test for the change mentioned at https://github.com/whatwg/html/pull/5109/files#r353452968.

In particular we want:

  1. A situation where the current settings object is cross-origin-domain with the nested BC's active document, but container's node document is same-origin-domain. Before the change this would return null; now it returns the document.

  2. A situation where the current settings object is same-origin-domain with the nested BC's active document, but container's node document is cross-origin-domain. Before the change this would return the document; now it returns null.

Consider a.example.com which embeds frame1 = a.example.com, frame2 = a.example.com

(1) should be doable with something like: Grab the getSVGDocument function from frame2. Then, change frame2's document.domain to "example.com". Now, call frame2GetSVGDocument.call(frame1). At that time the current settings object is frame2 (which is COD with frame1) but the container's node document is same-origin-domain (both are a.example.com)

(2) should be doable with something like: Grab getSVGDocument from frame2. Then, change frame1 and frame2's document.domain to "example.com". Now, call frame2GetSVGDocument.call(frame2). At that time the current settings object is frame2 (which is SOD with frame1) but the container's node document is COD (since the outer frame hasn't changed document.domain).

@annevk
Copy link
Member Author

annevk commented Dec 10, 2019

The current tests already test the case where the SVG's container and the SVG are same origin and the current settings object is cross origin-domain and that doesn't appear to affect things one bit.

(I'm actually wondering how the current tests are not running into "perform a security check" now. Maybe nobody performs that for non-Window-non-Location objects these days.)

annevk added a commit to whatwg/html that referenced this pull request Dec 10, 2019
These days all implementations only have security checks on a couple of objects. Firefox used to have cross-origin object wrapper, but those are no longer web observable.

Tests: html/browsers/origin/cross-origin-objects/cross-origin-objects.html and web-platform-tests/wpt#20432.
annevk added a commit to whatwg/html that referenced this pull request Dec 11, 2019
These days all implementations only have security checks on a couple of objects. Firefox used to have cross-origin object wrapper, but those are no longer web observable.

Tests: html/browsers/origin/cross-origin-objects/cross-origin-objects.html and web-platform-tests/wpt#20432.
@annevk
Copy link
Member Author

annevk commented Dec 12, 2019

Added that other test, results are as expected. Current settings object is not involved.

…e origin-domain with the embedder document, but both cross origin-domain with the SVG
Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

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

Looks good but please add comments similar to what I suggest, to explain why the expectations are as they are. These kind of tests are really hard to debug or maintain otherwise.

possibleDocument = instance[api]();
} else {
possibleDocument = instance[api];
}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: this could be simpler as

const possibleDocument = api === "getSVGDocument" ? instance[api]() : instance[api];

}
frame.onload = t.step_func_done(() => {
const instances = Object.keys(elements).map(element => frame.contentDocument.querySelector(element));
instances.forEach(instance => assert_apis(instance));
Copy link
Member

Choose a reason for hiding this comment

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

Suggest adding a comment like "Everything is same-origin-domain; this should definitely work"

instances.forEach(instance => assert_apis(instance));
document.domain = document.domain;
assert_equals(frame.contentDocument, null);
instances.forEach(instance => assert_apis(instance));
Copy link
Member

Choose a reason for hiding this comment

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

Suggest adding a comment like "Current settings object is now cross-origin domain, but container node document and nested BC node document are still same-origin domain, so all the APIs should still work".

}
frame.onload = t.step_func_done(() => {
const instances = Object.keys(elements).map(element => frame.contentDocument.querySelector(element));
instances.forEach(instance => assert_apis(instance));
Copy link
Member

Choose a reason for hiding this comment

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

Siggest adding a comment like "Everything is same-origin domain; this should definitely work"

const svgDocument = element_to_document(instance);
svgDocument.domain = svgDocument.domain;
});
instances.forEach(instance => assert_apis(instance, true));
Copy link
Member

Choose a reason for hiding this comment

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

Suggest adding a comment like "nested BC node document is now cross-origin domain with container BC's active document and current settings object, so we expect the APIs to start returning null"

instances.forEach(instance => assert_apis(instance, true));
document.domain = document.domain;
assert_equals(frame.contentDocument, null);
instances.forEach(instance => assert_apis(instance, true));
Copy link
Member

Choose a reason for hiding this comment

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

Suggest adding a comment like "nested BC node document is now same-origin domain with the current settings object, but still cross-origin domain with the container BC's node document, so the APIs should still return null"

let attr = "src";
if (name === "object") {
attr = "data";
}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: this could be simpler as

const attr = name === "object" ? "data" : "src";

} else {
possibleDocument = instance[api];
}
assert_not_equals(possibleDocument, null, `${name}[${api}]`);
Copy link
Member

Choose a reason for hiding this comment

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

Nit:

Suggested change
assert_not_equals(possibleDocument, null, `${name}[${api}]`);
assert_not_equals(possibleDocument, null, `${name}.${api}`);

(here and in the other file)

annevk added a commit to whatwg/html that referenced this pull request Dec 13, 2019
Additionally, make content document (also used by contentDocument) perform the same origin-domain comparison on the two documents involved rather than involve the current settings object.

Tests: web-platform-tests/wpt#20432.

Fixes #5094.
@annevk annevk merged commit b5f3eaf into master Dec 13, 2019
@annevk annevk deleted the annevk/getSVGDocument branch December 13, 2019 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants