Skip to content

Commit

Permalink
[PLT-1263] Add a cookie-csrf-per-request-limit attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
unai-ttxu committed Dec 11, 2024
1 parent 8c54e91 commit 9c4de61
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/cookies/csrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type csrf struct {

cookieOpts *options.Cookie
time clock.Clock
creationTime time.Time
}

// csrtStateTrim will indicate the length of the state trimmed for the name of the csrf cookie
Expand All @@ -70,6 +71,7 @@ func NewCSRF(opts *options.Cookie, codeVerifier string) (CSRF, error) {
CodeVerifier: codeVerifier,

cookieOpts: opts,
creationTime: time.Now(),
}, nil
}

Expand Down Expand Up @@ -176,7 +178,7 @@ func ClearExtraCsrfCookies(opts *options.Cookie, rw http.ResponseWriter, req *ht
}

sort.Slice(decodedCookies, func(i, j int) bool {
return decodedCookies[i].time.Before(decodedCookies[j].time)
return decodedCookies[i].creationTime.Before(decodedCookies[j].creationTime)
})

numberToDelete := len(decodedCookies) - opts.CSRFPerRequestLimit
Expand Down

0 comments on commit 9c4de61

Please sign in to comment.