From 9d7996d7fd0a041a1b94eba5f2b04943c9baddbf Mon Sep 17 00:00:00 2001 From: prez Date: Sat, 2 May 2020 17:36:34 +0200 Subject: [PATCH] client: add simple wildcard matching mechanism for trusted domains (#306) to resolve #305 --- syncplay/client.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/syncplay/client.py b/syncplay/client.py index 817047e..236720d 100755 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -506,6 +506,12 @@ class SyncplayClient(object): return False def isURITrusted(self, URIToTest): + def sWildcardMatch(a, b): + splt = a.split('*') + if len(splt) == 1: + return b.startswith(a) + return b.startswith(splt[0]) and b.endswith(splt[-1]) + URIToTest = URIToTest+"/" for trustedProtocol in constants.TRUSTABLE_WEB_PROTOCOLS: if URIToTest.startswith(trustedProtocol): @@ -513,7 +519,7 @@ class SyncplayClient(object): if self._config['trustedDomains']: for trustedDomain in self._config['trustedDomains']: trustableURI = ''.join([trustedProtocol, trustedDomain, "/"]) - if URIToTest.startswith(trustableURI): + if sWildcardMatch(trustableURI, URIToTest): return True return False else: