Bezbednost: ispravka otvorene redirekcije (open redirect)
- 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
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -282,11 +283,13 @@ 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)
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user