Skip to content

Custom domain: don't allow external domain #11064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions readthedocs/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,15 @@ def clean_domain(self):

domain_string = parsed.netloc

# Don't allow production or public domain to be set as custom domain
for invalid_domain in [settings.PRODUCTION_DOMAIN, settings.PUBLIC_DOMAIN]:
# Don't allow internal domains to be added, we have:
# - Dashboard domain
# - Public domain (from where documentation pages are served)
# - External version domain (from where PR previews are served)
for invalid_domain in [
settings.PRODUCTION_DOMAIN,
settings.PUBLIC_DOMAIN,
settings.RTD_EXTERNAL_VERSION_DOMAIN,
]:
if invalid_domain and domain_string.endswith(invalid_domain):
raise forms.ValidationError(
f'{invalid_domain} is not a valid domain.'
Expand Down
12 changes: 12 additions & 0 deletions readthedocs/rtd_tests/tests/test_domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ def test_public_domain_not_allowed(self):
f"{settings.PUBLIC_DOMAIN} is not a valid domain.",
)

@override_settings(RTD_EXTERNAL_VERSION_DOMAIN="readthedocs.build")
def test_external_domain_not_allowed(self):
for domain in ["readthedocs.build", "test.readthedocs.build"]:
form = DomainForm(
{"domain": domain},
project=self.project,
)
self.assertFalse(form.is_valid())
self.assertEqual(
form.errors["domain"][0], "readthedocs.build is not a valid domain."
)

def test_domain_with_path(self):
form = DomainForm(
{"domain": "domain.com/foo/bar"},
Expand Down