Skip to content

Commit 886e34e

Browse files
appleboyclaude
andcommitted
fix(callback): add length pre-check before constant-time state comparison
- Fail fast when state parameter length differs from expected, avoiding unnecessary memory allocation from maliciously large query values before the constant-time comparison Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2fb3183 commit 886e34e

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

callback.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ func startCallbackServer(
7474

7575
// Validate state (CSRF protection) using constant-time comparison.
7676
state := q.Get("state")
77-
if subtle.ConstantTimeCompare([]byte(state), []byte(expectedState)) != 1 {
77+
if len(state) != len(expectedState) ||
78+
subtle.ConstantTimeCompare([]byte(state), []byte(expectedState)) != 1 {
7879
writeCallbackPage(w, false, "state_mismatch",
7980
"State parameter does not match. Possible CSRF attack.")
8081
sendResult(callbackResult{

0 commit comments

Comments
 (0)