Skip to content

Commit

Permalink
cmd: Require explicit CORS enabling (#42)
Browse files Browse the repository at this point in the history
Signed-off-by: aeneasr <[email protected]>
  • Loading branch information
arekkas authored Aug 22, 2018
1 parent 6870443 commit 9a45107
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
7 changes: 6 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ The intent of this document is to make migration of breaking changes as easy as
breaking changes might be included here. Please check the [CHANGELOG.md](./CHANGELOG.md) for a full list of changes
before finalizing the upgrade process.

## 1.0.0-rc.1
## 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.
3 changes: 3 additions & 0 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ AUTHENTICATORS
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
9 changes: 7 additions & 2 deletions cmd/server/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ func RunServe(

n := negroni.New()
n.Use(negronilogrus.NewMiddlewareFromLogger(logger, "keto"))
corsHandler := cors.New(corsx.ParseOptions()).Handler(n)

var c http.Handler = n
if viper.GetString("CORS_ENABLED") == "true" {
logger.Info("Enabled CORS")
c = cors.New(corsx.ParseOptions()).Handler(n)
}

if ok, _ := cmd.Flags().GetBool("disable-telemetry"); !ok && viper.GetString("DATABASE_URL") != "memory" {
logger.Println("Transmission of telemetry data is enabled, to learn more go to: https://www.ory.sh/docs/guides/latest/telemetry/")
Expand Down Expand Up @@ -137,7 +142,7 @@ func RunServe(
address := fmt.Sprintf("%s:%s", viper.GetString("HOST"), viper.GetString("PORT"))
var srv = graceful.WithDefaults(&http.Server{
Addr: address,
Handler: corsHandler,
Handler: c,
})

if err := graceful.Graceful(func() error {
Expand Down

0 comments on commit 9a45107

Please sign in to comment.