@@ -129,16 +129,6 @@ If `HTTPCORSFilter` is set, then the gateway will generate the response of the "
129
129
For the actual cross-origin request, the gateway will add CORS headers to the response before it is sent to the client.
130
130
131
131
``` golang
132
- // AllowCredentialsType describes valid value of config `AllowCredentials`.
133
- //
134
- // +kubebuilder:validation:Enum=true
135
- type AllowCredentialsType string
136
-
137
- const (
138
- // The actual cross-origin request allows to include credentials.
139
- AllowCredentials AllowCredentialsType = " true"
140
- )
141
-
142
132
const (
143
133
// HTTPRouteFilterCORS can be used to add CORS headers to an
144
134
// HTTP response before it is sent to the client.
@@ -222,7 +212,7 @@ type HTTPCORSFilter struct {
222
212
// Output:
223
213
//
224
214
// The `Access-Control-Allow-Origin` response header can only use `*`
225
- // wildcard as value when the `AllowCredentials` field is unspecified .
215
+ // wildcard as value when the `AllowCredentials` field is false .
226
216
//
227
217
// Input:
228
218
// Origin: https://foo.example
@@ -233,7 +223,7 @@ type HTTPCORSFilter struct {
233
223
// Output:
234
224
// Access-Control-Allow-Origin: *
235
225
//
236
- // When the `AllowCredentials` field is specified and `AllowOrigins`
226
+ // When the `AllowCredentials` field is true and `AllowOrigins`
237
227
// field specified with the `*` wildcard, the gateway must return a
238
228
// single origin in the value of the `Access-Control-Allow-Origin`
239
229
// response header, instead of specifying the `*` wildcard. The value
@@ -259,8 +249,8 @@ type HTTPCORSFilter struct {
259
249
// AllowCredentials indicates whether the actual cross-origin request
260
250
// allows to include credentials.
261
251
//
262
- // The only valid value for the `Access-Control-Allow-Credentials`
263
- // response header is true (case-sensitive).
252
+ // When set to true, the gateway will include the `Access-Control-Allow-Credentials`
253
+ // response header with value true (case-sensitive).
264
254
//
265
255
// Input:
266
256
// Origin: https://foo.example
@@ -272,14 +262,12 @@ type HTTPCORSFilter struct {
272
262
// Access-Control-Allow-Origin: https://foo.example
273
263
// Access-Control-Allow-Credentials: true
274
264
//
275
- // If the credentials are not allowed in cross-origin requests,
276
- // the gateway will omit the header `Access-Control-Allow-Credentials`
277
- // entirely rather than setting its value to false .
265
+ // When set to false, the gateway will omit the header
266
+ // `Access-Control-Allow-Credentials` entirely (this is the standard CORS
267
+ // behavior) .
278
268
//
279
269
// Support: Extended
280
- //
281
- // +optional
282
- AllowCredentials AllowCredentialsType ` json:"allowCredentials,omitempty"`
270
+ AllowCredentials *bool ` json:"allowCredentials,omitempty"`
283
271
284
272
// AllowMethods indicates which HTTP methods are supported
285
273
// for accessing the requested resource.
@@ -317,7 +305,7 @@ type HTTPCORSFilter struct {
317
305
// Access-Control-Allow-Methods: GET, POST, DELETE, PATCH, OPTIONS
318
306
//
319
307
// The `Access-Control-Allow-Methods` response header can only use `*`
320
- // wildcard as value when the `AllowCredentials` field is unspecified .
308
+ // wildcard as value when the `AllowCredentials` field is false .
321
309
//
322
310
// Input:
323
311
// Access-Control-Request-Method: PUT
@@ -328,7 +316,7 @@ type HTTPCORSFilter struct {
328
316
// Output:
329
317
// Access-Control-Allow-Methods: *
330
318
//
331
- // When the `AllowCredentials` field is specified and `AllowMethods`
319
+ // When the `AllowCredentials` field is true and the `AllowMethods`
332
320
// field specified with the `*` wildcard, the gateway must specify one
333
321
// HTTP method in the value of the Access-Control-Allow-Methods response
334
322
// header. The value of the header `Access-Control-Allow-Methods` is same
@@ -386,7 +374,7 @@ type HTTPCORSFilter struct {
386
374
//
387
375
// A wildcard indicates that the requests with all HTTP headers are allowed.
388
376
// The `Access-Control-Allow-Headers` response header can only use `*` wildcard
389
- // as value when the `AllowCredentials` field is unspecified .
377
+ // as value when the `AllowCredentials` field is false .
390
378
//
391
379
// Input:
392
380
// Access-Control-Request-Headers: Content-Type, Cache-Control
@@ -397,8 +385,8 @@ type HTTPCORSFilter struct {
397
385
// Output:
398
386
// Access-Control-Allow-Headers: *
399
387
//
400
- // When the `AllowCredentials` field is specified and `AllowHeaders` field
401
- // specified with the `*` wildcard, the gateway must specify one or more
388
+ // When the `AllowCredentials` field is true and the `AllowHeaders` field
389
+ // is specified with the `*` wildcard, the gateway must specify one or more
402
390
// HTTP headers in the value of the `Access-Control-Allow-Headers` response
403
391
// header. The value of the header `Access-Control-Allow-Headers` is same as
404
392
// the `Access-Control-Request-Headers` header provided by the client. If
@@ -456,7 +444,7 @@ type HTTPCORSFilter struct {
456
444
//
457
445
// A wildcard indicates that the responses with all HTTP headers are exposed
458
446
// to clients. The `Access-Control-Expose-Headers` response header can only use
459
- // `*` wildcard as value when the `AllowCredentials` field is unspecified .
447
+ // `*` wildcard as value when the `AllowCredentials` field is false .
460
448
//
461
449
// Config:
462
450
// exposeHeaders: ["*"]
@@ -590,7 +578,7 @@ spec:
590
578
- allowOrigins:
591
579
- https://foo.example
592
580
- http://foo.example
593
- allowCredentials: " true"
581
+ allowCredentials: true
594
582
allowMethods:
595
583
- GET
596
584
- PUT
@@ -656,6 +644,48 @@ Access-Control-Allow-Headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Request
656
644
Access-Control-Expose-Headers: Content-Security-Policy
657
645
```
658
646
647
+ ### Disabling credentials
648
+
649
+ To disable credentials for cross-origin requests, simply don't set the
650
+ ` allowCredentials ` field at all. If you prefer to be explicit, you can
651
+ set it to ` false ` , although this will generally not be necessary:
652
+
653
+ ``` yaml
654
+ apiVersion : gateway.networking.k8s.io/v1
655
+ kind : HTTPRoute
656
+ metadata :
657
+ name : http-route-cors-no-credentials
658
+ spec :
659
+ hostnames :
660
+ - http.route.cors.com
661
+ parentRefs :
662
+ - group : gateway.networking.k8s.io
663
+ kind : Gateway
664
+ name : http-gateway
665
+ rules :
666
+ - backendRefs :
667
+ - kind : Service
668
+ name : http-route-cors
669
+ port : 80
670
+ matches :
671
+ - path :
672
+ type : PathPrefix
673
+ value : /resource/bar
674
+ filters :
675
+ - cors :
676
+ allowOrigins :
677
+ - https://foo.example
678
+ allowCredentials : false
679
+ allowMethods :
680
+ - GET
681
+ - POST
682
+ type : CORS
683
+ ` ` `
684
+
685
+ Omitting the field, and setting it to ` false` both mean `false`. In this
686
+ configuration the gateway will _not_ include the
687
+ ` Access-Control-Allow-Credentials` header in responses.
688
+
659
689
# # Prior Art
660
690
Some implementations already support CORS.
661
691
0 commit comments