Skip to content

Commit 120709e

Browse files
authored
Bug 1933266 - Update domain allowlist matching for Widevine (#3252)
1 parent b2d6bd3 commit 120709e

File tree

4 files changed

+66
-5
lines changed

4 files changed

+66
-5
lines changed

src/auslib/AUS.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import functools
22
import logging
3+
import re
34
from random import randint
45
from urllib.parse import urlparse
56

@@ -34,14 +35,29 @@ def isSpecialURL(url, specialForceHosts):
3435
def isForbiddenUrl(url, product, allowlistedDomains):
3536
if allowlistedDomains is None:
3637
allowlistedDomains = []
37-
domain = urlparse(url)[1]
38+
parsedUrl = urlparse(url)
39+
domain = parsedUrl.netloc
3840
if domain not in allowlistedDomains:
3941
logging.warning("Forbidden domain: %s", domain)
4042
return True
41-
if product not in allowlistedDomains[domain]:
43+
allowlistedDomain = allowlistedDomains[domain]
44+
if isinstance(allowlistedDomain, tuple):
45+
if product in allowlistedDomain:
46+
return False
4247
logging.warning("Forbidden domain for product %s: %s", product, domain)
43-
return True
44-
return False
48+
elif isinstance(allowlistedDomain, dict):
49+
path = parsedUrl.path
50+
for pathRegex in allowlistedDomain:
51+
if not re.fullmatch(pathRegex, path):
52+
continue
53+
if product in allowlistedDomain[pathRegex]:
54+
return False
55+
logging.warning("Forbidden domain/path for product %s: %s (%s)", product, domain, path)
56+
return True
57+
logging.warning("Forbidden domain/path: %s (%s)", domain, path)
58+
else:
59+
logging.warning("Forbidden domain, malformed entry: %s", domain)
60+
return True
4561

4662

4763
def getFallbackChannel(channel):

tests/test_AUS.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import mock
55
import pytest
66

7-
from auslib.AUS import AUS, FORCE_FALLBACK_MAPPING, FORCE_MAIN_MAPPING
7+
from auslib.AUS import AUS, FORCE_FALLBACK_MAPPING, FORCE_MAIN_MAPPING, isForbiddenUrl
88
from auslib.blobs.base import createBlob
99
from auslib.global_state import dbo
1010

@@ -211,3 +211,36 @@ def testPinningWithThrottling25WithForcingFailureAndFallback(self):
211211

212212
self.assertEqual(served_pinned, 1)
213213
self.assertEqual(tested, 1)
214+
215+
216+
class TestForbiddenUrl(unittest.TestCase):
217+
def test_urls(self):
218+
allowlist = {
219+
"ignore.net": ("c", "d"),
220+
"b.org": ("e", "f"),
221+
"a.com": {
222+
"/path/[\\w\\.]+/[\\w\\.]+\\.bin": (
223+
"a",
224+
"b",
225+
),
226+
},
227+
}
228+
229+
# Unmatched domain
230+
self.assertTrue(isForbiddenUrl("https://b.com/path/foo/bar.bin", "c", allowlist))
231+
232+
# Matches domain without path but not product
233+
self.assertTrue(isForbiddenUrl("https://b.org/anything/I/want.exe", "d", allowlist))
234+
235+
# Matches domain and product without path
236+
self.assertFalse(isForbiddenUrl("https://b.org/anything/I/want.exe", "e", allowlist))
237+
238+
# Matches domain but path doesn't match regex
239+
self.assertTrue(isForbiddenUrl("https://a.com/not/allowed.bin", "a", allowlist))
240+
self.assertTrue(isForbiddenUrl("https://a.com/path/not/allowed+.bin", "b", allowlist))
241+
242+
# Matches domain and path, but not product
243+
self.assertTrue(isForbiddenUrl("https://a.com/path/foo/bar.bin", "c", allowlist))
244+
245+
# Matches domain, path and product
246+
self.assertFalse(isForbiddenUrl("https://a.com/path/foo/bar.bin", "b", allowlist))

uwsgi/admin.wsgi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ DOMAIN_ALLOWLIST = {
3434
"Widevine",
3535
"Widevine-L1",
3636
),
37+
"www.google.com": {
38+
"/dl/release2/chrome_component/[\\w\\.]+/[\\w\\.]+\\.crx3": (
39+
"Widevine",
40+
"Widevine-L1",
41+
),
42+
},
3743
"ftp.mozilla.org": ("SystemAddons",),
3844
"fpn.firefox.com": ("FirefoxVPN", "Guardian"),
3945
"vpn.mozilla.org": ("FirefoxVPN", "Guardian"),

uwsgi/public.wsgi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ DOMAIN_ALLOWLIST = {
3535
"Widevine",
3636
"Widevine-L1",
3737
),
38+
"www.google.com": {
39+
"/dl/release2/chrome_component/[\\w\\.]+/[\\w\\.]+\\.crx3": (
40+
"Widevine",
41+
"Widevine-L1",
42+
),
43+
},
3844
"ftp.mozilla.org": ("SystemAddons",),
3945
"fpn.firefox.com": ("FirefoxVPN", "Guardian"),
4046
"vpn.mozilla.org": ("FirefoxVPN", "Guardian"),

0 commit comments

Comments
 (0)