You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api/middleware/cors.md
+21-10Lines changed: 21 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,8 @@ The middleware conforms to the `access-control-allow-origin` specification by pa
10
10
11
11
For more control, `AllowOriginsFunc` can be used to programatically determine if an origin is allowed. If no match was found in `AllowOrigins` and if `AllowOriginsFunc` returns true then the 'access-control-allow-origin' response header is set to the 'origin' request header.
12
12
13
+
When defining your Origins make sure they are properly formatted. The middleware validates and normalizes the provided origins, ensuring they're in the correct format by checking for valid schemes (http or https), and removing any trailing slashes.
14
+
13
15
## Signatures
14
16
15
17
```go
@@ -56,18 +58,27 @@ app.Use(cors.New(cors.Config{
56
58
}))
57
59
```
58
60
61
+
**Note: The following configuration is considered insecure and will result in a panic.**
| Next |`func(*fiber.Ctx) bool`| Next defines a function to skip this middleware when returned true. |`nil`|
64
-
| AllowOriginsFunc |`func(origin string) bool`| AllowOriginsFunc defines a function that will set the 'access-control-allow-origin' response header to the 'origin' request header when returned true. |`nil`|
65
-
| AllowOrigins |`string`| AllowOrigin defines a comma separated list of origins that may access the resource. |`"*"`|
66
-
| AllowMethods |`string`| AllowMethods defines a list of methods allowed when accessing the resource. This is used in response to a preflight request. |`"GET,POST,HEAD,PUT,DELETE,PATCH"`|
67
-
| AllowHeaders |`string`| AllowHeaders defines a list of request headers that can be used when making the actual request. This is in response to a preflight request. |`""`|
68
-
| AllowCredentials |`bool`| AllowCredentials indicates whether or not the response to the request can be exposed when the credentials flag is true. |`false`|
69
-
| ExposeHeaders |`string`| ExposeHeaders defines a whitelist headers that clients are allowed to access. |`""`|
70
-
| MaxAge |`int`| MaxAge indicates how long (in seconds) the results of a preflight request can be cached. If you pass MaxAge 0, Access-Control-Max-Age header will not be added and browser will use 5 seconds by default. To disable caching completely, pass MaxAge value negative. It will set the Access-Control-Max-Age header 0. |`0`|
| Next |`func(*fiber.Ctx) bool`| Next defines a function to skip this middleware when returned true. |`nil`|
75
+
| AllowOriginsFunc |`func(origin string) bool`| AllowOriginsFunc defines a function that will set the 'access-control-allow-origin' response header to the 'origin' request header when returned true. This allows for dynamic evaluation of allowed origins. Note if AllowCredentials is true, wildcard origins will be not have the 'access-control-allow-credentials' header set to 'true'.|`nil`|
76
+
| AllowOrigins |`string`| AllowOrigin defines a comma separated list of origins that may access the resource. |`"*"`|
77
+
| AllowMethods |`string`| AllowMethods defines a list of methods allowed when accessing the resource. This is used in response to a preflight request. |`"GET,POST,HEAD,PUT,DELETE,PATCH"`|
78
+
| AllowHeaders |`string`| AllowHeaders defines a list of request headers that can be used when making the actual request. This is in response to a preflight request. |`""`|
79
+
| AllowCredentials |`bool`| AllowCredentials indicates whether or not the response to the request can be exposed when the credentials flag is true. When used as part of a response to a preflight request, this indicates whether or not the actual request can be made using credentials. Note: If true, AllowOrigins cannot be set to a wildcard ("*") to prevent security vulnerabilities.|`false`|
80
+
| ExposeHeaders |`string`| ExposeHeaders defines a whitelist headers that clients are allowed to access. |`""`|
81
+
| MaxAge |`int`| MaxAge indicates how long (in seconds) the results of a preflight request can be cached. If you pass MaxAge 0, Access-Control-Max-Age header will not be added and browser will use 5 seconds by default. To disable caching completely, pass MaxAge value negative. It will set the Access-Control-Max-Age header 0. |`0`|
0 commit comments