CORS policy not working #1362
Replies: 11 comments
-
You need to share the basics of your CORS policy configuration otherwise we will not be able to help. The policy seems to work fine for me. |
Beta Was this translation helpful? Give feedback.
-
Hi @msavy, thanks for the response. These are the configurations right now we are using in CORS policy |
Beta Was this translation helpful? Give feedback.
-
That looks like a normal configuration. How are you testing it? CORS protocol operates against the Origin header, which is set automatically in browsers but if you are testing using cURL or postman you'll need to set it yourself |
Beta Was this translation helpful? Give feedback.
-
We are accessing the API through browser. Is there any other configurations that can override the CORS policy? |
Beta Was this translation helpful? Give feedback.
-
Not that I'm aware of. Just make sure you are operating on the correct API and the policy is definitely in the chain. You can verify that by looking at the CORS headers of the response. For example, If you are using a complex request like a POST then you will get preflight headers back also. e.g. |
Beta Was this translation helpful? Give feedback.
-
When you refer the API policy chain? What do you mean by that? |
Beta Was this translation helpful? Give feedback.
-
Basically what we are trying to do is, we are wrapping a 3rd party API through APIMan. We implement the gateway, For now we implemented the CORS policy to test on that. |
Beta Was this translation helpful? Give feedback.
-
Sorry, I'm not available for calls with community support. I do my best on community support when I have spare time (vs paid work that pays the bills!). More info is available here on what the concept of a policy chain is in Apiman: https://apiman.gitbooks.io/apiman-user-guide/content/user-guide/manager/concepts.html#_policy_chain Please look at the HTTP response headers that come back from the call you have made through the Apiman Gateway to your API. Do you see CORS headers in the response? You should see things like |
Beta Was this translation helpful? Give feedback.
-
As an example, I've set up a CORS policy that requires allows 1 origin http://foo.com If I do a cURL request as follows:
I get a successful response (correct). From the response you can see the following useful header(s)
If I use a deliberately invalid origin, then it fails:
|
Beta Was this translation helpful? Give feedback.
-
Hi @msavy, I am a bit confused that how you are requesting to localhost? My gateway for the API is my DNS and not localhost, hence endpoint of my API doesn't start with localhost. Also how can your localhost API be public and accessible to everyone? The following blog also suggests the same and uses the localhost endpoint for the public API. https://www.apiman.io/blog/security/plugin/policy/cors/1.2.x/2016/01/22/cors-redux.html |
Beta Was this translation helpful? Give feedback.
-
Because I was using localhost for the demonstration purposes (i.e. running Apiman on my local machine). The concepts are exactly the same. If you want anyone to be allowed to invoke the API (via CORS config), then just set the And you can add all non-simple methods to the preflight |
Beta Was this translation helpful? Give feedback.
-
Issue:
I have published an API publicly. To test the CORS policy, I am trying to request to the endpoint from a different origin but getting the API response but I think it should have given me some CORS response or error.
Goal:
Basically my end-goal is to allow only specific origin to make a request on the endpoint.
Any leads would be helpful. Thanks
Beta Was this translation helpful? Give feedback.
All reactions