From b742606c3d809108af7da2937e72db8ccbdff0cb Mon Sep 17 00:00:00 2001 From: Claire Date: Sat, 18 Dec 2021 23:32:02 +0100 Subject: [PATCH] Update design and highlight proxy misconfiguration using javascript --- app/views/errors/blocked_host.html.haml | 50 ++++++++++++++++++--- app/views/layouts/anonymous_error.html.haml | 16 +++++++ 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/app/views/errors/blocked_host.html.haml b/app/views/errors/blocked_host.html.haml index 698d4edb937..99ac88c1329 100644 --- a/app/views/errors/blocked_host.html.haml +++ b/app/views/errors/blocked_host.html.haml @@ -2,17 +2,57 @@ Blocked host: = host +- content_for :header_tags do + :javascript + document.addEventListener('DOMContentLoaded', function() { + const expected_host = #{json_escape(host.to_json)}; + + if (window.location.hostname !== expected_host) { + const p1 = document.getElementById('reverse-proxy'); + const p2 = document.getElementById('env-variables'); + const parent = p1.parentNode; + + // Swap both paragraphs + parent.removeChild(p1); + parent.insertBefore(p1, p2); + + // Replace start of paragraph with more affirmative content + const newPrelude = document.createElement('span'); + newPrelude.appendChild(document.createTextNode('If you are the server administrator and ')); + const c1 = document.createElement('code'); + c1.appendChild(document.createTextNode(expected_host)); + newPrelude.appendChild(c1); + newPrelude.appendChild(document.createTextNode(' is not the intended domain name but ')); + const c2 = document.createElement('code'); + c2.appendChild(document.createTextNode(window.location.hostname)); + newPrelude.appendChild(c2); + newPrelude.appendChild(document.createTextNode(' is, then your reverse-proxy is almost certainly misconfigured. Check')); + + const prelude = document.getElementById('reverse-proxy-prelude'); + prelude.parentNode.replaceChild(newPrelude, prelude); + + // Remove duplicate prelude + const prelude2 = document.getElementById('env-variables-prelude'); + prelude2.parentNode.removeChild(prelude2); + } + }); + - content_for :content do :plain -

Blocked host: #{host}

+

Blocked host: #{host}

- It appears you have tried accessing your Mastodon server using a different name (#{host}) than defined in the LOCAL_DOMAIN - and WEB_DOMAIN environment variables. + It appears you have tried accessing this Mastodon server using a different name (#{host}) than defined in its configuration. + If you are a user of this server, try reaching out to a server administrator.

-

- If that's not the case, check your reverse-proxy configuration to ensure it properly sets the Host header. +

+ If you are the server administrator and #{host} is the intended domain name for this server, please check the LOCAL_DOMAIN + and WEB_DOMAIN environment variables for typos or other errors. +

+ +

+ If #{host} is not the intended domain name for your server, please check your reverse-proxy configuration to ensure it properly sets the Host header.

diff --git a/app/views/layouts/anonymous_error.html.haml b/app/views/layouts/anonymous_error.html.haml index 2561dcb2f82..5d9d2325fbc 100644 --- a/app/views/layouts/anonymous_error.html.haml +++ b/app/views/layouts/anonymous_error.html.haml @@ -22,6 +22,20 @@ font-size: 14px; } + body.error .dialog { + padding: 20px; + max-width: 960px; + } + + body.error .dialog code { + font-size: .85em; + background: #17191f; + border-radius: 4px; + padding: .2em .3em; + font-family: monospace; + font-weight: 400; + } + body.error .dialog h1 { text-align: center; font-size: 20px; @@ -29,6 +43,8 @@ font-weight: 400; } + = yield :header_tags + %body.error .dialog .dialog__message= yield :content