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

Set allowed headers via API instead of defaulting to wildcard. #3023

Merged
merged 28 commits into from
Aug 7, 2017

Conversation

naunga
Copy link
Contributor

@naunga naunga commented Jul 16, 2017

This addresses issue #2982.

Setting the Access-Control-Allow-Headers to a wildcard, which was the default in Vault's CORS implementation, is an open spec and not merged is all browsers.

Things have been refactored to be a list of standard headers that Vault uses by default and users can append additional headers via the API.

@jefferai jefferai added this to the 0.7.4 milestone Jul 17, 2017
@jefferai jefferai modified the milestones: 0.7.4, 0.8.0 Jul 24, 2017
vault/cors.go Outdated

if strutil.StrListContains(urls, "*") && len(urls) > 1 {
urls = append(urls, "*")
} else if strutil.StrListContains(urls, "*") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new logic seems suspect -- the error message says that to allow all origins * must be the only value, but the logic makes the empty set automatically get * and if you were to only have * as your only supplied url you'd trigger the error since the length > 1 check got removed.

vault/cors.go Outdated
return errors.New("to allow all origins the '*' must be the only value for allowed_origins")
}

c.Lock()
c.AllowedOrigins = urls
c.Unlock()

c.Lock()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than unlock and lock, just keep the lock here.

// Allow the user to add additional headers to the list of
// headers allowed on cross-origin requests.
if len(headers) > 0 {
c.AllowedHeaders = append(c.AllowedHeaders, headers...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there ever a chance that Enable will be called multiple times? It seems like the right thing here would be to start fresh every time since this function is (presuambly) being given the canonical set of allowed headers. So rather than the check above and the check here, simply do:

c.AllowedHeaders = stdAllowedHeaders
if len(headers) > 0 {
c.AllowedHeaders = append(c.AllowedHeaders, headers...)
}

Let me know if I'm missing something here...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enable certainly could be called multiple times, because this code allows new headers to be appended to the existing set. This workflow, however, clashes with the workflow for setting origins. Your suggestion is correct.

vault/cors.go Outdated
func (c *CORSConfig) Disable() error {
atomic.StoreUint32(&c.Enabled, CORSDisabled)
c.Lock()
c.AllowedOrigins = []string(nil)
c.Unlock()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here, don't give up the lock and relock.

Copy link
Member

@jefferai jefferai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good, some minor stuff in comments!

@jefferai
Copy link
Member

jefferai commented Aug 7, 2017

Made a couple of minor adjustments. Looks good! Thanks!

@jefferai jefferai merged commit b837a1f into hashicorp:master Aug 7, 2017
chrishoffman pushed a commit that referenced this pull request Aug 8, 2017
* oss/master: (55 commits)
  update dr replication docs with the promotion response (#3124)
  Make travis_wait Travis wait longer_wait
  changelog++
  Set allowed headers via API instead of defaulting to wildcard. (#3023)
  Fix formatting in mfa docs (#3122)
  Fix minor typo (#3120)
  Update go-plugin to include go-hclog support
  Unlock the statelock on unsuccessful sealInitCommon
  Remove a couple unneeded cancels
  Make seal/stepdown functions async internally so they can poke the request context
  Update mock-plugin (#3107)
  Fix minor grammatical error (#3110)
  docs: MFA API (#3109)
  Cut version 0.8.0-rc1
  Update version
  Migrate physical backends into separate packages (#3106)
  changeling ++
  changelog++
  changelog++
  credsutil: Include hyphen as part of reqStr (#3037)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants