Skip to content

Commit fb65637

Browse files
committed
Revert "Remove settings that support https and disables suspicious host checking on Proxito"
This reverts commit 76cf10a.
1 parent 7cfbfa7 commit fb65637

File tree

7 files changed

+42
-12
lines changed

7 files changed

+42
-12
lines changed

dockerfiles/settings/proxito.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
from readthedocs.settings.proxito.base import CommunityProxitoSettingsMixin
24

35
from .docker_compose import DockerBaseSettings
@@ -19,5 +21,8 @@ def DEBUG_TOOLBAR_CONFIG(self):
1921
'SHOW_TOOLBAR_CALLBACK': lambda request: False,
2022
}
2123

24+
if os.environ.get("RTD_FORCE_HTTPS"):
25+
PROXITO_DEV_DISABLE_SUSPICIOUS_HOST_CHECK = True
26+
2227

2328
ProxitoDevSettings.load_settings(__name__)

docs/dev/install.rst

+2-3
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ save some work while typing docker compose commands. This section explains these
115115
* ``--no-reload`` makes all celery processes and django runserver
116116
to use no reload and do not watch for files changes
117117
* ``--no-django-debug`` runs all containers with ``DEBUG=False``
118-
* ``--http-domain`` configures an external domain for the environment (useful for Ngrok or other http proxy).
119-
Note that https proxies aren't supported.
120-
There will also be issues with "suspicious domain" failures on Proxito.
118+
* ``--http-domain`` configures an external domain for the environment (useful for Ngrok or other https proxy)
119+
* ``--https`` if using an HTTPS proxy, you may need to force the ``https://`` protocol for settings that otherwise automatically detect it as ``http://``
121120
* ``--ext-theme`` to use the new dashboard templates
122121
* ``--webpack`` to start the Webpack dev server for the new dashboard templates
123122

readthedocs/core/unresolver.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -485,11 +485,12 @@ def unresolve_domain(self, domain):
485485
log.info("Invalid format of external versions domain.", domain=domain)
486486
raise InvalidExternalDomainError(domain=domain)
487487

488-
if public_domain in domain or external_domain in domain:
489-
# NOTE: This can catch some possibly valid domains (docs.readthedocs.io.com)
490-
# for example, but these might be phishing, so let's block them for now.
491-
log.warning("Weird variation of our domain.", domain=domain)
492-
raise SuspiciousHostnameError(domain=domain)
488+
if not getattr(settings, "PROXITO_DEV_DISABLE_SUSPICIOUS_HOST_CHECK", False):
489+
if public_domain in domain or external_domain in domain:
490+
# NOTE: This can catch some possibly valid domains (docs.readthedocs.io.com)
491+
# for example, but these might be phishing, so let's block them for now.
492+
log.warning("Weird variation of our domain.", domain=domain)
493+
raise SuspiciousHostnameError(domain=domain)
493494

494495
# Custom domain.
495496
domain_object = (

readthedocs/settings/base.py

+2
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,8 @@ def DOCKER_LIMITS(self):
10581058
RTD_SPAM_THRESHOLD_DELETE_PROJECT = 1000
10591059
RTD_SPAM_MAX_SCORE = 9999
10601060

1061+
PROXITO_DEV_DISABLE_SUSPICIOUS_HOST_CHECK = False
1062+
10611063
CACHEOPS_ENABLED = False
10621064
CACHEOPS_TIMEOUT = 60 * 60 # seconds
10631065
CACHEOPS_OPS = {'get', 'fetch'}

readthedocs/settings/docker_compose.py

+16
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class DockerBaseSettings(CommunityBaseSettings):
3232
# In the local docker environment, nginx should be trusted to set the host correctly
3333
USE_X_FORWARDED_HOST = True
3434

35+
# Assume running on forwarded https
36+
if os.environ.get("RTD_FORCE_HTTPS"):
37+
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
38+
3539
MULTIPLE_BUILD_SERVERS = ['build']
3640

3741
# https://docs.docker.com/engine/reference/commandline/run/#add-entries-to-container-hosts-file---add-host
@@ -152,6 +156,12 @@ def DATABASES(self): # noqa
152156

153157
ACCOUNT_EMAIL_VERIFICATION = "none"
154158

159+
# Assume running on forwarded https, needs a special option for socialauth because
160+
# it detects HTTPS from the request automatically, and we may be running the app
161+
# on :80 behind a :443 proxy.
162+
if os.environ.get("RTD_FORCE_HTTPS"):
163+
ACCOUNT_DEFAULT_HTTP_PROTOCOL = "https"
164+
155165
SESSION_COOKIE_DOMAIN = None
156166
CACHES = {
157167
'default': {
@@ -196,6 +206,12 @@ def DATABASES(self): # noqa
196206
AWS_S3_ENDPOINT_URL = 'http://storage:9000/'
197207
AWS_QUERYSTRING_AUTH = False
198208

209+
# Force the protocol for generated URLs to be https://, otherwise
210+
# http:// is used because the storage server is running in a http
211+
# container.
212+
if os.environ.get("RTD_FORCE_HTTPS"):
213+
S3_STATIC_STORAGE_OVERRIDE_PROTOCOL = "https"
214+
199215
RTD_SAVE_BUILD_COMMANDS_TO_STORAGE = True
200216
RTD_BUILD_COMMANDS_STORAGE = 'readthedocs.storage.s3_storage.S3BuildCommandsStorage'
201217
BUILD_COLD_STORAGE_URL = 'http://storage:9000/builds'

readthedocs/storage/mixins.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,29 @@
66
class OverrideHostnameMixin:
77

88
"""
9-
Override the hostname when outputting URLs.
9+
Override the hostname or protocol when outputting URLs.
1010
1111
This is useful for use with a CDN or when proxying outside of Blob Storage
1212
1313
See: https://github.com/jschneier/django-storages/pull/658
1414
"""
1515

1616
override_hostname = (
17-
None # Just the hostname without scheme (eg. 'assets.readthedocs.org')
17+
None # use the hostname without scheme (eg. 'assets.readthedocs.org')
18+
)
19+
override_protocol = (
20+
None # set to "http" or "https". None = inherit automatic setting.
1821
)
1922

2023
def url(self, *args, **kwargs):
2124
url = super().url(*args, **kwargs)
2225

23-
if self.override_hostname:
26+
if self.override_hostname or self.override_protocol:
2427
parts = list(urlsplit(url))
25-
parts[1] = self.override_hostname
28+
if self.override_protocol:
29+
parts[0] = self.override_protocol
30+
if self.override_hostname:
31+
parts[1] = self.override_hostname
2632
url = urlunsplit(parts)
2733

2834
return url

readthedocs/storage/s3_storage.py

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class S3StaticStorageMixin:
7979

8080
bucket_name = getattr(settings, "S3_STATIC_STORAGE_BUCKET", None)
8181
override_hostname = getattr(settings, "S3_STATIC_STORAGE_OVERRIDE_HOSTNAME", None)
82+
override_protocol = getattr(settings, "S3_STATIC_STORAGE_OVERRIDE_PROTOCOL", None)
8283

8384
def __init__(self, *args, **kwargs):
8485
super().__init__(*args, **kwargs)

0 commit comments

Comments
 (0)