From b7521777cdcd161f2eb9e1a664c4d0e28eefd0da Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Thu, 25 Sep 2025 15:42:15 -0700 Subject: Hard-code the redirect path We can add back all that garbage when it's necessary --- roseh.moe.go | 42 +++++------------------------------------- templates/login.html.template | 1 - 2 files changed, 5 insertions(+), 38 deletions(-) diff --git a/roseh.moe.go b/roseh.moe.go index bcadd3e..0c7003f 100644 --- a/roseh.moe.go +++ b/roseh.moe.go @@ -19,7 +19,6 @@ import ( "net/http" "os" "path/filepath" - "strconv" "strings" "sync" "time" @@ -208,30 +207,6 @@ func cookieAuth(w http.ResponseWriter, r *http.Request) (string, bool) { return csrfToken, true } -type redirectPath int - -const ( - redirectInvalid redirectPath = iota - redirectNotepad -) - -func parseRedirectPath(formVal string) redirectPath { - i, err := strconv.Atoi(formVal) - if err != nil { - return redirectInvalid - } - return redirectPath(i) -} - -func (r redirectPath) Path() (string, bool) { - switch r { - case redirectNotepad: - return "/notepad", true - default: - return "", false - } -} - var ( //go:embed templates/login.html.template loginString string @@ -239,24 +214,17 @@ var ( ) type loginTemplateArgs struct { - Error bool - Redirect redirectPath + Error bool } func login(w http.ResponseWriter, r *http.Request) { - redirectPathEnum := parseRedirectPath(r.FormValue("redirect")) - redirectPath, ok := redirectPathEnum.Path() - if !ok { - http.Error(w, "Invalid redirect path", http.StatusBadRequest) - return - } key, pwHash, err := pwhash.Hash(r.FormValue("password"), notepadPasswordSalt) if err != nil { http.Error(w, fmt.Sprintf("Unable to hash password: %s", err), http.StatusInternalServerError) return } if subtle.ConstantTimeCompare(pwHash[:], notepadPassword) == 0 { - if err := loginTemplate.Execute(w, loginTemplateArgs{Error: true, Redirect: redirectPathEnum}); err != nil { + if err := loginTemplate.Execute(w, loginTemplateArgs{Error: true}); err != nil { log.Printf("Warning: login: %s", err) } return @@ -267,7 +235,7 @@ func login(w http.ResponseWriter, r *http.Request) { } encryptionKeyMu.Unlock() attachCookie(w) - http.Redirect(w, r, redirectPath, http.StatusSeeOther) + http.Redirect(w, r, "/notepad", http.StatusSeeOther) } func readNotepad(key []byte) (string, error) { @@ -304,7 +272,7 @@ type notepadTemplateArgs struct { func notepad(w http.ResponseWriter, r *http.Request) { csrfToken, ok := cookieAuth(w, r) if !ok { - if err := loginTemplate.Execute(w, loginTemplateArgs{Redirect: redirectNotepad}); err != nil { + if err := loginTemplate.Execute(w, loginTemplateArgs{}); err != nil { log.Printf("Warning: login: %s", err) } return @@ -313,7 +281,7 @@ func notepad(w http.ResponseWriter, r *http.Request) { key := encryptionKey encryptionKeyMu.Unlock() if key == nil { - if err := loginTemplate.Execute(w, loginTemplateArgs{Redirect: redirectNotepad}); err != nil { + if err := loginTemplate.Execute(w, loginTemplateArgs{}); err != nil { log.Printf("Warning: login: %s", err) } return diff --git a/templates/login.html.template b/templates/login.html.template index 696defe..0cf3469 100644 --- a/templates/login.html.template +++ b/templates/login.html.template @@ -7,6 +7,5 @@
-
-- cgit v1.3.1