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

Language switching and connection test do not work on ipv6.internet.nl #1489

Open
baknu opened this issue Aug 26, 2024 · 1 comment · May be fixed by #1580
Open

Language switching and connection test do not work on ipv6.internet.nl #1489

baknu opened this issue Aug 26, 2024 · 1 comment · May be fixed by #1580
Assignees

Comments

@baknu
Copy link
Contributor

baknu commented Aug 26, 2024

  1. When on ipv6.internet.nl clicking on "English" or "Nederlands" does not work.
    Note that the target domains en.ipv6.internet.nl and nl.ipv6.internet.nl actually work.
  2. The connection test does not work on ipv6.internet.nl (and also not on nl.ipv6.internet.nl and en.ipv6.internet.nl).
@baknu baknu changed the title Language switching does not work on ipv6.internet.nl Language switching and connection test do not work on ipv6.internet.nl Aug 26, 2024
@bwbroersma
Copy link
Collaborator

bwbroersma commented Dec 3, 2024

  1. It's an python issue:
    $ curl -sSf 'https://nl.ipv6.internet.nl/change_language/' -d 'language=en' -i | grep -i location
    location: /
    $ curl -sSf 'https://nl.internet.nl/change_language/' -d 'language=en' -i | grep -i location
    location: https://en.internet.nl/
    BTW Somehow the csrfmiddlewaretoken is not needed.
  2. Is fixed by Cleanup nginx conf #1565
    You can test it on http://nl.ipv6.dev-docker.internet.nl/ and http://ipv6.dev-docker.internet.nl/.

This code fails if there is ipv6:

known_languages = [language[0] for language in settings.LANGUAGES]
if new_language and new_language in known_languages:
url_regex = re.compile("^(?P<protocol>http[s]?://).*$")
uri = request.build_absolute_uri()
protocol = url_regex.match(uri).group("protocol")
# If the previous language is in the host remove it.
# Also if the hostname starts with 'www.' (may appear in the
# default language site) remove it so that the language prefix gets
# applied to the domain name.
previous_language = hostname.split(".", 1)[0]
if previous_language in known_languages or previous_language == "www":
no_language_host = request.get_host().replace(previous_language + ".", "", 1)
else:
no_language_host = request.get_host()
language_prefix = new_language + "."
redirect_url = protocol + language_prefix + no_language_host + previous_page
else:
redirect_url = previous_page
try:
return SafeHttpResponseRedirect(redirect_url)
except DisallowedRedirect as exc:
logging.info(f"Rejected redirect: {exc}")
return HttpResponseRedirect("/")

Problem is here:

class SafeHttpResponseRedirect(HttpResponseRedirect):
"""
This light wrapper around HttpResponseRedirect refuses redirects to
other hosts or schemes. It should be used for any case where part
of the URL may be based on user input.
"""
def __init__(self, redirect_to, *args, **kwargs):
super().__init__(redirect_to, *args, **kwargs)
allowed_hosts = []
for host in settings.ALLOWED_HOSTS:
allowed_hosts.append(host)
for language_code, language_name in settings.LANGUAGES:
allowed_hosts.append(language_code + host)
if not settings.DEBUG and not url_has_allowed_host_and_scheme(redirect_to, allowed_hosts=allowed_hosts):
raise DisallowedRedirect("Unsafe redirect to URL: %s" % redirect_to)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants