File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
tools/server/public_simplechat/local.tools Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ # Handle URL validation
2+ # by Humans for All
3+
4+ import urllib .parse
5+ import re
6+ from dataclasses import dataclass
7+
8+
9+ gMe = {
10+ }
11+
12+
13+ @dataclass (frozen = True )
14+ class UrlVResponse :
15+ """
16+ Used to return result wrt urlreq helper below.
17+ """
18+ callOk : bool
19+ statusCode : int
20+ statusMsg : str = ""
21+
22+
23+ def validator_ok ():
24+ pass
25+
26+
27+ def validate_url (url : str , tag : str ):
28+ """
29+ Implement a re based filter logic on the specified url.
30+ """
31+ tag = f"VU:{ tag } "
32+ if (not gMe .get ('--allowed.domains' )):
33+ return UrlVResponse (False , 400 , f"DBUG:{ tag } :MissingAllowedDomains" )
34+ urlParts = urllib .parse .urlparse (url )
35+ print (f"DBUG:ValidateUrl:{ urlParts } , { urlParts .hostname } " )
36+ urlHName = urlParts .hostname
37+ if not urlHName :
38+ return UrlVResponse (False , 400 , f"WARN:{ tag } :Missing hostname in Url" )
39+ bMatched = False
40+ for filter in gMe ['--allowed.domains' ]:
41+ if re .match (filter , urlHName ):
42+ bMatched = True
43+ if not bMatched :
44+ return UrlVResponse (False , 400 , f"WARN:{ tag } :requested hostname not allowed" )
45+ return UrlVResponse (True , 200 )
You can’t perform that action at this time.
0 commit comments