tor-browser

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

setup_sharded_server_state.py (1083B)


      1 import json
      2 import importlib
      3 session_manager = importlib.import_module('device-bound-session-credentials.session_manager')
      4 
      5 def main(request, response):
      6    request_body = json.loads(request.body.decode('utf-8'))
      7 
      8    test_id = request_body.get("testId")
      9    if test_id is None:
     10        test_id = session_manager.initialize_test()
     11 
     12    # subdomain-registration.https.html does registration on a
     13    # subdomain. Without the Domain attribute, the test_id cookie won't
     14    # be available on the subdomain.
     15    cookie_attributes = f"Domain={request.url_parts.hostname}"
     16 
     17    # Cross-site tests (e.g. allowed-refresh-initiators.https.html) require a
     18    # SameSite=None cookie, which must also be Secure. But
     19    # not-secure-connection.html cannot have a Secure cookie, so we need to make
     20    # the attributes conditional on the test.
     21    cross_site = request_body.get("crossSite")
     22    if cross_site is not None and cross_site:
     23        cookie_attributes += ";SameSite=None;Secure"
     24 
     25    headers = [("Set-Cookie", f"test_id={test_id};{cookie_attributes}")]
     26 
     27    return (200, headers, "")