summaryrefslogtreecommitdiffstats
path: root/dom/security/test/referrer-policy/referrer_page.sjs
blob: 62ec634e40725047ae8bc1df6a0ad5342c3a3767 (plain)
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
Cu.importGlobalProperties(["URLSearchParams"]);

function handleRequest(request, response) {
  let params = new URLSearchParams(request.queryString);
  let referrerPolicyHeader = params.get("header") || "";
  let metaReferrerPolicy = params.get("meta") || "";
  let showReferrer = params.has("show");

  if (referrerPolicyHeader) {
    response.setHeader("Referrer-Policy", referrerPolicyHeader, false);
  }

  let metaString = "";
  let resultString = "";

  if (metaReferrerPolicy) {
    metaString = `<meta name="referrer" content="${metaReferrerPolicy}">`;
  }

  if (showReferrer) {
    if (request.hasHeader("Referer")) {
      resultString = `Referer Header: <a id="result">${request.getHeader(
        "Referer"
      )}</a>`;
    } else {
      resultString = `Referer Header: <a id="result"></a>`;
    }
  }

  response.write(
    `<!DOCTYPE HTML>
     <html>
     <head>
       ${metaString}
     </head>
     <body>
       ${resultString}
     </body>
     </html>`
  );
}