Confused about how to handle CORS OPTIONS preflight requests

I sat down and debugged through the org.apache.catalina.filters.CorsFilter to figure out why the request was being forbidden. Hopefully this can help someone out in the future. According to the W3 CORS Spec Section 6.2 Preflight Requests, the preflight must reject the request if any header submitted does not match the allowed headers. The default configuration … Read more

.NET Web API CORS PreFlight Request

You can add a handler to deal with this type of request. Create a class derive from “DelegatingHandler”: public class PreflightRequestsHandler : DelegatingHandler { protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { if (request.Headers.Contains(“Origin”) && request.Method.Method.Equals(“OPTIONS”)) { var response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK }; // Define and add values to variables: origins, … Read more

Go gin framework CORS

FWIW, this is my CORS Middleware that works for my needs. func CORSMiddleware() gin.HandlerFunc { return func(c *gin.Context) { c.Writer.Header().Set(“Access-Control-Allow-Origin”, “*”) c.Writer.Header().Set(“Access-Control-Allow-Credentials”, “true”) c.Writer.Header().Set(“Access-Control-Allow-Headers”, “Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With”) c.Writer.Header().Set(“Access-Control-Allow-Methods”, “POST, OPTIONS, GET, PUT”) if c.Request.Method == “OPTIONS” { c.AbortWithStatus(204) return } c.Next() } }

How to authorize CORS preflight request on IIS with Windows Authentication

There are several ways to accomplish this, other answers can be found on this similar question –> Angular4 ASP.NET Core 1.2 Windows Authentication CORS for PUT and POST Gives 401 CORS Module It is possible to configure IIS by using the CORS Module. As seen here: https://blogs.iis.net/iisteam/getting-started-with-the-iis-cors-module And further information available here: https://blogs.iis.net/iisteam/getting-started-with-the-iis-cors-module The IIS … Read more

CORS error on request to localhost dev server from remote site

Original Answer I finally found the answer, in this RFC about CORS-RFC1918 from a Chrome-team member. To sum it up, Chrome has implemented CORS-RFC1918, which prevents public network resources from requesting private-network resources – unless the public-network resource is secure (HTTPS) and the private-network resource provides appropriate (yet-undefined) CORS headers. There’s also a Chrome flag … Read more

Chrome CORS error on request to localhost dev server from remote site

Original Answer I finally found the answer, in this RFC about CORS-RFC1918 from a Chrome-team member. To sum it up, Chrome has implemented CORS-RFC1918, which prevents public network resources from requesting private-network resources – unless the public-network resource is secure (HTTPS) and the private-network resource provides appropriate (yet-undefined) CORS headers. There’s also a Chrome flag … Read more

How to CORS-enable Apache web server (including preflight and custom headers)?

To fully CORS-enable an Apache web server, you need to have it configured to look like this: Header always set Access-Control-Allow-Origin “*” Header always set Access-Control-Allow-Headers “Authorization” Header always set Access-Control-Allow-Methods “GET” Header always set Access-Control-Expose-Headers “Content-Security-Policy, Location” Header always set Access-Control-Max-Age “600” RewriteEngine On RewriteCond %{REQUEST_METHOD} OPTIONS RewriteRule ^(.*)$ $1 [R=200,L] Longer explanation at … Read more