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

Specify allowed headers explicitly instead of using a wildcard #2969

Closed
wants to merge 2 commits into from
Closed

Specify allowed headers explicitly instead of using a wildcard #2969

wants to merge 2 commits into from

Conversation

chaitanyagupta
Copy link

@chaitanyagupta chaitanyagupta commented Jul 4, 2017

While testing out the recently merged CORS support I faced this error in both Chrome and Firefox:

XMLHttpRequest cannot load http://127.0.0.1:8200/v1/secret/path. Request header field X-Vault-Token is not allowed by Access-Control-Allow-Headers in preflight response.

Vault sets the value of Access-Control-Allow-Headers to *. This, it turns out, is still an open spec issue and has not yet been merged in either Chrome or Firefox: whatwg/fetch#548

The fix is to explicitly specify the list of headers that should be allowed e.g. Content-Type, X-Vault-Token, etc. The changes here fix that.

@jefferai
Copy link
Member

jefferai commented Jul 4, 2017

This isn't sufficient as there are more headers vault uses and more it may use in the future. We could maybe set it to the current list but then I'd want to refactor things so that we have less risk of leaving something out later. But even then a newer client against an older vault server may have problems.

@chaitanyagupta
Copy link
Author

I was wondering if there are other headers that Vault uses. So how do you want to go about it? Because in its current form, CORS support is pretty much not working.

@chaitanyagupta
Copy link
Author

I've added two more headers to the allowed list: Content-Type to send a JSON body in POST requests, and X-Requested-With to support libs like jquery which set it by default.

@jefferai
Copy link
Member

jefferai commented Jul 5, 2017

This is illustrating my point -- you've added two more headers, but you've still omitted actual Vault headers that Vault clients can legitimately set.

@chaitanyagupta
Copy link
Author

chaitanyagupta commented Jul 5, 2017

Yes, I get what you are saying. No need to merge this PR (though I will keep updating my branch to ensure things work for me).

That said, I don't think CORS support is usable until this issue is fixed.

I also grepped though the source to figure out which other headers vault clients might use. Is this all, or are there any headers that I've missed?

X-Vault-AWS-IAM-Server-ID
X-Vault-Internal-No-Request-Forwarding
X-Vault-No-Request-Forwarding
X-Vault-Token
X-Vault-Wrap-Format
X-Vault-Wrap-TTL

@jefferai
Copy link
Member

jefferai commented Jul 5, 2017

All of those can be supplied by a client except the Internal-No-Request-Forwarding one.

However, thinking about this, I think really the right thing to do would be to have that be a default list, but expand the CORS support to allow specifying allowed headers in addition to allowed origins. This is especially useful since there is now support to allow specifying headers to be audit-logged for request tracing purposes.

It's more work but in the end ensures that all uses can be satisfied. Any chance you'd be willing to dive in on that?

@chaitanyagupta
Copy link
Author

All of those can be supplied by a client except the Internal-No-Request-Forwarding one.

However, thinking about this, I think really the right thing to do would be to have that be a default list, but expand the CORS support to allow specifying allowed headers in addition to allowed origins. This is especially useful since there is now support to allow specifying headers to be audit-logged for request tracing purposes.

Yes, this makes sense.

It's more work but in the end ensures that all uses can be satisfied. Any chance you'd be willing to dive in on that?

Unfortunately I can't. I am unfamiliar with both Go and Vault internals, and with no time to spare, it doesn't look possible for me to pick up.

(As for the status of my fork, I will use it for the time being. However, to stay upto date with upstream over the long term, unless this issue gets fixed, it makes sense to use a reverse proxy that will serve both vault and the UI from the same origin).

@naunga
Copy link
Contributor

naunga commented Jul 10, 2017

I'd be happy to work on this PR if someone else isn't already.

@jefferai
Copy link
Member

@naunga Nobody is working on this currently, just an open issue. Thanks!

@jefferai
Copy link
Member

jefferai commented Aug 7, 2017

Fixed by #3023

@chaitanyagupta
Copy link
Author

That's great! Thanks @naunga @jefferai

@chaitanyagupta chaitanyagupta deleted the cors-allowed-headers-fix branch August 8, 2017 08:24
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.

3 participants