diff options
-rw-r--r-- | http_error_page.go | 5 | ||||
-rw-r--r-- | http_server.go | 7 | ||||
-rw-r--r-- | templates/400_colon.tmpl | 26 |
3 files changed, 38 insertions, 0 deletions
diff --git a/http_error_page.go b/http_error_page.go index 85ad859..00ef04b 100644 --- a/http_error_page.go +++ b/http_error_page.go @@ -18,6 +18,11 @@ func errorPage400(w http.ResponseWriter, params map[string]any, msg string) { _ = templates.ExecuteTemplate(w, "400", params) } +func errorPage400Colon(w http.ResponseWriter, params map[string]any) { + w.WriteHeader(http.StatusBadRequest) + _ = templates.ExecuteTemplate(w, "400_colon", params) +} + func errorPage403(w http.ResponseWriter, params map[string]any, msg string) { w.WriteHeader(http.StatusForbidden) params["complete_error_msg"] = msg diff --git a/http_server.go b/http_server.go index df8f362..baddf9d 100644 --- a/http_server.go +++ b/http_server.go @@ -48,6 +48,13 @@ func (router *forgeHTTPRouter) ServeHTTP(writer http.ResponseWriter, request *ht segments = segments[:len(segments)-1] } + for _, v := range segments { + if strings.Contains(v, ":") { + errorPage400Colon(writer, params) + return + } + } + params["url_segments"] = segments params["dir_mode"] = dirMode params["global"] = globalData diff --git a/templates/400_colon.tmpl b/templates/400_colon.tmpl new file mode 100644 index 0000000..6d8ec25 --- /dev/null +++ b/templates/400_colon.tmpl @@ -0,0 +1,26 @@ +{{/* + SPDX-License-Identifier: AGPL-3.0-only + SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org> +*/}} +{{- define "400_colon" -}} +<!DOCTYPE html> +<html lang="en"> + <head> + {{- template "head_common" . -}} + <title>400 Bad Request – {{ .global.forge_title }}</title> + </head> + <body class="400-colon"> + {{- template "header" . -}} + <div class="padding-wrapper complete-error-page"> + <h1>400 Bad Request</h1> + <p>We recently switched URL schemes. Previously “<code>:</code>” was used as our URL group separator, but because OpenSMTPD does not implement local-part address quoting properly, we’re unable to include “<code>:</code>” in URLs properly, hence we use “<code>-</code>” now.</p> + <p>As a precaution in case visitors get confused, this page was set up. <strong>You should probably replace all “<code>:</code>”s with “<code>-</code>”s in the URL bar.</strong></p> + <hr /> + <address>Lindenii Forge</address> + </div> + <footer> + {{- template "footer" . -}} + </footer> + </body> +</html> +{{- end -}} |