Skip to content

Commit afe3276

Browse files
author
Vipul Rawat
authored
Merge pull request #147 from gofr-dev/en/remove_origin_header_from_CORS
remove Origin from the list of necessary CORS header
2 parents d322506 + c161d78 commit afe3276

File tree

2 files changed

+1
-9
lines changed

2 files changed

+1
-9
lines changed

pkg/middleware/cors.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
const (
13-
allowedHeaders = "Authorization, Content-Type, x-requested-with, origin, true-client-ip, X-Correlation-ID"
13+
allowedHeaders = "Authorization, Content-Type, x-requested-with, true-client-ip, X-Correlation-ID"
1414
allowedMethods = "PUT, POST, GET, DELETE, OPTIONS, PATCH"
1515
)
1616

@@ -47,8 +47,6 @@ func getValidCORSHeaders(envHeaders map[string]string) map[string]string {
4747

4848
// If config is not set - for the three headers, set default value.
4949
switch header {
50-
case "Access-Control-Allow-Origin":
51-
validCORSHeadersAndValues[header] = "*"
5250
case "Access-Control-Allow-Headers":
5351
validCORSHeadersAndValues[header] = allowedHeaders
5452
case "Access-Control-Allow-Methods":
@@ -68,7 +66,6 @@ func getValidCORSHeaders(envHeaders map[string]string) map[string]string {
6866
// AllowedCORSHeader returns the HTTP headers used for CORS configuration in web applications.
6967
func AllowedCORSHeader() []string {
7068
return []string{
71-
"Access-Control-Allow-Origin",
7269
"Access-Control-Allow-Headers",
7370
"Access-Control-Allow-Methods",
7471
"Access-Control-Allow-Credentials",

pkg/middleware/cors_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,17 @@ func Test_getValidCORSHeaders(t *testing.T) {
5757
}{
5858
{map[string]string{},
5959
map[string]string{
60-
"Access-Control-Allow-Origin": "*",
6160
"Access-Control-Allow-Headers": allowedHeaders,
6261
"Access-Control-Allow-Methods": allowedMethods,
6362
},
6463
},
6564
{map[string]string{
6665
"Access-Control-Max-Age": strconv.Itoa(600),
6766
"Access-Control-Allow-Headers": "",
68-
"Access-Control-Allow-Origin": "same-origin",
6967
"Access-Control-Allow-Methods": http.MethodPost,
7068
},
7169
map[string]string{
7270
"Access-Control-Max-Age": strconv.Itoa(600),
73-
"Access-Control-Allow-Origin": "same-origin",
7471
"Access-Control-Allow-Headers": allowedHeaders,
7572
"Access-Control-Allow-Methods": http.MethodPost,
7673
},
@@ -79,7 +76,6 @@ func Test_getValidCORSHeaders(t *testing.T) {
7976
"Access-Control-Allow-Headers": "clientid",
8077
},
8178
map[string]string{
82-
"Access-Control-Allow-Origin": "*",
8379
"Access-Control-Allow-Headers": allowedHeaders + ", clientid",
8480
"Access-Control-Allow-Methods": allowedMethods,
8581
},
@@ -93,7 +89,6 @@ func Test_getValidCORSHeaders(t *testing.T) {
9389
map[string]string{
9490
"Access-Control-Allow-Credentials": "true",
9591
"Access-Control-Max-Age": strconv.Itoa(600),
96-
"Access-Control-Allow-Origin": "*",
9792
"Access-Control-Allow-Headers": allowedHeaders,
9893
"Access-Control-Allow-Methods": allowedMethods,
9994
},

0 commit comments

Comments
 (0)