-
Notifications
You must be signed in to change notification settings - Fork 51
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
Generate function never called when Vision route has CORS enabled #90
Comments
I'm not following the flow. Why are vision routes acting differently? |
sorry @hueniverse you're right, it's not limited to vision routes, but to any route being access directly from browser when CORS is enabled. so if CORS is set globally and one tries to access a route directly in browser for example, this makes it so that a route can't be used in both CORS and non-CORS contexts when using crumb. maybe this is okay though, and I just need to clearly state that in crumb readme? |
Directly you mean CURL? |
CURL or in a browser Here's the headers from chrome dev tools from a Vision route with CORS enabled
vs
|
If I disable CORS for the same route, then crumb generate is called and crumb works as expected. This came up when I was debugging someone's setup where the crumb cookie wasn't being set or added to the view context, and it was because CORS was enabled globally |
Why isn't the browser sending the CORS headers? |
I don't know honestly. Probably the root issue. I'll dig in to that |
@hueniverse the browser will never use CORS for a single api request or for an initial html page as served by a Vision route for example. |
this page outlines when the header origin is served https://wiki.mozilla.org/Security/Origin |
I think that's the right change. Enforce CORS where Origin is present. |
Closed by a11b358 |
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions. |
So I think found the reason why the crumb cookie isn't being set sometimes.
If you setup your server with CORS enabled globally but also using Vision like this:
And then proceed to create a few routes returning views, the view routes will never call Crumb's generate function, because https://github.com/hapijs/crumb/blob/master/lib/index.js#L83 will always fail unless CORS is explicitly turned off for the view route.
The reason being that
request.route.settings.cors
evaluates totrue
, but then no CORS headers are actually set with the view, so theorigin
header isn't set makingrequest.info.cors.isOriginMatch
fail here https://github.com/hapijs/hapi/blob/ed195fad213a9da0f0762271c4907f4218e2abaf/lib/cors.js#L177-L179As far as I can see, it comes down to the user being aware that a view route can't have CORS enabled. @hueniverse do you think there's any way to work around this in code, or will the best solution be to document the heck out of it in Crumb?
The text was updated successfully, but these errors were encountered: