diff --git a/backend/handlers/bookings/admin_reserve.go b/backend/handlers/bookings/admin_reserve.go index 0e81a9a..fcdaee2 100644 --- a/backend/handlers/bookings/admin_reserve.go +++ b/backend/handlers/bookings/admin_reserve.go @@ -2,7 +2,7 @@ package bookings import ( "context" - "crypto/md5" + "crypto/sha256" "crussell/clock" "crussell/db" "crussell/handlers/scheduling" @@ -152,7 +152,7 @@ func AdminReserveSlotHandler(w http.ResponseWriter, r *http.Request) { ip = r.RemoteAddr } } - ipHash := fmt.Sprintf("%x", md5.Sum([]byte(ip)))[:8] + ipHash := fmt.Sprintf("%x", sha256.Sum256([]byte(ip)))[:8] if _, delErr := db.Conn.Exec(r.Context(), ` DELETE FROM time_blockers WHERE (description LIKE 'RESERVATION:admin:%' AND created_by = $1) diff --git a/backend/handlers/bookings/overlap_test.go b/backend/handlers/bookings/overlap_test.go index fd8bdd2..a27d04f 100644 --- a/backend/handlers/bookings/overlap_test.go +++ b/backend/handlers/bookings/overlap_test.go @@ -5,7 +5,7 @@ package bookings import ( "bytes" "context" - "crypto/md5" + "crypto/sha256" "encoding/json" "fmt" "net/http" @@ -1938,7 +1938,7 @@ func TestReserveSlot_CleansUpAnonReservation(t *testing.T) { // Set a known IP that the test request will use testIP := "192.0.2.1" - ipHash := fmt.Sprintf("%x", md5.Sum([]byte(testIP)))[:8] + ipHash := fmt.Sprintf("%x", sha256.Sum256([]byte(testIP)))[:8] // Create an anonymous reservation (created_by = NULL) matching this IP hash var blockerID string @@ -2139,7 +2139,7 @@ func TestAdminReserveSlot_CleansUpAnonReservation(t *testing.T) { future := weekdayTime(time.Monday, 10) testIP := "192.0.2.2" - ipHash := fmt.Sprintf("%x", md5.Sum([]byte(testIP)))[:8] + ipHash := fmt.Sprintf("%x", sha256.Sum256([]byte(testIP)))[:8] // Create an anonymous reservation matching this IP var blockerID string diff --git a/backend/handlers/bookings/reserve.go b/backend/handlers/bookings/reserve.go index 8f19ec6..daed57d 100644 --- a/backend/handlers/bookings/reserve.go +++ b/backend/handlers/bookings/reserve.go @@ -1,7 +1,7 @@ package bookings import ( - "crypto/md5" + "crypto/sha256" "encoding/json" "fmt" "log" @@ -140,7 +140,7 @@ func ReserveSlotHandler(w http.ResponseWriter, r *http.Request) { if hasAuth { // Also compute IP hash to clean up anonymous reservations // that may have been created before the user logged in. - ipHash := fmt.Sprintf("%x", md5.Sum([]byte(ip)))[:8] + ipHash := fmt.Sprintf("%x", sha256.Sum256([]byte(ip)))[:8] if _, delErr := db.Conn.Exec(r.Context(), ` DELETE FROM time_blockers WHERE (created_by = $1 AND description LIKE 'RESERVATION:user:%') @@ -245,7 +245,7 @@ func ReserveSlotHandler(w http.ResponseWriter, r *http.Request) { } } else { // Calculate ipHash from IP address - ipHash := fmt.Sprintf("%x", md5.Sum([]byte(ip)))[:8] + ipHash := fmt.Sprintf("%x", sha256.Sum256([]byte(ip)))[:8] // ANONYMOUS: Use transaction for atomic rate cap + overlap check + insert tx, err := db.Conn.Begin(r.Context())