tor-browser

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

authenticate.py (825B)


      1 # TODO(https://crbug.com/406819294): Simplify relative import for util.
      2 import importlib
      3 util = importlib.import_module("speculation-rules.prefetch.resources.util")
      4 
      5 def main(request, response):
      6  def fmt(x):
      7    return f'"{x.decode("utf-8")}"' if x is not None else "undefined"
      8 
      9  sec_purpose = request.headers.get("Sec-Purpose", b"").decode("utf-8")
     10 
     11  headers = [
     12    (b"Content-Type", b"text/html"),
     13    (b'WWW-Authenticate', b'Basic'),
     14    (b'Cache-Control', b'no-store')
     15  ]
     16  status = 200 if request.auth.username is not None or sec_purpose.startswith(
     17      "prefetch") else 401
     18 
     19  content = util.get_executor_html(
     20    request,
     21    f'''window.requestCredentials = {{
     22        username: {fmt(request.auth.username)},
     23        password: {fmt(request.auth.password)}
     24      }};
     25    ''')
     26 
     27  return status, headers, content