Skip to content

Commit

Permalink
fix: ignore more cloudflare cookies (#3499)
Browse files Browse the repository at this point in the history
  • Loading branch information
alnr authored Sep 14, 2023
1 parent 159c131 commit f124ab5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion selfservice/flow/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ func EnsureCSRF(
}

// Workaround for Cloudflare setting cookies that we can't control.
// https://developers.cloudflare.com/fundamentals/reference/policies-compliances/cloudflare-cookies/
var cookies []string
for _, c := range r.Cookies() {
if !strings.HasPrefix(c.Name, "__cf") {
if !(strings.HasPrefix(c.Name, "__cf") || strings.HasPrefix(c.Name, "_cf") || strings.HasPrefix(c.Name, "cf_")) {
cookies = append(cookies, c.Name)
}
}
Expand Down
2 changes: 1 addition & 1 deletion selfservice/flow/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestVerifyRequest(t *testing.T) {

// Cloudflare
require.NoError(t, flow.EnsureCSRF(reg, &http.Request{
Header: http.Header{"Cookie": {"__cflb=0pg1RtZzPoPDprTf8gX3TJm8XF5hKZ4pZV74UCe7"}},
Header: http.Header{"Cookie": {"__cflb=0pg1RtZzPoPDprTf8gX3TJm8XF5hKZ4pZV74UCe7", "_cfuvid=blub", "cf_clearance=bla"}},
}, flow.TypeAPI, false, x.FakeCSRFTokenGenerator, ""), "should ignore Cloudflare cookies")
require.NoError(t, flow.EnsureCSRF(reg, &http.Request{
Header: http.Header{"Cookie": {"__cflb=0pg1RtZzPoPDprTf8gX3TJm8XF5hKZ4pZV74UCe7; __cfruid=0pg1RtZzPoPDprTf8gX3TJm8XF5hKZ4pZV74UCe7"}},
Expand Down

0 comments on commit f124ab5

Please sign in to comment.