github.com/google/go-safeweb@v0.0.0-20231219055052-64d8cfc90fbb/examples/trustedtypes/unsafe.html (about)

     1  <!--
     2  Copyright 2020 Google LLC
     3  Licensed under the Apache License, Version 2.0 (the "License");
     4  you may not use this file except in compliance with the License.
     5  You may obtain a copy of the License at
     6  	
     7  https://www.apache.org/licenses/LICENSE-2.0
     8  Unless required by applicable law or agreed to in writing, software
     9  distributed under the License is distributed on an "AS IS" BASIS,
    10  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  See the License for the specific language governing permissions and
    12  limitations under the License.
    13  -->
    14  <!DOCTYPE html>
    15  <html lang="en">
    16  
    17  <head>
    18      <title>Trusted Types - example</title>
    19      <!-- Install polyfill for browsers that do not support Trusted Types yet. -->
    20      <script src="https://w3c.github.io/webappsec-trusted-types/dist/es5/trustedtypes.build.js"
    21          data-csp="require-trusted-types-for 'script'"></script>
    22  </head>
    23  
    24  <body>
    25      <p>This document installs the following script which introduces a DOM XSS vulnerability:</p>
    26      <p>
    27          <code>document.getElementById("hash").innerHTML = location.hash;</code>
    28      </p>
    29      With TrustedTypes protection enabled, the browser will reject execution of any JavaScript code on this page.
    30      You can verify it by looking at the console output)
    31      <p>location hash: <span id="hash"></span></p>
    32      <script>
    33          window.addEventListener('load', function () {
    34              // This piece of code is vulnerable to DOM XSS.
    35              document.getElementById("hash").innerHTML = location.hash;
    36          })
    37      </script>
    38  </body>
    39  
    40  </html>