Perth0603 commited on
Commit
0d951c0
·
verified ·
1 Parent(s): b16cfad

Upload 7 files

Browse files
Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -83,6 +83,20 @@ _AUTOCALIB_LEGIT_URLS: List[str] = []
83
  _KNOWN_LEGIT_HOSTS: List[str] = []
84
  _KNOWN_PHISH_HOSTS: List[str] = []
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  # -------------------------
87
  # CSV configuration support (optional)
88
  # -------------------------
@@ -440,9 +454,9 @@ def predict_url(payload: PredictUrlPayload):
440
  host = (urlparse(url_str).hostname or "").lower()
441
  if host:
442
  override_label: Optional[str] = None
443
- if host in _KNOWN_LEGIT_HOSTS:
444
  override_label = "LEGIT"
445
- elif host in _KNOWN_PHISH_HOSTS:
446
  override_label = "PHISH"
447
  if override_label is not None:
448
  # Map numeric label according to resolved polarity
 
83
  _KNOWN_LEGIT_HOSTS: List[str] = []
84
  _KNOWN_PHISH_HOSTS: List[str] = []
85
 
86
+ def _normalize_host(value: str) -> str:
87
+ v = value.strip().lower()
88
+ if v.startswith("www."):
89
+ v = v[4:]
90
+ return v
91
+
92
+ def _host_matches_any(host: str, known: List[str]) -> bool:
93
+ base = _normalize_host(host)
94
+ for item in known:
95
+ k = _normalize_host(item)
96
+ if base == k or base.endswith("." + k):
97
+ return True
98
+ return False
99
+
100
  # -------------------------
101
  # CSV configuration support (optional)
102
  # -------------------------
 
454
  host = (urlparse(url_str).hostname or "").lower()
455
  if host:
456
  override_label: Optional[str] = None
457
+ if _host_matches_any(host, _KNOWN_LEGIT_HOSTS):
458
  override_label = "LEGIT"
459
+ elif _host_matches_any(host, _KNOWN_PHISH_HOSTS):
460
  override_label = "PHISH"
461
  if override_label is not None:
462
  # Map numeric label according to resolved polarity