Skip to content

Commit 14c91e0

Browse files
Add docs from gofiber/fiber@e3232c1
1 parent 9cacad4 commit 14c91e0

File tree

3 files changed

+460
-95
lines changed

3 files changed

+460
-95
lines changed

docs/core/middleware/csrf.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ app.Use(csrf.New(csrf.Config{
3434
KeyLookup: "header:X-Csrf-Token",
3535
CookieName: "csrf_",
3636
CookieSameSite: "Lax",
37-
Expiration: 1 * time.Hour,
37+
IdleTimeout: 30 * time.Minute,
3838
KeyGenerator: utils.UUIDv4,
3939
Extractor: func(c fiber.Ctx) (string, error) { ... },
4040
}))
@@ -106,15 +106,14 @@ func (h *Handler) DeleteToken(c fiber.Ctx) error
106106
| CookieSecure | `bool` | Indicates if the CSRF cookie is secure. | false |
107107
| CookieHTTPOnly | `bool` | Indicates if the CSRF cookie is HTTP-only. | false |
108108
| CookieSameSite | `string` | Value of SameSite cookie. | "Lax" |
109-
| CookieSessionOnly | `bool` | Decides whether the cookie should last for only the browser session. Ignores Expiration if set to true. | false |
110-
| Expiration | `time.Duration` | Expiration is the duration before the CSRF token will expire. | 1 * time.Hour |
109+
| CookieSessionOnly | `bool` | Decides whether the cookie should last for only the browser session. (cookie expires on close). | false |
110+
| IdleTimeout | `time.Duration` | IdleTimeout is the duration of inactivity before the CSRF token will expire. | 30 * time.Minute |
111111
| KeyGenerator | `func() string` | KeyGenerator creates a new CSRF token. | utils.UUID |
112112
| ErrorHandler | `fiber.ErrorHandler` | ErrorHandler is executed when an error is returned from fiber.Handler. | DefaultErrorHandler |
113113
| Extractor | `func(fiber.Ctx) (string, error)` | Extractor returns the CSRF token. If set, this will be used in place of an Extractor based on KeyLookup. | Extractor based on KeyLookup |
114114
| SingleUseToken | `bool` | SingleUseToken indicates if the CSRF token be destroyed and a new one generated on each use. (See TokenLifecycle) | false |
115115
| Storage | `fiber.Storage` | Store is used to store the state of the middleware. | `nil` |
116116
| Session | `*session.Store` | Session is used to store the state of the middleware. Overrides Storage if set. | `nil` |
117-
| SessionKey | `string` | SessionKey is the key used to store the token in the session. | "csrfToken" |
118117
| TrustedOrigins | `[]string` | TrustedOrigins is a list of trusted origins for unsafe requests. This supports subdomain matching, so you can use a value like "https://*.example.com" to allow any subdomain of example.com to submit requests. | `[]` |
119118

120119
### Default Config
@@ -124,11 +123,10 @@ var ConfigDefault = Config{
124123
KeyLookup: "header:" + HeaderName,
125124
CookieName: "csrf_",
126125
CookieSameSite: "Lax",
127-
Expiration: 1 * time.Hour,
126+
IdleTimeout: 30 * time.Minute,
128127
KeyGenerator: utils.UUIDv4,
129128
ErrorHandler: defaultErrorHandler,
130129
Extractor: FromHeader(HeaderName),
131-
SessionKey: "csrfToken",
132130
}
133131
```
134132

@@ -144,12 +142,11 @@ var ConfigDefault = Config{
144142
CookieSecure: true,
145143
CookieSessionOnly: true,
146144
CookieHTTPOnly: true,
147-
Expiration: 1 * time.Hour,
145+
IdleTimeout: 30 * time.Minute,
148146
KeyGenerator: utils.UUIDv4,
149147
ErrorHandler: defaultErrorHandler,
150148
Extractor: FromHeader(HeaderName),
151149
Session: session.Store,
152-
SessionKey: "csrfToken",
153150
}
154151
```
155152

@@ -304,7 +301,7 @@ The Referer header is automatically included in requests by all modern browsers,
304301

305302
## Token Lifecycle
306303

307-
Tokens are valid until they expire or until they are deleted. By default, tokens are valid for 1 hour, and each subsequent request extends the expiration by 1 hour. The token only expires if the user doesn't make a request for the duration of the expiration time.
304+
Tokens are valid until they expire or until they are deleted. By default, tokens are valid for 30 minutes, and each subsequent request extends the expiration by the idle timeout. The token only expires if the user doesn't make a request for the duration of the idle timeout.
308305

309306
### Token Reuse
310307

0 commit comments

Comments
 (0)