tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

moving-between-documents-iframe.py (2777B)


      1 import random
      2 import time
      3 
      4 from wptserve.utils import isomorphic_decode
      5 
      6 
      7 """
      8 This script serves
      9 """
     10 
     11 def main(request, response):
     12  inlineOrExternal = request.GET.first(b"inlineOrExternal", b"null")
     13  hasBlockingStylesheet = request.GET.first(b"hasBlockingStylesheet", b"true") == b"true"
     14  result = request.GET.first(b"result", b"success")
     15  type = u"text/javascript" if request.GET.first(b"type", b"classic") == b"classic" else u"module"
     16 
     17  response.headers.set(b"Content-Type", b"text/html; charset=utf-8")
     18  response.headers.set(b"Transfer-Encoding", b"chunked")
     19  response.write_status_headers()
     20 
     21  # Step 1: Start parsing.
     22  body = u"""<!DOCTYPE html>
     23    <head>
     24      <script>
     25        parent.postMessage("fox", "*");
     26      </script>
     27  """
     28 
     29  if hasBlockingStylesheet:
     30    body += u"""
     31        <link rel="stylesheet" href="slow-flag-setter.py?result=css&cache=%f">
     32      """ % random.random()
     33 
     34  body += u"""
     35    </head>
     36    <body>
     37  """
     38 
     39  if inlineOrExternal == b"inline" or inlineOrExternal == b"external" or inlineOrExternal == b"empty-src":
     40        body += u"""
     41      <streaming-element>
     42    """
     43 
     44  # Trigger DOM processing
     45  body += u"A" * 100000
     46 
     47  response.writer.write(u"%x\r\n" % len(body))
     48  response.writer.write(body)
     49  response.writer.write(u"\r\n")
     50 
     51  body = u""
     52 
     53  if inlineOrExternal == b"inline":
     54    time.sleep(1)
     55    body += u"""
     56        <script id="s1" type="%s"
     57                onload="scriptOnLoad()"
     58                onerror="scriptOnError(event)">
     59        if (!window.readyToEvaluate) {
     60          window.didExecute = "executed too early";
     61        } else {
     62          window.didExecute = "executed";
     63        }
     64    """ % type
     65    if result == b"parse-error":
     66      body += u"1=2 parse error\n"
     67 
     68    body += u"""
     69        </script>
     70      </streaming-element>
     71    """
     72  elif inlineOrExternal == b"external":
     73    time.sleep(1)
     74    body += u"""
     75        <script id="s1" type="%s"
     76                src="slow-flag-setter.py?result=%s&cache=%s"
     77                onload="scriptOnLoad()"
     78                onerror="scriptOnError(event)"></script>
     79      </streaming-element>
     80    """ % (type, isomorphic_decode(result), random.random())
     81  elif inlineOrExternal == b"empty-src":
     82    time.sleep(1)
     83    body += u"""
     84        <script id="s1" type="%s"
     85                src=""
     86                onload="scriptOnLoad()"
     87                onerror="scriptOnError(event)"></script>
     88      </streaming-element>
     89    """ % (type,)
     90 
     91  #        // if readyToEvaluate is false, the script is probably
     92  #       // wasn't blocked by stylesheets as expected.
     93 
     94  # Trigger DOM processing
     95  body += u"B" * 100000
     96 
     97  response.writer.write(u"%x\r\n" % len(body))
     98  response.writer.write(body)
     99  response.writer.write(u"\r\n")
    100 
    101  response.writer.write(u"0\r\n")
    102  response.writer.write(u"\r\n")