mirror of
https://github.com/Rayzggz/server_torii.git
synced 2025-06-19 21:51:20 +08:00
fix: clearance failure caused by UA changes
This commit is contained in:
@ -12,6 +12,7 @@ import (
|
||||
"server_torii/internal/action"
|
||||
"server_torii/internal/config"
|
||||
"server_torii/internal/dataType"
|
||||
"server_torii/internal/utils"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@ -96,7 +97,7 @@ func CheckCaptcha(r *http.Request, reqData dataType.UserRequest, ruleSet *config
|
||||
func GenClearance(reqData dataType.UserRequest, ruleSet config.RuleSet) []byte {
|
||||
timeNow := time.Now().Unix()
|
||||
mac := hmac.New(sha512.New, []byte(ruleSet.CAPTCHARule.SecretKey))
|
||||
mac.Write([]byte(fmt.Sprintf("%d%s%sCAPTCHA-CLEARANCE", timeNow, reqData.Host, reqData.UserAgent)))
|
||||
mac.Write([]byte(fmt.Sprintf("%d%s%sCAPTCHA-CLEARANCE", timeNow, reqData.Host, utils.GetClearanceUserAgent(reqData.UserAgent))))
|
||||
return []byte(fmt.Sprintf("%s:%s", fmt.Sprintf("%d", time.Now().Unix()), fmt.Sprintf("%x", mac.Sum(nil))))
|
||||
}
|
||||
|
||||
@ -123,7 +124,7 @@ func verifyClearanceCookie(reqData dataType.UserRequest, ruleSet config.RuleSet)
|
||||
}
|
||||
|
||||
mac := hmac.New(sha512.New, []byte(ruleSet.CAPTCHARule.SecretKey))
|
||||
mac.Write([]byte(fmt.Sprintf("%d%s%sCAPTCHA-CLEARANCE", parsedTimestamp, reqData.Host, reqData.UserAgent)))
|
||||
mac.Write([]byte(fmt.Sprintf("%d%s%sCAPTCHA-CLEARANCE", parsedTimestamp, reqData.Host, utils.GetClearanceUserAgent(reqData.UserAgent))))
|
||||
computedHash := fmt.Sprintf("%x", mac.Sum(nil))
|
||||
|
||||
return hmac.Equal([]byte(computedHash), []byte(expectedHash))
|
||||
|
Reference in New Issue
Block a user