summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2025-11-15 09:26:26 -0800
committerRose Hogenson <rosehogenson@posteo.net>2025-11-15 09:26:26 -0800
commit2a489c6760852e135812062617d67ad4776db1a1 (patch)
tree5f9ad3ea09d2f62a3e21c3b5f1ddd6caf73709c0
parente3c4636772547507448146e04c71de657a5d4105 (diff)
downloadroseh.moe-2a489c6760852e135812062617d67ad4776db1a1.tar.zst
Fix cross-domain login
-rw-r--r--roseh.moe.go14
-rw-r--r--templates/login.html.template2
2 files changed, 10 insertions, 6 deletions
diff --git a/roseh.moe.go b/roseh.moe.go
index 2576627..1f9a9f2 100644
--- a/roseh.moe.go
+++ b/roseh.moe.go
@@ -447,14 +447,17 @@ var (
)
type loginTemplateArgs struct {
- SelfURL string
Redirect string
Error bool
}
-func executeLoginTemplate(w io.Writer, redirect string) {
+func redirectLogin(w http.ResponseWriter, r *http.Request, redirect string) {
redirect += base64.RawURLEncoding.EncodeToString(mac([]byte(redirect)))
- if err := loginTemplate.Execute(w, loginTemplateArgs{SelfURL: *selfURL, Redirect: redirect}); err != nil {
+ http.Redirect(w, r, *selfURL+"/login?redirect="+url.QueryEscape(redirect), http.StatusFound)
+}
+
+func serveLogin(w http.ResponseWriter, r *http.Request) {
+ if err := loginTemplate.Execute(w, loginTemplateArgs{Redirect: r.FormValue("redirect")}); err != nil {
log.Printf("Warning: login: %s", err)
}
}
@@ -509,7 +512,7 @@ type notepadTemplateArgs struct {
func notepad(w http.ResponseWriter, r *http.Request) {
if !cookieAuth(w, r) {
- executeLoginTemplate(w, "/notepad")
+ redirectLogin(w, r, "/notepad")
return
}
notepadContentsMu.Lock()
@@ -586,7 +589,7 @@ type jellyfinReverseProxy struct {
func (p *jellyfinReverseProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if !cookieAuth(w, r) {
- executeLoginTemplate(w, "https://cinema.rose.moe")
+ redirectLogin(w, r, "https://cinema.rose.moe")
return
}
p.proxy.ServeHTTP(w, r)
@@ -605,6 +608,7 @@ func main() {
http.HandleFunc("POST /wormhole/{hole}/upload", wormholeSend)
http.HandleFunc("GET /wormhole/{hole}", wormholeRecv)
http.HandleFunc("GET /wormhole/{hole}/qr.png", wormholeQR)
+ http.HandleFunc("GET /login", serveLogin)
http.HandleFunc("POST /login", login)
http.HandleFunc("GET /notepad", notepad)
http.HandleFunc("POST /notepad", autosave)
diff --git a/templates/login.html.template b/templates/login.html.template
index 368e099..8d1ec9b 100644
--- a/templates/login.html.template
+++ b/templates/login.html.template
@@ -4,7 +4,7 @@
{{if .Error}}
<p class="login-error">Incorrect password</p>
{{end}}
- <form class="password-form" action="{{.SelfURL}}/login" method="post">
+ <form class="password-form" action="/login" method="post">
<input type="hidden" name="redirect" value="{{.Redirect}}">
<label class="password-label" for="password">Enter password</label>
<input id="password" class="password" type="password" name="password" autofocus>