Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/whats_new.md
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,8 @@ We've added support for `zstd` compression on top of `gzip`, `deflate`, and `bro

The `Expiration` field in the CSRF middleware configuration has been renamed to `IdleTimeout` to better describe its functionality. Additionally, the default value has been reduced from 1 hour to 30 minutes.

The `ContextKey` field has been removed. Tokens and handlers are now stored using unexported keys; retrieve them with `csrf.TokenFromContext(c)` or `csrf.HandlerFromContext(c)`.

### EncryptCookie

Added support for specifying key length when using `encryptcookie.GenerateKey(length)`. Keys must be base64-encoded and may be 16, 24, or 32 bytes when decoded, supporting AES-128, AES-192, and AES-256 (default).
Expand Down Expand Up @@ -2107,6 +2109,13 @@ app.Use(csrf.New(csrf.Config{
}))
```

- **ContextKey Removal**: The `ContextKey` field has been removed from the CSRF middleware configuration. Access the token and handler using helper functions instead:

```go
token := csrf.TokenFromContext(c)
handler := csrf.HandlerFromContext(c)
```
Comment on lines +2112 to +2117

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with other migration points in this section, consider providing a Before and After example. This would make it clearer to users what the new helper functions replace.

Here is a suggested replacement for lines 2112-2117:

- **ContextKey Removal**: The `ContextKey` field has been removed from the CSRF middleware configuration. Use the new helper functions to access the token and handler from the context instead of `c.Locals()`.

  **Before:**
  ```go
  // In a handler, assuming default ContextKey "csrf"
  token := c.Locals("csrf")

After:

// In a handler
token := csrf.TokenFromContext(c)
handler := csrf.HandlerFromContext(c)


- **Session Key Removal**: The `SessionKey` field has been removed from the CSRF middleware configuration. The session key is now an unexported constant within the middleware to avoid potential key collisions in the session store.

- **KeyLookup Field Removal**: The `KeyLookup` field has been removed from the CSRF middleware configuration. This field was deprecated and is no longer needed as the middleware now uses a more secure approach for token management.
Expand Down