Исправления в ветке main

This commit is contained in:
2025-11-09 14:45:56 +06:00
parent 731784b420
commit 8348cac2aa
11 changed files with 194 additions and 17 deletions

View File

@@ -3,6 +3,7 @@ package serve
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"html/template"
"net/http"
@@ -92,6 +93,7 @@ func RenderLoginPage(w http.ResponseWriter, data LoginPageData) error {
func getSessionID(r *http.Request) string {
// Пытаемся получить из cookie
if cookie, err := r.Cookie("session_id"); err == nil {
fmt.Printf("[CSRF DEBUG] SessionID получен из cookie: %s\n", cookie.Value)
return cookie.Value
}
@@ -99,7 +101,12 @@ func getSessionID(r *http.Request) string {
ip := r.RemoteAddr
userAgent := r.Header.Get("User-Agent")
fmt.Printf("[CSRF DEBUG] SessionID не найден в cookie. Генерация нового на основе IP=%s, User-Agent (первые 50 символов): %s...\n",
ip, safeSubstring(userAgent, 0, 50))
// Создаем простой хеш для сессии
hash := sha256.Sum256([]byte(ip + userAgent))
return hex.EncodeToString(hash[:])[:16]
sessionID := hex.EncodeToString(hash[:])[:16]
fmt.Printf("[CSRF DEBUG] Сгенерирован SessionID: %s\n", sessionID)
return sessionID
}