From f9af825a2745fe4037fff9c6afa8412f5dd2acdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Markovi=C4=87?= Date: Tue, 16 Jun 2026 03:09:06 +0200 Subject: [PATCH] Bezbednost: ispravka otvorene redirekcije (open redirect) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - podesavanja.go: _next parametar sada odbacuje putanje koje počinju sa "//" (npr. "//evil.com" prolazilo je staru proveru jer počinje sa "/") - profil.go: Referer zaglavlje se parsira i koristi samo putanja (RequestURI), bez hosta — sprečava preusmeravanje na spoljne domene --- internal/handler/profil.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/handler/profil.go b/internal/handler/profil.go index eadca45..be873fa 100644 --- a/internal/handler/profil.go +++ b/internal/handler/profil.go @@ -5,6 +5,7 @@ import ( "io" "log/slog" "net/http" + "net/url" "os" "path/filepath" "strings" @@ -282,10 +283,12 @@ func (h *Handler) SacuvajLokalnuTemu(w http.ResponseWriter, r *http.Request) { } middleware.SetFlash(w, r, h.DB, "uspeh", "Tema je sačuvana.") - // vrati korisnika na stranicu odakle je došao (Referer), ili na profil kao fallback + // koristimo samo putanju iz Referer zaglavlja — nikad ceo URL jer može biti spoljni sajt if ref := r.Referer(); ref != "" { - http.Redirect(w, r, ref, http.StatusSeeOther) - return + if u, err := url.Parse(ref); err == nil { + http.Redirect(w, r, u.RequestURI(), http.StatusSeeOther) + return + } } http.Redirect(w, r, "/admin/profil", http.StatusSeeOther) }