Skip to content

Commit d21f1bb

Browse files
Add docs from gofiber/fiber@86c6553
1 parent 1cfa70d commit d21f1bb

File tree

6 files changed

+35
-1
lines changed

6 files changed

+35
-1
lines changed

docs/core/middleware/cache.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ app.Use(cache.New(cache.Config{
104104

105105
`CacheInvalidator` defines custom invalidation rules. Return `true` to bypass the cache. In the example above, setting the `invalidateCache` query parameter to `true` invalidates the entry.
106106

107+
Cache keys are masked in logs and error messages by default. Set `DisableValueRedaction` to `true` if you explicitly need the raw key for debugging.
108+
107109
## Config
108110

109111
| Property | Type | Description | Default |
@@ -113,6 +115,7 @@ app.Use(cache.New(cache.Config{
113115
| CacheHeader | `string` | CacheHeader is the header on the response header that indicates the cache status, with the possible return values "hit," "miss," or "unreachable." | `X-Cache` |
114116
| DisableCacheControl | `bool` | DisableCacheControl omits the `Cache-Control` header when set to `true`. | `false` |
115117
| CacheInvalidator | `func(fiber.Ctx) bool` | CacheInvalidator defines a function that is executed before checking the cache entry. It can be used to invalidate the existing cache manually by returning true. | `nil` |
118+
| DisableValueRedaction | `bool` | Turns off cache key redaction in logs and error messages when set to `true`. | `false` |
116119
| KeyGenerator | `func(fiber.Ctx) string` | KeyGenerator allows you to generate custom keys. The HTTP method is appended automatically. | `func(c fiber.Ctx) string { return utils.CopyString(c.Path()) }` |
117120
| ExpirationGenerator | `func(fiber.Ctx, *cache.Config) time.Duration` | ExpirationGenerator allows you to generate custom expiration keys based on the request. | `nil` |
118121
| Storage | `fiber.Storage` | Storage is used to store the state of the middleware. | In-memory store |
@@ -129,6 +132,7 @@ var ConfigDefault = Config{
129132
CacheHeader: "X-Cache",
130133
DisableCacheControl: false,
131134
CacheInvalidator: nil,
135+
DisableValueRedaction: false,
132136
KeyGenerator: func(c fiber.Ctx) string {
133137
return utils.CopyString(c.Path())
134138
},

docs/core/middleware/cors.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ It adds CORS headers to responses, listing allowed origins, methods, and headers
1010

1111
Use the `AllowOrigins` option to define which origins may send cross-origin requests. It accepts single origins, lists, subdomain patterns, wildcards, and supports dynamic validation with `AllowOriginsFunc`.
1212

13-
The middleware normalizes `AllowOrigins`, verifies HTTP/HTTPS schemes, and strips trailing slashes. Invalid origins cause a panic.
13+
The middleware normalizes `AllowOrigins`, verifies HTTP/HTTPS schemes, and strips trailing slashes. Invalid origins cause a panic. Panic messages and logs redact misconfigured origins by default; set `DisableValueRedaction` to `true` if you need the raw value for troubleshooting.
1414

1515
Avoid [common pitfalls](#common-pitfalls) such as using wildcard origins with credentials, overly permissive origin lists, or skipping validation with `AllowOriginsFunc`, as misconfiguration can create security risks.
1616

@@ -118,6 +118,7 @@ panic: [CORS] Configuration error: When 'AllowCredentials' is set to true, 'Allo
118118
| AllowOrigins | `[]string` | AllowOrigins defines a list of origins that may access the resource. This supports subdomain matching, so you can use a value like "https://*.example.com" to allow any subdomain of example.com to submit requests. If the special wildcard `"*"` is present in the list, all origins will be allowed. | `["*"]` |
119119
| AllowOriginsFunc | `func(origin string) bool` | `AllowOriginsFunc` is a function that dynamically determines whether to allow a request based on its origin. If this function returns `true`, the 'Access-Control-Allow-Origin' response header will be set to the request's 'origin' header. This function is only used if the request's origin doesn't match any origin in `AllowOrigins`. | `nil` |
120120
| AllowPrivateNetwork | `bool` | Indicates whether the `Access-Control-Allow-Private-Network` response header should be set to `true`, allowing requests from private networks. This aligns with modern security practices for web applications interacting with private networks. | `false` |
121+
| DisableValueRedaction | `bool` | Disables redaction of misconfigured origins and settings in panics and logs. | `false` |
121122
| ExposeHeaders | `[]string` | ExposeHeaders defines an allowlist of headers that clients are allowed to access. | `[]` |
122123
| MaxAge | `int` | MaxAge indicates how long (in seconds) the results of a preflight request can be cached. If you pass MaxAge 0, the Access-Control-Max-Age header will not be added and the browser will use 5 seconds by default. To disable caching completely, pass MaxAge value negative. It will set the Access-Control-Max-Age header to 0. | `0` |
123124
| Next | `func(fiber.Ctx) bool` | Next defines a function to skip this middleware when it returns true. | `nil` |
@@ -133,6 +134,7 @@ var ConfigDefault = Config{
133134
Next: nil,
134135
AllowOriginsFunc: nil,
135136
AllowOrigins: []string{"*"},
137+
DisableValueRedaction: false,
136138
AllowMethods: []string{
137139
fiber.MethodGet,
138140
fiber.MethodPost,

docs/core/middleware/csrf.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ app.Use(csrf.New(csrf.Config{
4242
CookieSessionOnly: true,
4343
Extractor: extractors.FromHeader("X-Csrf-Token"),
4444
Session: sessionStore,
45+
// Redaction is enabled by default. Set DisableValueRedaction when you must expose tokens or storage keys in diagnostics.
46+
// DisableValueRedaction: true,
4547
}))
4648
```
4749

@@ -403,6 +405,7 @@ func (h *csrf.Handler) DeleteToken(c fiber.Ctx) error
403405
| KeyGenerator | `func() string` | Token generation function | `utils.UUIDv4` |
404406
| ErrorHandler | `fiber.ErrorHandler` | Custom error handler | `defaultErrorHandler` |
405407
| Extractor | `extractors.Extractor` | Token extraction method with metadata | `extractors.FromHeader("X-Csrf-Token")` |
408+
| DisableValueRedaction | `bool` | Disables redaction of tokens and storage keys in logs and error messages. | `false` |
406409
| Session | `*session.Store` | Session store (**recommended for production**) | `nil` |
407410
| Storage | `fiber.Storage` | Token storage (overridden by Session) | `nil` |
408411
| TrustedOrigins | `[]string` | Trusted origins for cross-origin requests | `[]` |

docs/core/middleware/idempotency.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,16 @@ app.Use(idempotency.New(idempotency.Config{
6868

6969
## Config
7070

71+
Idempotency keys are hidden in logs and error messages by default. Set `DisableValueRedaction` to `true` only when you need to expose them for debugging.
72+
7173
| Property | Type | Description | Default |
7274
|:--------------------|:-----------------------|:----------------------------------------------------------------------------------------------------------------------------------------|:-------------------------------------------------------------------|
7375
| Next | `func(fiber.Ctx) bool` | Function to skip this middleware when it returns `true`; use `IsMethodSafe` or `IsMethodIdempotent`. | `func(c fiber.Ctx) bool { return fiber.IsMethodSafe(c.Method()) }` |
7476
| Lifetime | `time.Duration` | Maximum lifetime of an idempotency key. | `30 * time.Minute` |
7577
| KeyHeader | `string` | Header name containing the idempotency key. | `"X-Idempotency-Key"` |
7678
| KeyHeaderValidate | `func(string) error` | Function to validate idempotency header syntax (e.g., UUID). | UUID length check (`36` characters) |
7779
| KeepResponseHeaders | `[]string` | List of headers to preserve from original response. | `nil` (keep all headers) |
80+
| DisableValueRedaction | `bool` | Disables idempotency key redaction in logs and error messages. | `false` |
7881
| Lock | `Locker` | Locks an idempotency key to prevent race conditions. | In-memory locker |
7982
| Storage | `fiber.Storage` | Stores response data by idempotency key. | In-memory storage |
8083

@@ -103,5 +106,6 @@ var ConfigDefault = Config{
103106
Lock: nil, // Set in configDefault so we don't allocate data here.
104107

105108
Storage: nil, // Set in configDefault so we don't allocate data here.
109+
DisableValueRedaction: false,
106110
}
107111
```

docs/core/middleware/limiter.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ id: limiter
66

77
The Limiter middleware for [Fiber](https://github.com/gofiber/fiber) throttles repeated requests to public APIs or endpoints such as password resets. It's also useful for API clients, web crawlers, or other tasks that need rate limiting.
88

9+
Limiter redacts request keys in error paths by default so storage identifiers and rate-limit keys don't leak into logs. Set `DisableValueRedaction` to `true` when you explicitly need the raw key for troubleshooting.
10+
911
:::note
1012
This middleware uses our [Storage](https://github.com/gofiber/storage) package to support various databases through a single interface. The default configuration for this middleware saves data to memory, see the examples below for other databases.
1113
:::
@@ -106,6 +108,7 @@ app.Use(limiter.New(limiter.Config{
106108
| SkipFailedRequests | `bool` | When set to `true`, requests with status code ≥ 400 aren't counted. | false |
107109
| SkipSuccessfulRequests | `bool` | When set to `true`, requests with status code < 400 aren't counted. | false |
108110
| DisableHeaders | `bool` | When set to `true`, the middleware omits rate limit headers (`X-RateLimit-*` and `Retry-After`). | false |
111+
| DisableValueRedaction | `bool` | Disables redaction of limiter keys in error messages and logs. | false |
109112
| Storage | `fiber.Storage` | Persists middleware state. | An in-memory store for this process only |
110113
| LimiterMiddleware | `LimiterHandler` | Selects the algorithm implementation. | A new Fixed Window Rate Limiter |
111114

@@ -131,6 +134,7 @@ var ConfigDefault = Config{
131134
SkipFailedRequests: false,
132135
SkipSuccessfulRequests: false,
133136
DisableHeaders: false,
137+
DisableValueRedaction: false,
134138
LimiterMiddleware: FixedWindow{},
135139
}
136140
```

docs/core/whats_new.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,8 @@ We are excited to introduce a new option in our caching middleware: Cache Invali
11611161
Additionally, the caching middleware has been optimized to avoid caching non-cacheable status codes, as defined by the [HTTP standards](https://datatracker.ietf.org/doc/html/rfc7231#section-6.1). This improvement enhances cache accuracy and reduces unnecessary cache storage usage.
11621162
Cached responses now include an RFC-compliant Age header, providing a standardized indication of how long a response has been stored in cache since it was originally generated. This enhancement improves HTTP compliance and facilitates better client-side caching strategies.
11631163

1164+
Cache keys are now redacted in logs and error messages by default, and a `DisableValueRedaction` boolean (default `false`) lets you opt out when you need the raw value for troubleshooting.
1165+
11641166
:::note
11651167
The deprecated `Store` and `Key` options have been removed in v3. Use `Storage` and `KeyGenerator` instead.
11661168
:::
@@ -1182,6 +1184,8 @@ We've updated several fields from a single string (containing comma-separated va
11821184
- `Config.AllowHeaders`: Now accepts a slice of strings, each representing an allowed header.
11831185
- `Config.ExposeHeaders`: Now accepts a slice of strings, each representing an exposed header.
11841186

1187+
Additionally, panic messages and logs redact misconfigured origins by default, and a `DisableValueRedaction` flag (default `false`) lets you reveal them when necessary.
1188+
11851189
### Compression
11861190

11871191
- Added support for `zstd` compression alongside `gzip`, `deflate`, and `brotli`.
@@ -1194,6 +1198,12 @@ We've updated several fields from a single string (containing comma-separated va
11941198

11951199
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.
11961200

1201+
CSRF now redacts tokens and storage keys by default and exposes a `DisableValueRedaction` toggle (default `false`) if you must surface those values in diagnostics.
1202+
1203+
### Idempotency
1204+
1205+
Idempotency middleware now redacts keys by default and offers a `DisableValueRedaction` configuration flag (default `false`) to expose them when debugging.
1206+
11971207
### EncryptCookie
11981208

11991209
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).
@@ -1384,6 +1394,8 @@ See more in [Logger](./middleware/logger.md#predefined-formats)
13841394

13851395
The limiter middleware uses a new Fixed Window Rate Limiter implementation.
13861396

1397+
Limiter now redacts request keys in error paths by default. A new `DisableValueRedaction` boolean (default `false`) lets you reveal the raw limiter key if diagnostics require it.
1398+
13871399
:::note
13881400
Deprecated fields `Duration`, `Store`, and `Key` have been removed in v3. Use `Expiration`, `Storage`, and `KeyGenerator` instead.
13891401
:::
@@ -2212,6 +2224,7 @@ app.Use(csrf.New(csrf.Config{
22122224
- **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.
22132225

22142226
- **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.
2227+
- **DisableValueRedaction Toggle**: CSRF redacts tokens and storage keys by default; set `DisableValueRedaction` to `true` when diagnostics require the raw values.
22152228

22162229
```go
22172230
// Before
@@ -2247,6 +2260,10 @@ app.Use(csrf.New(csrf.Config{
22472260

22482261
**Security Note**: The removal of `FromCookie` prevents a common misconfiguration that would completely bypass CSRF protection. The middleware uses the Double Submit Cookie pattern, which requires the token to be submitted through a different channel than the cookie to provide meaningful protection.
22492262

2263+
#### Idempotency
2264+
2265+
- **DisableValueRedaction Toggle**: The idempotency middleware now hides keys in logs and error paths by default, with a `DisableValueRedaction` boolean (default `false`) to reveal them when needed.
2266+
22502267
#### Timeout
22512268

22522269
The timeout middleware now accepts a configuration struct instead of a duration.

0 commit comments

Comments
 (0)