Add wildcard matching of trusted subdomains (#587)

This commit is contained in:
Etoh 2023-02-21 23:11:42 +00:00 committed by GitHub
parent e1bcf12a1a
commit 6f1f43dcf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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