Skip to content

Commit 9ec4fb9

Browse files
committed
refactor(server): separate challenge exact-timestamp and skew checks
The previous condition conflated three distinct failures under one "challenge timestamp mismatch" message. Split it into: 1) message timestamp != challenge create timestamp, and 2) valid exact match but outside allowed skew. Both still map to HTTP 400. Copilot review on #402.
1 parent a551dd2 commit 9ec4fb9

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

model/wallet_auth_challenge_model.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,17 @@ func UseWalletAuthChallenge(
271271
return
272272
}
273273

274-
if messageTime.Before(createTime.Add(-WalletAuthChallengeSkewPast)) ||
275-
messageTime.After(createTime.Add(WalletAuthChallengeSkewFuture)) ||
276-
messageTime.Unix() != createTime.Unix() {
274+
// The message must be the exact one issued for this challenge.
275+
if messageTime.Unix() != createTime.Unix() {
277276
err = errors.New("challenge timestamp mismatch")
278277
return
279278
}
279+
// Then allow small clock skew relative to challenge creation time.
280+
if messageTime.Before(createTime.Add(-WalletAuthChallengeSkewPast)) ||
281+
messageTime.After(createTime.Add(WalletAuthChallengeSkewFuture)) {
282+
err = errors.New("challenge timestamp outside allowed skew")
283+
return
284+
}
280285

281286
if used {
282287
err = errors.New("challenge already used")
@@ -308,7 +313,7 @@ func UseWalletAuthChallenge(
308313
switch err.Error() {
309314
case "challenge already used", "challenge expired":
310315
code = "403"
311-
case "challenge timestamp mismatch":
316+
case "challenge timestamp mismatch", "challenge timestamp outside allowed skew":
312317
code = "400"
313318
}
314319
return &UseWalletAuthChallengeResult{

0 commit comments

Comments
 (0)