summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÖzgür Kesim <oec@codeblau.de>2025-08-19 18:16:30 +0200
committerÖzgür Kesim <oec@codeblau.de>2025-08-19 18:16:30 +0200
commit52d9e3420c521f6b785bc17826f1770f982c2662 (patch)
tree31feeec3b4c43f0790ce6c729fac46aae038d006
parent76bf01bc10a5d0335db240cb1055a934ac6583ea (diff)
add referer checkmain
-rw-r--r--genesungswuensche.go17
1 files changed, 13 insertions, 4 deletions
diff --git a/genesungswuensche.go b/genesungswuensche.go
index dc526b6..68fd81b 100644
--- a/genesungswuensche.go
+++ b/genesungswuensche.go
@@ -924,7 +924,7 @@ func (s *Server) markReadHandler(w http.ResponseWriter, r *http.Request) {
}
fmt.Println(r.Header.Get("X-Forwarded-For"),
- "mark read success from",
+ "mark read from",
sourcePath, "to", destPath)
w.Header().Set("Content-Type", "application/json")
@@ -992,7 +992,7 @@ func (s *Server) markUnreadHandler(w http.ResponseWriter, r *http.Request) {
return
}
fmt.Println(r.Header.Get("X-Forwarded-For"),
- "unread success from",
+ "mark unread from",
sourcePath, "to", destPath)
w.Header().Set("Content-Type", "application/json")
@@ -1011,7 +1011,16 @@ func auth(handler http.HandlerFunc) http.HandlerFunc {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
return
}
+ handler(w, r)
+ }
+}
+func referer(handler http.HandlerFunc) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ if r.Referer() != "https://www.codeblau.de/genesung/" {
+ http.Error(w, "CSRF!?", http.StatusBadRequest)
+ return
+ }
handler(w, r)
}
}
@@ -1034,8 +1043,8 @@ func main() {
}
http.HandleFunc("/", auth(server.indexHandler))
- http.HandleFunc("/genesung/api/mark-read", auth(server.markReadHandler))
- http.HandleFunc("/genesung/api/mark-unread", auth(server.markUnreadHandler))
+ http.HandleFunc("/genesung/api/mark-read", auth(referer(server.markReadHandler)))
+ http.HandleFunc("/genesung/api/mark-unread", auth(referer(server.markUnreadHandler)))
fmt.Printf("Starting server on http://localhost:%s\n", port)
fmt.Printf("Serving emails from: %s\n", maildirPath)