Why isn’t my CORS configuration causing the server to filter incoming requests? How can I make the server only accept requests from a specific origin?

CORS configuration won’t prevent the server from accepting requests based on the value of the Origin request header. You can’t do that just through CORS configuration. When you configure CORS support on a server, all that the server does differently is just to send the Access-Control-Allow-Origin response header and other CORS response headers. Actual enforcement … Read more

Spring Data Rest and Cors

Indeed, before Spring Data REST 2.6 (Ingalls) only HandlerMapping instances created by Spring MVC WebMvcConfigurationSupport and controllers annotated with @CrossOrigin were CORS aware. But now that DATAREST-573 has been fixed, RepositoryRestConfiguration now exposes a getCorsRegistry() for global setup and @CrossOrigin annotations on repositories are also recognized so this is the recommended approach. See https://stackoverflow.com/a/42403956/1092077 answer … Read more

Access-control-allow-origin with multiple domains

For IIS 7.5+ and Rewrite 2.0 you can use: <system.webServer> <httpProtocol> <customHeaders> <add name=”Access-Control-Allow-Headers” value=”Origin, X-Requested-With, Content-Type, Accept” /> <add name=”Access-Control-Allow-Methods” value=”POST,GET,OPTIONS,PUT,DELETE” /> </customHeaders> </httpProtocol> <rewrite> <outboundRules> <clear /> <rule name=”AddCrossDomainHeader”> <match serverVariable=”RESPONSE_Access_Control_Allow_Origin” pattern=”.*” /> <conditions logicalGrouping=”MatchAll” trackAllCaptures=”true”> <add input=”{HTTP_ORIGIN}” pattern=”(http(s)?://((.+\.)?domain1\.com|(.+\.)?domain2\.com|(.+\.)?domain3\.com))” /> </conditions> <action type=”Rewrite” value=”{C:0}” /> </rule> </outboundRules> </rewrite> </system.webServer> Explaining the server variable … Read more

Google Maps API: No ‘Access-Control-Allow-Origin’ header is present on the requested resource

https://maps.googleapis.com/maps/api doesn’t support getting requests from frontend JavaScript running in web apps in the way your code is trying to use it. Instead you must use the supported Google Maps JavaScript API, the client-side code for which is different from what you’re trying. A sample for the Distance Matrix service looks more like: <script> var … Read more

How can you debug a CORS request with cURL?

Here’s how you can debug CORS requests using curl. Sending a regular CORS request using cUrl: curl -H “Origin: http://example.com” –verbose \ https://www.googleapis.com/discovery/v1/apis?fields= The -H “Origin: http://example.com” flag is the third party domain making the request. Substitute in whatever your domain is. The –verbose flag prints out the entire response so you can see the … Read more

What security risks exist when setting Access-Control-Allow-Origin to accept all domains?

By responding with Access-Control-Allow-Origin: *, the requested resource allows sharing with every origin. This basically means that any site can send an XHR request to your site and access the server’s response which would not be the case if you hadn’t implemented this CORS response. So any site can make a request to your site … Read more