From 7f54e17bf4dc9d465e0515d96cc068eaf85c5016 Mon Sep 17 00:00:00 2001 From: NanamiAdmin Date: Fri, 27 Feb 2026 23:13:15 +0800 Subject: [PATCH] fix(auth): skip timestamp validation in debug mode Modify ValidateTimeStamp to bypass validation when in debug mode. Also update request validation to make timestamp optional in debug mode while maintaining security checks in production. --- auth.go | 5 ++++- handlers.go | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/auth.go b/auth.go index 37ca10f..e8c4704 100644 --- a/auth.go +++ b/auth.go @@ -170,8 +170,11 @@ func isValidPassword(password string) bool { } func ValidateTimeStamp(timeStamp int64) error { + if globalConfig.Debug { + return nil + } currentTime := time.Now().UnixMilli() - if !globalConfig.Debug && (currentTime-timeStamp > 3000 || timeStamp-currentTime > 3000) { + if currentTime-timeStamp > 3000 || timeStamp-currentTime > 3000 { return errors.New("timestamp out of valid range") } return nil diff --git a/handlers.go b/handlers.go index 6f7a800..0de4608 100644 --- a/handlers.go +++ b/handlers.go @@ -220,12 +220,14 @@ func ValidateRequestWithBody(w http.ResponseWriter, r *http.Request, body []byte return 0, "", errors.New("token is required") } - timeStamp, ok := reqMap["timeStamp"].(float64) - if !ok { + timeStamp := int64(0) + if ts, ok := reqMap["timeStamp"].(float64); ok { + timeStamp = int64(ts) + } else if !globalConfig.Debug { return 0, "", errors.New("timeStamp is required") } - if err := ValidateTimeStamp(int64(timeStamp)); err != nil { + if err := ValidateTimeStamp(timeStamp); err != nil { return 0, "", err }