Attachment #785657: Tests for Bug 886262: HTML <object>s do not inherit sandbox flags from their parents. for bug #886262

View | Details | Raw Unified | Return to bug 886262
Collapse All | Expand All

(-)a/content/html/content/test/Makefile.in (+7 lines)
Line     Link Here 
 Lines 283-298   MOCHITEST_FILES = \ Link Here 
283
		file_iframe_sandbox_a_if5.html \
283
		file_iframe_sandbox_a_if5.html \
284
		file_iframe_sandbox_a_if6.html \
284
		file_iframe_sandbox_a_if6.html \
285
		file_iframe_sandbox_a_if7.html \
285
		file_iframe_sandbox_a_if7.html \
286
		file_iframe_sandbox_a_if8.html \
286
		file_iframe_sandbox_a_if8.html \
287
		file_iframe_sandbox_a_if9.html \
287
		file_iframe_sandbox_a_if9.html \
288
		file_iframe_sandbox_a_if10.html \
288
		file_iframe_sandbox_a_if10.html \
289
		file_iframe_sandbox_a_if11.html \
289
		file_iframe_sandbox_a_if11.html \
290
		file_iframe_sandbox_a_if12.html \
290
		file_iframe_sandbox_a_if12.html \
291
		file_iframe_sandbox_a_if13.html \
292
		file_iframe_sandbox_a_if14.html \
293
		file_iframe_sandbox_a_if15.html \
294
		file_iframe_sandbox_a_if16.html \
295
		file_iframe_sandbox_a_if17.html \
296
		file_iframe_sandbox_a_if18.html \
297
		file_iframe_sandbox_a_if19.html \
291
		test_iframe_sandbox_same_origin.html \
298
		test_iframe_sandbox_same_origin.html \
292
		file_iframe_sandbox_b_if1.html \
299
		file_iframe_sandbox_b_if1.html \
293
		file_iframe_sandbox_b_if2.html \
300
		file_iframe_sandbox_b_if2.html \
294
		file_iframe_sandbox_b_if3.html \
301
		file_iframe_sandbox_b_if3.html \
295
		test_iframe_sandbox_general.html \
302
		test_iframe_sandbox_general.html \
296
		file_iframe_sandbox_c_if1.html \
303
		file_iframe_sandbox_c_if1.html \
297
		file_iframe_sandbox_c_if2.html \
304
		file_iframe_sandbox_c_if2.html \
298
		file_iframe_sandbox_c_if3.html \
305
		file_iframe_sandbox_c_if3.html \
(-)a/content/html/content/test/file_iframe_sandbox_a_if10.html (+1 lines)
Line     Link Here 
 Lines 2-11    Link Here 
2
<html>
2
<html>
3
<head>
3
<head>
4
  <meta charset="utf-8">
4
  <meta charset="utf-8">
5
  <title>Test for Bug 341604</title>
5
  <title>Test for Bug 341604</title>
6
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
6
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
7
</head>
7
</head>
8
<frameset>
8
<frameset>
9
  <frame src="file_iframe_sandbox_a_if11.html">
9
  <frame src="file_iframe_sandbox_a_if11.html">
10
  <frame src="file_iframe_sandbox_a_if16.html">
10
</frameset>
11
</frameset>
11
</html>
12
</html>
(-)a/content/html/content/test/file_iframe_sandbox_a_if11.html (-1 / +1 lines)
Line     Link Here 
 Lines 13-23    Link Here 
13
        window.parent.parent.postMessage({ok: true, desc: "a frame inside a sandboxed iframe is not same origin with the iframe's parent"}, "*");
13
        window.parent.parent.postMessage({ok: true, desc: "a frame inside a sandboxed iframe is not same origin with the iframe's parent"}, "*");
14
      }
14
      }
15
     }
15
     }
16
  </script>
16
  </script>
17
</head>
17
</head>
18
<frameset>
18
<frameset>
19
  <frame onload='doStuff()' src="file_iframe_sandbox_a_if12.html">
19
  <frame onload='doStuff()' src="file_iframe_sandbox_a_if12.html">
20
</frameset>
20
</frameset>
21
I'm a &lt;frame&gt; inside an iframe which is sandboxed with 'allow-scripts'
21
I'm a &lt;frame&gt; inside an iframe which is sandboxed with 'allow-scripts allow-forms'
22
</html>
22
</html>
23
23
(-)a/content/html/content/test/file_iframe_sandbox_a_if12.html (-1 / +1 lines)
Line     Link Here 
 Lines 12-23   function doStuff() { Link Here 
12
  }
12
  }
13
  catch (e) {
13
  catch (e) {
14
    dump("caught some e if12\n");
14
    dump("caught some e if12\n");
15
    window.parent.parent.parent.postMessage({ok: true, desc: "a frame inside a frame inside a sandboxed iframe is not same origin with the iframe's parent"}, "*");
15
    window.parent.parent.parent.postMessage({ok: true, desc: "a frame inside a frame inside a sandboxed iframe is not same origin with the iframe's parent"}, "*");
16
  }
16
  }
17
}
17
}
18
</script>
18
</script>
19
<body onload='doStuff()'>
19
<body onload='doStuff()'>
20
  I'm a &lt;frame&gt; inside a &lt;frame&gt; inside an iframe which is sandboxed with 'allow-scripts'
20
  I'm a &lt;frame&gt; inside a &lt;frame&gt; inside an iframe which is sandboxed with 'allow-scripts allow-forms'
21
</body>
21
</body>
22
</html>
22
</html>
23
23
(-)a/content/html/content/test/file_iframe_sandbox_a_if13.html (+13 lines)
Line     Link Here 
Line 0    Link Here 
1
<!DOCTYPE HTML>
2
<html>
3
<head>
4
  <meta charset="utf-8">
5
  <title>Test for Bug 886262</title>
6
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
7
</head>
8
9
<body>
10
  <object data="file_iframe_sandbox_a_if14.html"></object>
11
</body>
12
13
</html>
(-)a/content/html/content/test/file_iframe_sandbox_a_if14.html (+34 lines)
Line     Link Here 
Line 0    Link Here 
1
<!DOCTYPE HTML>
2
<html>
3
<head>
4
  <meta charset="utf-8">
5
  <title>Test for Bug 886262</title>
6
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
7
</head>
8
9
<script>
10
  window.addEventListener("message", receiveMessage, false);
11
12
  function receiveMessage(event)
13
  {
14
    window.parent.parent.postMessage({ok: event.data.ok, desc: "objects containing " + event.data.desc}, "*");
15
  }
16
17
  function doStuff() {
18
    try {
19
      window.parent.parent.ok_wrapper(false, "an object inside a sandboxed iframe should NOT be same origin with the iframe's parent");
20
    }
21
    catch (e) {
22
      window.parent.parent.postMessage({ok: true, desc: "an object inside a sandboxed iframe is not same origin with the iframe's parent"}, "*");
23
    }
24
  }
25
</script>
26
27
<body onload='doStuff()'>
28
I'm a &lt;object&gt; inside an iframe which is sandboxed with 'allow-scripts allow-forms'
29
30
  <object data="file_iframe_sandbox_a_if15.html"></object>
31
</body>
32
33
</html>
34
(-)a/content/html/content/test/file_iframe_sandbox_a_if15.html (+33 lines)
Line     Link Here 
Line 0    Link Here 
1
<!DOCTYPE HTML>
2
<html>
3
<head>
4
  <meta charset="utf-8">
5
  <title>Test for Bug 886262</title>
6
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
7
</head>
8
9
<script>
10
function doStuff() {
11
  try {
12
    window.parent.parent.parent.ok_wrapper(false, "an object inside a frame or object inside a sandboxed iframe should NOT be same origin with the iframe's parent");
13
  }
14
  catch (e) {
15
    window.parent.parent.parent.postMessage({ok: true, desc: "an object inside a frame or object inside a sandboxed iframe is not same origin with the iframe's parent"}, "*");
16
  }
17
18
  // Check that sandboxed forms browsing context flag NOT set by attempting to submit a form.
19
  document.getElementById('a_form').submit();
20
}
21
</script>
22
23
<body onload='doStuff()'>
24
  I'm a &lt;object&gt; inside a &lt;frame&gt; or &lt;object&gt; inside an iframe which is sandboxed with 'allow-scripts allow-forms'
25
26
  <form method="get" action="file_iframe_sandbox_form_pass.html" id="a_form">
27
    First name: <input type="text" name="firstname">
28
    Last name: <input type="text" name="lastname">
29
    <input type="submit" id="a_button">
30
  </form>
31
</body>
32
</html>
33
(-)a/content/html/content/test/file_iframe_sandbox_a_if16.html (+25 lines)
Line     Link Here 
Line 0    Link Here 
1
<!DOCTYPE HTML>
2
<html>
3
<head>
4
  <meta charset="utf-8">
5
  <title>Test for Bug 886262</title>
6
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
7
</head>
8
9
<script>
10
  window.addEventListener("message", receiveMessage, false);
11
12
  function receiveMessage(event)
13
  {
14
    window.parent.parent.postMessage({ok: event.data.ok, desc: "objects containing " + event.data.desc}, "*");
15
  }
16
</script>
17
18
<body>
19
I'm a &lt;frame&gt; inside an iframe which is sandboxed with 'allow-scripts allow-forms'
20
21
  <object data="file_iframe_sandbox_a_if15.html"></object>
22
</body>
23
24
</html>
25
(-)a/content/html/content/test/file_iframe_sandbox_a_if17.html (+27 lines)
Line     Link Here 
Line 0    Link Here 
1
<!DOCTYPE HTML>
2
<html>
3
<head>
4
  <meta charset="utf-8">
5
  <title>Test for Bug 886262</title>
6
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
7
</head>
8
9
<script>
10
  function doTest() {
11
    var if_18_19 = document.getElementById('if_18_19');
12
    if_18_19.sandbox = "allow-scripts allow-same-origin";
13
    if_18_19.contentWindow.postMessage("go", "*");
14
  }
15
</script>
16
17
<body onload="doTest()">
18
  I am sandboxed but with "allow-scripts". I change the sandbox flags on if_18_19 to
19
  "allow-scripts allow-same-origin" then get it to re-navigate itself to
20
  file_iframe_sandbox_a_if18.html, which attemps to call a function in my parent.
21
  This should fail since my sandbox flags should be copied to it when the sandbox
22
  flags are changed.
23
24
  <iframe sandbox="allow-scripts" id="if_18_19" src="file_iframe_sandbox_a_if19.html" height="10" width="10"></iframe>
25
</body>
26
</html>
27
(-)a/content/html/content/test/file_iframe_sandbox_a_if18.html (+26 lines)
Line     Link Here 
Line 0    Link Here 
1
<!DOCTYPE HTML>
2
<html>
3
<head>
4
  <meta charset="utf-8">
5
  <title>Test for Bug 886262</title>
6
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
7
</head>
8
9
<script>
10
  function doTest() {
11
    try {
12
      window.parent.parent.ok_wrapper(false, "an iframe in an iframe SHOULD copy its parent's sandbox flags when its sandbox flags are changed");
13
    }
14
    catch (e) {
15
      window.parent.parent.postMessage({ok: true, desc: "an iframe in an iframe copies its parent's sandbox flags when its sandbox flags are changed"}, "*");
16
    }
17
  }
18
</script>
19
20
<body onload="doTest()">
21
  I'm an iframe whose sandbox flags have been changed to include allow-same-origin.
22
  I should not be able to call a function in my parent's parent because my parent's
23
  iframe does not have allow-same-origin set.
24
</body>
25
</html>
26
(-)a/content/html/content/test/file_iframe_sandbox_a_if19.html (+21 lines)
Line     Link Here 
Line 0    Link Here 
1
<!DOCTYPE HTML>
2
<html>
3
<head>
4
  <meta charset="utf-8">
5
  <title>Test for Bug 341604</title>
6
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
7
  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
8
</head>
9
10
<script>
11
  window.addEventListener("message", function(e){
12
     window.open("file_iframe_sandbox_a_if18.html", "_self");
13
  }, false);
14
</script>
15
16
<body>
17
  I'm just here to navigate to file_iframe_sandbox_a_if18.html after my owning
18
  iframe has had allow-same-origin added.
19
</body>
20
</html>
21
(-)a/content/html/content/test/test_iframe_sandbox_inheritance.html (-3 / +50 lines)
Line     Link Here 
 Lines 34-51   function ok_wrapper(result, desc) { Link Here 
34
  ok(result, desc);
34
  ok(result, desc);
35
35
36
  completedTests++;
36
  completedTests++;
37
37
38
  if (result) {
38
  if (result) {
39
	  passedTests++;
39
	  passedTests++;
40
  } 
40
  } 
41
41
42
  if (completedTests == 6) {
42
  if (completedTests == 13) {
43
    is(passedTests, 6, "there should be 6 passed inheritance tests");
43
    is(passedTests, completedTests, "there should be " + completedTests + " passed inheritance tests");
44
    SimpleTest.finish();
44
    SimpleTest.finish();
45
  }
45
  }
46
}
46
}
47
47
48
function doTest() {
48
function doTest() {
49
  // fails if bad
49
  // fails if bad
50
  // 1) an iframe with no sandbox attribute inside an iframe that has sandbox = ""
50
  // 1) an iframe with no sandbox attribute inside an iframe that has sandbox = ""
51
  // should not be able to execute scripts (cannot ever loosen permissions)
51
  // should not be able to execute scripts (cannot ever loosen permissions)
 Lines 97-118   function doTest() { Link Here 
97
  // 10) a <frame> inside an <iframe> sandboxed with 'allow-scripts' should not be same
97
  // 10) a <frame> inside an <iframe> sandboxed with 'allow-scripts' should not be same
98
  // origin with this document
98
  // origin with this document
99
  // done by file_iframe_sandbox_a_if11.html which is contained with file_iframe_sandbox_a_if10.html
99
  // done by file_iframe_sandbox_a_if11.html which is contained with file_iframe_sandbox_a_if10.html
100
100
101
  // passes if good
101
  // passes if good
102
  // 11) a <frame> inside a <frame> inside an <iframe> sandboxed with 'allow-scripts' should not be same
102
  // 11) a <frame> inside a <frame> inside an <iframe> sandboxed with 'allow-scripts' should not be same
103
  // origin with its parent frame or this document
103
  // origin with its parent frame or this document
104
  // done by file_iframe_sandbox_a_if12.html which is contained with file_iframe_sandbox_a_if11.html
104
  // done by file_iframe_sandbox_a_if12.html which is contained with file_iframe_sandbox_a_if11.html
105
106
  // passes if good, fails if bad
107
  // 12) An <object> inside an <iframe> sandboxed with 'allow-scripts' should not be same
108
  // origin with this document
109
  // Done by file_iframe_sandbox_a_if14.html which is contained within file_iframe_sandbox_a_if13.html
110
111
  // passes if good, fails if bad
112
  // 13) An <object> inside an <object> inside an <iframe> sandboxed with 'allow-scripts' should not be same
113
  // origin with its parent frame or this document
114
  // Done by file_iframe_sandbox_a_if15.html which is contained within file_iframe_sandbox_a_if14.html
115
116
  // passes if good, fails if bad
117
  // 14) An <object> inside a <frame> inside an <iframe> sandboxed with 'allow-scripts' should not be same
118
  // origin with its parent frame or this document
119
  // Done by file_iframe_sandbox_a_if15.html which is contained within file_iframe_sandbox_a_if16.html
120
  // which is contained within file_iframe_sandbox_a_if10.html
121
122
  // passes if good
123
  // 15) An <object> inside an <object> inside an <iframe> sandboxed with 'allow-scripts allow-forms'
124
  // should be able to submit forms.
125
  // Done by file_iframe_sandbox_a_if15.html which is contained within file_iframe_sandbox_a_if14.html
126
127
  // passes if good
128
  // 16) An <object> inside a <frame> inside an <iframe> sandboxed with 'allow-scripts allow-forms'
129
  // should be able to submit forms.
130
  // Done by file_iframe_sandbox_a_if15.html which is contained within file_iframe_sandbox_a_if16.html
131
  // which is contained within file_iframe_sandbox_a_if10.html
132
133
  // fails if bad
134
  // 17) An <object> inside an <iframe> sandboxed with 'allow-same-origin'
135
  // should not be able to run scripts.
136
  // Done by iframe "if_no_scripts" using a data: load.
137
138
  // passes if good
139
  // 18) An <object> inside an <iframe> sandboxed with 'allow-scripts allow-same-origin'
140
  // should be able to run scripts and be same origin with this document.
141
  // Done by iframe "if_scripts" using a data: load.
142
143
  // passes if good, fails if bad
144
  // 19) Make sure that the parent's document's sandboxing flags are copied when
145
  // changing the sandbox flags on an iframe inside an iframe.
146
  // Done in file_iframe_sandbox_a_if17.html and file_iframe_sandbox_a_if18.html
105
}
147
}
106
148
107
addLoadEvent(doTest);
149
addLoadEvent(doTest);
108
</script>
150
</script>
109
<body>
151
<body>
110
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=341604">Mozilla Bug 341604</a> - Implement HTML5 sandbox attribute for IFRAMEs
152
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=341604">Mozilla Bug 341604</a> - Implement HTML5 sandbox attribute for IFRAMEs
111
<p id="display"></p>
153
<p id="display"></p>
112
<div id="content">
154
<div id="content">
113
<iframe sandbox="" id="if_1" src="file_iframe_sandbox_a_if1.html" height="10" width="10"></iframe>
155
<iframe sandbox="" id="if_1" src="file_iframe_sandbox_a_if1.html" height="10" width="10"></iframe>
114
<iframe sandbox="allow-scripts" id="if_3" src="file_iframe_sandbox_a_if3.html" height="10" width="10"></iframe>
156
<iframe sandbox="allow-scripts" id="if_3" src="file_iframe_sandbox_a_if3.html" height="10" width="10"></iframe>
115
<iframe sandbox="allow-scripts allow-same-origin" id="if_5" src="file_iframe_sandbox_a_if5.html" height="10" width="10"></iframe>
157
<iframe sandbox="allow-scripts allow-same-origin" id="if_5" src="file_iframe_sandbox_a_if5.html" height="10" width="10"></iframe>
116
<iframe sandbox="allow-scripts allow-same-origin" id="if_8" src="file_iframe_sandbox_a_if8.html" height="10" width="10"></iframe>
158
<iframe sandbox="allow-scripts allow-same-origin" id="if_8" src="file_iframe_sandbox_a_if8.html" height="10" width="10"></iframe>
117
<iframe sandbox="allow-scripts" id="if_10" src="file_iframe_sandbox_a_if10.html" height="10" width="10"></iframe>
159
<iframe sandbox="allow-scripts allow-forms" id="if_10" src="file_iframe_sandbox_a_if10.html" height="10" width="10"></iframe>
160
<iframe sandbox="allow-scripts allow-forms" id="if_13" src="file_iframe_sandbox_a_if13.html" height="10" width="10"></iframe>
161
<iframe sandbox="allow-same-origin" id="if_no_scripts" src="data:text/html,<object%20data='data:text/html,<script>parent.parent.ok_wrapper(false, &quot;an object inside an iframe sandboxed with only allow-same-origin should not be able to run scripts&quot;)</script>'></object>" height="10" width="10"></iframe>
162
<iframe sandbox="allow-scripts allow-same-origin" id="if_scripts" src="data:text/html,<object%20data='data:text/html,<script>parent.parent.ok_wrapper(true, &quot;an object inside an iframe sandboxed with allow-scripts allow-same-origin should be able to run scripts and call functions in the parent of the iframe&quot;)</script>'></object>" height="10" width="10"></iframe>
163
<iframe sandbox="allow-same-origin" id="if_19" src="data:text/html,<iframe%20data='data:text/html,<script>parent.parent.ok_wrapper(true, &quot;an object inside an iframe sandboxed with allow-scripts allow-same-origin should be able to run scripts and call functions in the parent of the iframe&quot;)</script>'></object>" height="10" width="10"></iframe>
164
<iframe sandbox="allow-scripts" id="if_17" src="file_iframe_sandbox_a_if17.html" height="10" width="10"></iframe>
118
</div>
165
</div>

Return to bug 886262