Skip to content

Commit 2ef2ed1

Browse files
authored
Merge pull request #1 from hashicorp/jeff-disable-autoconfigured-cors-values
Add a flag to allow disabling autoconfigured CORS allowed origin values
2 parents 3330b9b + 505fba7 commit 2ef2ed1

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

configutil/listener.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@ type Listener struct {
8585
// RandomPort is used only for some testing purposes
8686
RandomPort bool `hcl:"-"`
8787

88-
CorsEnabledRaw interface{} `hcl:"cors_enabled"`
89-
CorsEnabled *bool `hcl:"-"`
90-
CorsAllowedOrigins []string `hcl:"cors_allowed_origins"`
91-
CorsAllowedHeaders []string `hcl:"-"`
92-
CorsAllowedHeadersRaw []string `hcl:"cors_allowed_headers"`
88+
CorsEnabledRaw interface{} `hcl:"cors_enabled"`
89+
CorsEnabled *bool `hcl:"-"`
90+
CorsDisableDefaultAllowedOriginValuesRaw interface{} `hcl:"cors_disable_default_allowed_origin_values"`
91+
CorsDisableDefaultAllowedOriginValues *bool `hcl:"-"`
92+
CorsAllowedOrigins []string `hcl:"cors_allowed_origins"`
93+
CorsAllowedHeaders []string `hcl:"-"`
94+
CorsAllowedHeadersRaw []string `hcl:"cors_allowed_headers"`
9395
}
9496

9597
func (l *Listener) GoString() string {
@@ -330,6 +332,15 @@ func ParseListeners(result *SharedConfig, list *ast.ObjectList) error {
330332
l.CorsEnabledRaw = nil
331333
}
332334

335+
if l.CorsDisableDefaultAllowedOriginValuesRaw != nil {
336+
disabled, err := parseutil.ParseBool(l.CorsDisableDefaultAllowedOriginValuesRaw)
337+
if err != nil {
338+
return multierror.Prefix(fmt.Errorf("invalid value for cors_disable_default_allowed_origin_values: %w", err), fmt.Sprintf("listeners.%d", i))
339+
}
340+
l.CorsDisableDefaultAllowedOriginValues = &disabled
341+
l.CorsDisableDefaultAllowedOriginValuesRaw = nil
342+
}
343+
333344
if strutil.StrListContains(l.CorsAllowedOrigins, "*") && len(l.CorsAllowedOrigins) > 1 {
334345
return multierror.Prefix(errors.New("cors_allowed_origins must only contain a wildcard or only non-wildcard values"), fmt.Sprintf("listeners.%d", i))
335346
}

0 commit comments

Comments
 (0)