Add wildcard matching of trusted subdomains (#587) (#588)

This commit is contained in:
Etoh 2023-02-28 20:32:47 +00:00 committed by GitHub
parent a6b8b6d333
commit e0dd0cf05f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -569,8 +569,15 @@ class SyncplayClient(object):
if self._config['trustedDomains']:
for entry in self._config['trustedDomains']:
trustedDomain, _, path = entry.partition('/')
if o.hostname not in (trustedDomain, "www." + trustedDomain):
# domain does not match
foundMatch = False
if o.hostname in (trustedDomain, "www." + trustedDomain):
foundMatch = True
elif "*" in trustedDomain:
wildcardRegex = "^("+re.escape(trustedDomain).replace("\\*","([^.]+)")+")$"
wildcardMatch = bool(re.fullmatch(wildcardRegex, o.hostname, re.IGNORECASE))
if wildcardMatch:
foundMatch = True
if not foundMatch:
continue
if path and not o.path.startswith('/' + path):
# trusted domain has a path component and it does not match