Skip to content

Commit 37409ee

Browse files
committed
Test TT is not enforced when taking an element out of a TT realm to a non-TT realm.
See discussions at w3c/trusted-types#425 (comment).
1 parent affa7c3 commit 37409ee

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
</head>
8+
<body>
9+
<script>
10+
const iframePolicy = trustedTypes.createPolicy("iframePolicy", {
11+
createHTML: (s) => s,
12+
});
13+
14+
const iframe_srcdoc = `
15+
<!DOCTYPE html>
16+
<head>
17+
<meta charset="utf-8">
18+
<meta
19+
http-equiv="Content-Security-Policy"
20+
content="require-trusted-types-for 'script';"
21+
/>
22+
</head>
23+
<body>
24+
<div id="nonSVGTestElements">
25+
<iframe id="iframe-srcdoc" srcdoc="v"></iframe>
26+
<script id="script-src" src="v"><\/script>
27+
</div>
28+
<svg id="svgTestElements">
29+
<script id="script-href" href="v"><\/script>
30+
<script id="script-xlinkhref" xlink:href="v"><\/script>
31+
</svg>
32+
</body>`;
33+
34+
// TODO: Add xlink:href case. It fails getting testAttr in the test script below.
35+
const testCases = ["iframe-srcdoc", "script-src", "script-href"];
36+
37+
const sourceFrame = document.createElement("iframe");
38+
sourceFrame.srcdoc = iframePolicy.createHTML(
39+
iframe_srcdoc
40+
);
41+
document.body.append(sourceFrame);
42+
43+
async_test(
44+
(t) => {
45+
t.add_cleanup(() => {
46+
sourceFrame.remove();
47+
});
48+
49+
sourceFrame.addEventListener(
50+
"load",
51+
t.step_func_done(() => {
52+
testCases.forEach(c => {
53+
const aTestElement = sourceFrame.contentWindow.document.getElementById(c);
54+
const testAttr = aTestElement.attributes[1];
55+
const sourceElement =
56+
sourceFrame.contentDocument.body.querySelector(
57+
aTestElement.localName
58+
);
59+
const sourceAttr = sourceElement.getAttributeNode(
60+
testAttr.name
61+
);
62+
sourceElement.removeAttributeNode(sourceAttr);
63+
// Now `sourceElement`'s node document's global belongs to a non TT-realm.
64+
document.body.append(sourceElement);
65+
sourceElement.setAttributeNode(sourceAttr);
66+
sourceElement.setAttributeNS(sourceAttr.namespaceURI, sourceAttr.name, sourceAttr.value);
67+
let attr_node = sourceElement.getAttributeNodeNS(sourceAttr.namespaceURI, sourceAttr.name);
68+
assert_equals(attr_node.value + "", "v");
69+
});
70+
})
71+
);
72+
}, `setAttribute and setAttributeNode are not is no longer enforced while being taken out to a non-TT realm.`);
73+
</script>
74+
</body>
75+
</html>

0 commit comments

Comments
 (0)