princemaxp commited on
Commit
e9f9e54
·
verified ·
1 Parent(s): 8427644

Update header_analyzer.py

Browse files
Files changed (1) hide show
  1. header_analyzer.py +37 -3
header_analyzer.py CHANGED
@@ -29,10 +29,43 @@ def get_domain_age_days(domain: str):
29
  return None
30
  return None
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  def analyze_headers(headers, body=""):
33
  """
34
  Input: headers dict, optional body text
35
- Output: (findings: list[str], score: int)
36
  """
37
  findings = []
38
  score = 0
@@ -128,6 +161,7 @@ def analyze_headers(headers, body=""):
128
  score += 12
129
 
130
  if not findings:
131
- return ["No suspicious issues found in headers."], 0
132
 
133
- return findings, score, parse_auth_results(headers.get("Authentication-Results") or headers.get("Authentication-results") or "")
 
 
29
  return None
30
  return None
31
 
32
+ def parse_auth_results(auth_header: str):
33
+ """
34
+ Parse the Authentication-Results header and return a readable summary.
35
+ """
36
+ auth_header = (auth_header or "").lower()
37
+ findings = []
38
+
39
+ if not auth_header:
40
+ return "No Authentication-Results header found"
41
+
42
+ # SPF
43
+ if "spf=pass" in auth_header:
44
+ findings.append("SPF passed")
45
+ elif "spf=fail" in auth_header:
46
+ findings.append("SPF failed")
47
+
48
+ # DKIM
49
+ if "dkim=pass" in auth_header:
50
+ findings.append("DKIM passed")
51
+ elif "dkim=fail" in auth_header or "dkim=permerror" in auth_header:
52
+ findings.append("DKIM failed")
53
+
54
+ # DMARC
55
+ if "dmarc=pass" in auth_header:
56
+ findings.append("DMARC passed")
57
+ elif "dmarc=fail" in auth_header:
58
+ findings.append("DMARC failed")
59
+
60
+ if not findings:
61
+ return "Authentication results unclear or missing"
62
+
63
+ return ", ".join(findings)
64
+
65
  def analyze_headers(headers, body=""):
66
  """
67
  Input: headers dict, optional body text
68
+ Output: (findings: list[str], score: int, auth_summary: str)
69
  """
70
  findings = []
71
  score = 0
 
161
  score += 12
162
 
163
  if not findings:
164
+ return ["No suspicious issues found in headers."], 0, "No Authentication-Results header found"
165
 
166
+ # Return findings, cumulative score, and parsed authentication summary
167
+ return findings, score, parse_auth_results(auth_results)