Skip to content

Commit 12c90eb

Browse files
authored
Embed API: fix regex patterns for allowed external domains (#11059)
The patterns were not ending with `$`, so any domain that started with the allowed domain would be allowed (docs.python.org.example.com). This isn't a security issue, since including content from a domain that isn't allowed is not differently than including content from a domain that is hosted on RTD (users shouldn't allow including content from projects they don't trust). This is mostly to prevent abuse.
1 parent 7daff3d commit 12c90eb

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

readthedocs/embed/v3/tests/test_basics.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class TestEmbedAPIv3Basics:
1010
@pytest.fixture(autouse=True)
1111
def setup_method(self, settings):
1212
settings.PUBLIC_DOMAIN = "readthedocs.io"
13-
settings.RTD_EMBED_API_EXTERNAL_DOMAINS = ["docs.project.com"]
13+
settings.RTD_EMBED_API_EXTERNAL_DOMAINS = [r"^docs\.project\.com$"]
1414

1515
self.api_url = reverse("embed_api_v3")
1616

readthedocs/embed/v3/tests/test_external_pages.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class TestEmbedAPIv3ExternalPages:
1414
@pytest.fixture(autouse=True)
1515
def setup_method(self, settings):
1616
settings.PUBLIC_DOMAIN = "readthedocs.io"
17-
settings.RTD_EMBED_API_EXTERNAL_DOMAINS = ["docs.project.com"]
17+
settings.RTD_EMBED_API_EXTERNAL_DOMAINS = [r"^docs\.project\.com$"]
1818

1919
self.api_url = reverse("embed_api_v3")
2020

readthedocs/settings/base.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -932,10 +932,10 @@ def DOCKER_LIMITS(self):
932932
MAILERLITE_API_KEY = None
933933

934934
RTD_EMBED_API_EXTERNAL_DOMAINS = [
935-
r'docs\.python\.org',
936-
r'docs\.scipy\.org',
937-
r'docs\.sympy\.org',
938-
r'numpy\.org',
935+
r'^docs\.python\.org$',
936+
r'^docs\.scipy\.org$',
937+
r'^docs\.sympy\.org$',
938+
r'^numpy\.org$',
939939
]
940940
RTD_EMBED_API_PAGE_CACHE_TIMEOUT = 5 * 10
941941
RTD_EMBED_API_DEFAULT_REQUEST_TIMEOUT = 1

readthedocs/settings/docker_compose.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ def RTD_EMBED_API_EXTERNAL_DOMAINS(self):
8383
domains = super().RTD_EMBED_API_EXTERNAL_DOMAINS
8484
domains.extend(
8585
[
86-
r".*\.readthedocs\.io",
87-
r".*\.org\.readthedocs\.build",
88-
r".*\.readthedocs-hosted\.com",
89-
r".*\.com\.readthedocs\.build",
86+
r"^.*\.readthedocs\.io$",
87+
r"^.*\.org\.readthedocs\.build$",
88+
r"^.*\.readthedocs-hosted\.com$",
89+
r"^.*\.com\.readthedocs\.build$",
9090
]
9191
)
9292
return domains

0 commit comments

Comments
 (0)