]> git.mxchange.org Git - fba.git/blobdiff - fba/csrf.py
Continued:
[fba.git] / fba / csrf.py
index 1d22ccbf796846daddf1d50296fde29cb5ae0ec5..4602c284910c243294866bd0c8cff7316caf7305 100644 (file)
@@ -18,7 +18,6 @@ import bs4
 import reqto
 
 from fba import config
-#from fba import instances
 from fba import network
 
 def determine(domain: str, headers: dict) -> dict:
@@ -33,32 +32,27 @@ def determine(domain: str, headers: dict) -> dict:
     # Default headers with no CSRF
     reqheaders = headers
 
-    try:
-        # Fetch / to check for meta tag indicating csrf
-        # DEBUG: print(f"DEBUG: Fetching / from domain='{domain}' for CSRF check ...")
-        response = reqto.get(
-            f"https://{domain}/",
-            headers=network.web_headers,
-            timeout=(config.get("connection_timeout"), config.get("read_timeout"))
+    # Fetch / to check for meta tag indicating csrf
+    # DEBUG: print(f"DEBUG: Fetching / from domain='{domain}' for CSRF check ...")
+    response = reqto.get(
+        f"https://{domain}/",
+        headers=network.web_headers,
+        timeout=(config.get("connection_timeout"), config.get("read_timeout"))
+    )
+
+    # DEBUG: print(f"DEBUG: response.ok='{response.ok}',response.status_code={response.status_code},response.text()={len(response.text)}")
+    if response.ok and len(response.text) > 0:
+        meta = bs4.BeautifulSoup(
+            response.text,
+            "html.parser"
         )
+        # DEBUG: print(f"DEBUG: meta[]='{type(meta)}'")
+        tag = meta.find("meta", attrs={"name": "csrf-token"})
 
-        # DEBUG: print(f"DEBUG: response.ok='{response.ok}',response.status_code={response.status_code},response.text()={len(response.text)}")
-        if response.ok and len(response.text) > 0:
-            meta = bs4.BeautifulSoup(
-                response.text,
-                "html.parser"
-            )
-            # DEBUG: print(f"DEBUG: meta[]='{type(meta)}'")
-
-            tag = meta.find("meta", attrs={"name": "csrf-token"})
-            # DEBUG: print(f"DEBUG: tag={tag}")
-
+        # DEBUG: print(f"DEBUG: tag={tag}")
+        if tag is not None:
             # DEBUG: print(f"DEBUG: Adding CSRF token='{tag['content']}' for domain='{domain}'")
             reqheaders["X-CSRF-Token"] = tag["content"]
 
-    except BaseException as exception:
-        # DEBUG: print(f"DEBUG: No CSRF token found, using normal headers: domain='{domain}',exception[{type(exception)}]={exception}")
-        pass
-
     # DEBUG: print(f"DEBUG: reqheaders()={len(reqheaders)} - EXIT!")
     return reqheaders