tor-browser

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

echo-policy.py (884B)


      1 # This will echo the 'Sec-Required-Document-Policy' request header in the body
      2 # of the response, as well as in the 'Document-Policy' response header (to
      3 # ensure the response is loaded by a user agent which is implementing document
      4 # policy.)
      5 import json
      6 
      7 from wptserve.utils import isomorphic_decode
      8 
      9 def main(request, response):
     10    msg = {}
     11    headers = [(b'Content-Type', b'text/html')]
     12 
     13    srdp = request.headers.get(b'Sec-Required-Document-Policy')
     14    if srdp:
     15      msg[u'requiredPolicy'] = isomorphic_decode(srdp)
     16      headers.append((b'Document-Policy', srdp))
     17 
     18    frameId = request.GET.first(b'id',None)
     19    if frameId:
     20      msg[u'id'] = isomorphic_decode(frameId)
     21 
     22    content = u"""<!DOCTYPE html>
     23 <script>
     24 top.postMessage(%s, "*");
     25 </script>
     26 %s
     27 """ % (json.dumps(msg), isomorphic_decode(srdp) if srdp != None else srdp)
     28 
     29    return (200, u'OK'), headers, content