tor-browser

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

credentials-test-helper.py (1405B)


      1 def main(request, response):
      2    """
      3    A handler that does either one of the following based on the provided
      4    "action" parameter:
      5    1) action="store-cookie": Stores the provided token and the request cookie
      6    to the stash, and returns a regular module script content.
      7    2) action="get-cookie": Retrieves and returns the content stored in the
      8    stash at the provided token.
      9    """
     10    token = request.GET[b"token"]
     11    action = request.GET[b"action"]
     12 
     13    response.status = 200
     14    response.headers.append(b"Content-Type", b"text/javascript")
     15 
     16    if b"access_control_allow_credentials_header" in request.GET:
     17      response.headers.append(b"Access-Control-Allow-Credentials", request.GET[b"access_control_allow_credentials_header"])
     18 
     19    if b"access_control_allow_origin_header" in request.GET:
     20      response.headers.append(b"Access-Control-Allow-Origin", request.GET[b"access_control_allow_origin_header"])
     21 
     22    if b"shared_storage_cross_origin_worklet_allowed_header" in request.GET:
     23      response.headers.append(b"Shared-Storage-Cross-Origin-Worklet-Allowed", request.GET[b"shared_storage_cross_origin_worklet_allowed_header"])
     24 
     25    if action == b"store-cookie":
     26      cookie = request.headers.get(b"Cookie", b"NO_COOKIE_HEADER")
     27      request.server.stash.put(token, cookie)
     28      return b""
     29    else:
     30      assert action == b"get-cookie"
     31      return request.server.stash.take(token)