File: cross-origin-same-site-credentials.https.sub.html

package info (click to toggle)
thunderbird 1%3A140.4.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,609,432 kB
  • sloc: cpp: 7,672,442; javascript: 5,901,613; ansic: 3,898,954; python: 1,413,343; xml: 653,997; asm: 462,286; java: 180,927; sh: 113,489; makefile: 20,460; perl: 14,288; objc: 13,059; yacc: 4,583; pascal: 3,352; lex: 1,720; ruby: 1,222; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (55 lines) | stat: -rw-r--r-- 2,968 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE HTML>
<html>
<head>
  <title>Test that credentials are sent properly in a cross-origin but same-site nested context</title>
  <script src='/resources/testharness.js'></script>
  <script src='/resources/testharnessreport.js'></script>
  <script src='resources/report-helper.js'></script>
</head>
<body>
  <script>
    const base_url = `${location.protocol}//${location.host}`;
    const endpoint = `${base_url}/reporting/resources/report.py`;
    const id = 'd6f382f4-028d-51e0-9ef2-a635439da02a';

    promise_test(async t => {
      // If this is not run from the expected origin, then the A->A->www.A frame embedding will not be correct,
      // and the cookies set in the top-level page will never be returned with the reports.
      assert_true(location.href.startsWith("https://{{hosts[][]}}:{{ports[https][0]}}/"),
                  "Test running on unexpected origin; subsequent assertions will fail.");

      // Set credentials, and set up test to clear them afterwards. Cookies are set with the Domain
      // attribute, so that they may be sent to same-site resources.
      await fetch('/cookies/resources/setSameSiteDomain.py?reporting', {mode: 'no-cors', credentials: 'include', cache: 'no-store'});
      t.add_cleanup(() => fetch("/cookies/resources/dropSameSite.py", {mode: 'no-cors', credentials: 'include', cache: 'no-store'}));

      // Insert a same-origin frame, which will then frame a same-site but cross-origin page to
      // trigger a CSP error.
      const frame = document.createElement('iframe');
      frame.src = `https://{{hosts[][]}}:{{ports[https][0]}}/reporting/resources/middle-frame.https.sub.html?host={{hosts[][www]}}&reportID=${id}`;

      // Wait for the inner frame to signal that the report has been generated.
      await new Promise(resolve => {
        window.addEventListener('message', ev => {
          if (ev.data === "done")
            resolve(ev.data);
          });
        document.body.appendChild(frame);
      });

      const reports = await pollReports(endpoint, id);
      checkReportExists(reports, 'csp-violation',
                        `https://{{hosts[][www]}}:{{ports[https][0]}}/reporting/resources/same-origin-report.https.sub.html?reportID=${id}`);

      // All credentials set at the top-level should be received.
      const cookies = await pollCookies(endpoint, id);
      assert_equals(cookies.samesite_none, "[samesite_none=reporting]", "Credential value was correct");
      assert_equals(cookies.samesite_unspecified, "[samesite_unspecified=reporting]", "Credential value was correct");
      assert_equals(cookies.samesite_lax, "[samesite_lax=reporting]", "Credential value was correct");
      assert_equals(cookies.samesite_strict, "[samesite_strict=reporting]", "Credential value was correct");
      assert_equals(Object.keys(cookies).length, 4, "No additional cookies were received");

    }, "Reporting endpoints received credentials.");
  </script>
</body>
</html>