summaryrefslogtreecommitdiffstats
path: root/dom/security/test/csp/file_navigate_to.sjs
blob: d3b3b1c2b114480b8d7656f06d15eeb1570c86ab (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
42
43
44
45
46
47
48
49
// Custom *.sjs file specifically for the needs of
// https://bugzilla.mozilla.org/show_bug.cgi?id=1529068

"use strict";
Components.utils.importGlobalProperties(["URLSearchParams"]);

const TEST_NAVIGATION_HEAD = `
  <!DOCTYPE HTML>
  <html>
  <head>
    <title>Bug 1529068 Implement CSP 'navigate-to' directive</title>`;

const TEST_NAVIGATION_AFTER_META = `
  </head>
  <body>
    <script type="text/javascript">
    window.location = "`;

const TEST_NAVIGATION_FOOT = `";
    </script>
  </body>
  </html>
  `;

function handleRequest(request, response) {
  const query = new URLSearchParams(request.queryString);

  response.setHeader("Cache-Control", "no-cache", false);
  response.setHeader("Content-Type", "text/html", false);

  if (query.get("redir")) {
    response.setStatusLine(request.httpVersion, "302", "Found");
    response.setHeader("Location", query.get("redir"), false);
    return;
  }

  response.write(TEST_NAVIGATION_HEAD);

  // We need meta to set multiple CSP headers.
  if (query.get("csp")) {
    response.write("<meta http-equiv=\"Content-Security-Policy\" content=\""+query.get("csp")+"\">");
  }
  if (query.get("csp2")) {
    response.write("<meta http-equiv=\"Content-Security-Policy\" content=\""+query.get("csp2")+"\">");
  }

  response.write(TEST_NAVIGATION_AFTER_META + query.get("target") + TEST_NAVIGATION_FOOT);

}