Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd: Disable cors per default #107

Merged
merged 1 commit into from
Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ before finalizing the upgrade process.

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## 1.0.0-rc.1

### CORS is disabled by default

A new environment variable `CORS_ENABLED` was introduced. It sets whether CORS is enabled ("true") or not ("false")".
Default is disabled.

## 1.0.0-beta.8

### `noop` authenticator no longer bypasses authorizers/credentials issuers
Expand Down
3 changes: 3 additions & 0 deletions cmd/helper_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import (

var corsMessage = `CORS CONTROLS
==============
- CORS_ENABLED: Switch CORS support on (true) or off (false). Default is off (false).
Example: CORS_ENABLED=true

- CORS_ALLOWED_ORIGINS: A list of origins (comma separated values) a cross-domain request can be executed from.
If the special * value is present in the list, all origins will be allowed. An origin may contain a wildcard (*)
to replace 0 or more characters (i.e.: http://*.domain.com). Usage of wildcards implies a small performance penality.
Expand Down
7 changes: 5 additions & 2 deletions cmd/serve_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,18 @@ HTTP CONTROLS
}

n.UseHandler(judgeHandler)
ch := cors.New(corsx.ParseOptions()).Handler(n)
var h http.Handler = n
if viper.GetString("CORS_ENABLED") == "true" {
h = cors.New(corsx.ParseOptions()).Handler(n)
}

go refreshKeys(keyManager, 0)
go refreshRules(matcher, 0)

addr := fmt.Sprintf("%s:%s", viper.GetString("HOST"), viper.GetString("PORT"))
server := graceful.WithDefaults(&http.Server{
Addr: addr,
Handler: ch,
Handler: h,
})

logger.Printf("Listening on %s", addr)
Expand Down
7 changes: 5 additions & 2 deletions cmd/serve_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ OTHER CONTROLS
}

n.UseHandler(handler)
ch := cors.New(corsx.ParseOptions()).Handler(n)
var h http.Handler = n
if viper.GetString("CORS_ENABLED") == "true" {
h = cors.New(corsx.ParseOptions()).Handler(n)
}

var cert tls.Certificate
tlsCert := viper.GetString("HTTP_TLS_CERT")
Expand All @@ -223,7 +226,7 @@ OTHER CONTROLS
addr := fmt.Sprintf("%s:%s", viper.GetString("HOST"), viper.GetString("PORT"))
server := graceful.WithDefaults(&http.Server{
Addr: addr,
Handler: ch,
Handler: h,
TLSConfig: &tls.Config{
Certificates: []tls.Certificate{cert},
},
Expand Down