summaryrefslogtreecommitdiffstats
path: root/dom/security/test/csp/file_svg_inline_style_server.sjs
blob: 6073f36f62adba4b3b337c00ba55251c4da09b4d (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
"use strict";

const SVG_IMG = `<svg width="200" height="200" viewBox="0 0 150 150" xmlns="http://www.w3.org/2000/svg">
   <style>
     circle {
       fill: orange;
       stroke: black;
       stroke-width: 10px;
     }
   </style>
   <circle cx="50" cy="50" r="40" />
   </svg>`;

const SVG_IMG_NO_INLINE_STYLE = `<svg width="200" height="200" viewBox="0 0 150 150" xmlns="http://www.w3.org/2000/svg">
   <circle cx="50" cy="50" r="40" />
   </svg>`;

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

  response.setHeader("Cache-Control", "no-cache", false);
  response.setHeader("Content-Type", "image/svg+xml", false);

  if (query.includes("svg_inline_style_csp")) {
    response.setHeader("Content-Security-Policy", "default-src 'none'", false);
    response.write(SVG_IMG);
    return;
  }

  if (query.includes("svg_inline_style_nocsp")) {
    response.write(SVG_IMG);
    return;
  }

  if (query.includes("svg_no_inline_style")) {
    response.write(SVG_IMG_NO_INLINE_STYLE);
    return;
  }

  // we should never get here, but just in case
  // return something unexpected
  response.write("do'h");
}