Bezbednost: open redirect i kolačići bez Secure atributa

- _next parametar: sanitizacija preko url.Parse (Host+Scheme prazan = relativan URL)
umesto ručnog string check-a koji CodeQL nije prepoznavao
- Kolačići: dodat Secure atribut (true u produkciji, false u razvoju)
na 4 mesta: ntech_sesija brisanje (auth.go, prijava.go),
ntech_flash_greska postavljanje i brisanje (auth.go, dashboard.go)
This commit is contained in:
2026-06-16 03:32:07 +02:00
parent 3054041257
commit 18dd2fc460
4 changed files with 30 additions and 16 deletions
+7 -2
View File
@@ -7,6 +7,7 @@ import (
"io"
"log/slog"
"net/http"
"net/url"
"os"
"path/filepath"
"regexp"
@@ -264,8 +265,12 @@ func (h *Handler) SacuvajPodesavanja(w http.ResponseWriter, r *http.Request) {
}
sledeci := "/podesavanja"
if next := r.FormValue("_next"); strings.HasPrefix(next, "/") && (len(next) == 1 || (next[1] != '/' && next[1] != '\\')) {
sledeci = next
if next := r.FormValue("_next"); next != "" {
if u, err := url.Parse(next); err == nil && u.Host == "" && u.Scheme == "" {
if p := u.RequestURI(); p != "" {
sledeci = p
}
}
}
// backup podešavanja — pri neispravnom unosu javljamo jasnu grešku