Skip to content

Fix Access-Control-Request-Method header#4424

Merged
timneutkens merged 2 commits into
vercel:canaryfrom
swissspidy:Access-Control-Request-Method
Jun 7, 2018
Merged

Fix Access-Control-Request-Method header#4424
timneutkens merged 2 commits into
vercel:canaryfrom
swissspidy:Access-Control-Request-Method

Conversation

@swissspidy
Copy link
Copy Markdown
Contributor

At least since #3578, the Access-Control-Request-Method HTTP header for preflight requests doesn't contain the actual request method, but instead the origin.

That's not correct.

Comment thread server/utils.js Outdated
res.setHeader('Access-Control-Request-Method', req.headers.origin)
res.setHeader('Access-Control-Request-Method', req.method)
res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET')
res.setHeader('Access-Control-Allow-Headers', req.headers.origin)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Interestingly this seems also wrong 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, you're right.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you can fix this one too I'll merge the PR 👍

@timneutkens
Copy link
Copy Markdown
Contributor

I did some research into this and found that Access-Control-Request-Method is a request only header, we shouldn't reply with that header, instead, we have to reply with the correct allowed headers.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Request-Method

I've updated the PR to reflect this. cc @arunoda please review

@timneutkens timneutkens requested a review from arunoda May 25, 2018 10:32
@swissspidy
Copy link
Copy Markdown
Contributor Author

Thanks @timneutkens!

Copy link
Copy Markdown

@pranaygp pranaygp left a comment

Choose a reason for hiding this comment

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

Code LGTM.

Just to confirm intended behavior, the server now replies saying "Any header you request of me is allowed"? If so, can we not instead just use '*'? https://fetch.spec.whatwg.org/#http-new-header-syntax

@timneutkens
Copy link
Copy Markdown
Contributor

I should have linked to MDN as that's why I made the choice not to use *:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers

There's a compatibility note there saying * has not been implemented in many browsers.

The wildcard value (*) that is mentioned in the latest specification, is not yet implemented in browsers:

@timneutkens timneutkens merged commit a411b35 into vercel:canary Jun 7, 2018
@pranaygp
Copy link
Copy Markdown

pranaygp commented Jun 7, 2018

Nice catch @timneutkens 🙇‍♀️

@swissspidy swissspidy deleted the Access-Control-Request-Method branch June 7, 2018 18:48
lependu pushed a commit to lependu/next.js that referenced this pull request Jun 19, 2018
* Fix Access-Control-Request-Method header

* Make OPTIONS request work
@lock lock Bot locked as resolved and limited conversation to collaborators Jun 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants