···1-from dns.resolver import resolve as resolve_dns, NXDOMAIN
02from re import match as regex_match
3from typing import Any
4-import httpx
56from .kv import KV, nokv
7-8from .validator import is_valid_authserver_meta
9from ..security import is_safe_url
10···96 return did
9798 try:
99- answer = resolve_dns(f"_atproto.{handle}", "TXT")
100- except NXDOMAIN:
101 return None
102103 for record in answer:
···1+import dns.resolver as dns
2+import httpx
3from re import match as regex_match
4from typing import Any
056from .kv import KV, nokv
07from .validator import is_valid_authserver_meta
8from ..security import is_safe_url
9···95 return did
9697 try:
98+ answer = dns.resolve(f"_atproto.{handle}", "TXT")
99+ except dns.NXDOMAIN:
100 return None
101102 for record in answer:
+12-4
src/main.py
···45def page_profile_with_did(did: str):
46 did = f"did:{did}"
47 if not is_valid_did(did):
48- return "invalid did", 400
49 return page_profile(did)
5051···55 kv = KV(app, "did_from_handle")
56 did = resolve_did_from_handle(handle, kv, reload=reload)
57 if did is None:
58- return "did not found", 404
59 return page_profile(did, reload=reload)
606162def page_profile(did: str, reload: bool = False):
00063 kv = KV(app, "pds_from_did")
64 pds = resolve_pds_from_did(did, kv, reload=reload)
65 if pds is None:
66- return "pds not found", 404
67 profile, _ = load_profile(pds, did, reload=reload)
68 links = load_links(pds, did, reload=reload)
69 if links is None:
70- return "profile not found", 404
7172 if reload:
73 # remove the ?reload parameter
···265 )
266 if not response or not response.is_success:
267 app.logger.warning("PDS HTTP ERROR")
00000
···45def page_profile_with_did(did: str):
46 did = f"did:{did}"
47 if not is_valid_did(did):
48+ return render_template("error.html", message="invalid did"), 400
49 return page_profile(did)
5051···55 kv = KV(app, "did_from_handle")
56 did = resolve_did_from_handle(handle, kv, reload=reload)
57 if did is None:
58+ return render_template("error.html", message="did not found"), 404
59 return page_profile(did, reload=reload)
606162def page_profile(did: str, reload: bool = False):
63+ if _is_did_blocked(did):
64+ app.logger.debug(f"handling blocked did {did}")
65+ return render_template("error.html", message="profile not found"), 404
66 kv = KV(app, "pds_from_did")
67 pds = resolve_pds_from_did(did, kv, reload=reload)
68 if pds is None:
69+ return render_template("error.html", message="pds not found"), 404
70 profile, _ = load_profile(pds, did, reload=reload)
71 links = load_links(pds, did, reload=reload)
72 if links is None:
73+ return render_template("error.html", message="profile not found"), 404
7475 if reload:
76 # remove the ?reload parameter
···268 )
269 if not response or not response.is_success:
270 app.logger.warning("PDS HTTP ERROR")
271+272+273+def _is_did_blocked(did: str) -> bool:
274+ kv = KV(app, "blockeddids")
275+ return kv.get(did) is not None