From a05a9a2d8a1476e71629d681c6ba1ab707873e52 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 31 Mar 2024 07:01:10 +0200 Subject: [PATCH] Continued: - handled ParserRejectedMarkup properly --- fba/http/csrf.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/fba/http/csrf.py b/fba/http/csrf.py index a66fa02..0e9a3a8 100644 --- a/fba/http/csrf.py +++ b/fba/http/csrf.py @@ -59,13 +59,20 @@ def determine(domain: str, headers: dict) -> dict: logger.debug("Parsing response.text()=%d Bytes ...", len(response.text)) cookies.store(domain, response.cookies.get_dict()) + # Init tag + tag = None + # Parse text - meta = bs4.BeautifulSoup( - response.text, - "html.parser" - ) - logger.debug("meta[]='%s'", type(meta)) - tag = meta.find("meta", attrs={"name": "csrf-token"}) + try: + meta = bs4.BeautifulSoup( + response.text, + "html.parser" + ) + + logger.debug("meta[]='%s'", type(meta)) + tag = meta.find("meta", attrs={"name": "csrf-token"}) + except bs4.builder.ParserRejectedMarkup: + logger.warning("domain='%s' has returned invalid HTML markup", domain) logger.debug("tag[%s]='%s'", type(tag), tag) if tag is not None: -- 2.39.5