Skip to content
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

Remove logic for guessing slug from an unregistered domain #5143

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions readthedocs/core/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.urls.base import set_urlconf
from django.utils.deprecation import MiddlewareMixin
from django.utils.translation import ugettext_lazy as _
from django.shortcuts import render

from readthedocs.projects.models import Domain, Project

Expand Down Expand Up @@ -106,9 +107,9 @@ def process_request(self, request):
)
# Try header first, then DNS
elif not hasattr(request, 'domain_object'):
# Some person is CNAMEing to us. 404.
# Some person is CNAMEing to us without configuring a domain - 404.
log.warning(LOG_TEMPLATE.format(msg='CNAME 404', **log_kwargs))
raise Http404(_('Invalid hostname'))
return render(request, 'core/dns-404.html', context={'host': host}, status=404)
# Google was finding crazy www.blah.readthedocs.org domains.
# Block these explicitly after trying CNAME logic.
if len(domain_parts) > 3 and not settings.DEBUG:
Expand Down
43 changes: 43 additions & 0 deletions readthedocs/core/templates/core/dns-404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{% extends "base.html" %}
{% load core_tags %}
{% load i18n %}

{% block title %}
{% trans "Maze Found - Invalid Host" %}
{% endblock %}

{% block header-wrapper %}
{% include "error_header.html" %}
{% endblock %}

{% block notify %}{% endblock %}

{# Hide the language select form so we don't set a CSRF cookie #}
{% block language-select-form %}{% endblock %}


{% block content %}
<h1>{% trans '404 - Invalid Host' %}</h1>
<h3>{% blocktrans %}The host "{{ host }}" is unknown to Read the Docs{% endblocktrans %}</h3>

<p>
{% with docsurl='https://docs.readthedocs.io/en/stable/custom_domains.html' %}
{% blocktrans trimmed %}
If you control this domain and believe this is in error,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be is an error?

Suggested change
If you control this domain and believe this is in error,
If you control this domain and believe this is an error,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either works but I think yours is better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I guess is used more in other areas?

please review our <a href="{{ docsurl }}">custom domain documentation</a>.
In the past, we allowed custom domains to point to us without configuring the domain in the Read the Docs dashboard
and we attempted to intelligently guess the correct project.
This was never explicitly supported and documented. It just happened to work.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Believe it used to be documented.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can update that then

Below are some steps to help you get your domain working again:
{% endblocktrans %}
{% endwith %}
</p>


<ul style="margin-left: 2em; list-style: inherit">
<li>{% trans 'Ensure you have a CNAME record pointing to <code>readthedocs.io</code>' %}</li>
<li>{% trans 'Add your desired domain in the Read the Docs dashboard for your project (under Your Project &gt;&gt; Admin &gt;&gt; Domains)' %}</li>
</ul>


{% endblock %}