ResourceOverride
ResourceOverride copied to clipboard
XMLHttpRequest cannot load url. Response for preflight is invalid (redirect)
I'm trying to redirect requests from a webapp to an internal server. But I keep getting these errors in console whenever the app tries to send a request, and I'm unable to login because of it (api won't work)
The browser is sending an OPTIONS (preflight) request because whatever code that's making the request isn't satisfying the requirements to avoid a preflight request. See here: https://stackoverflow.com/questions/42168773/how-to-resolve-preflight-is-invalid-redirect-in-cors
Basically,
- The http method must be GET, HEAD, or POST
- The only headers you can set are Accept, Accept-Language, Content-Language, Content-Type, DPR, Downlink, Save-Data, Viewport-Width, or Width
- The Content-Type request header must be application/x-www-form-urlencoded, multipart/form-data, or text/plain
Resource Override can change request headers, although in this case, chrome seems to filter out the request automatically (probably so extensions can't change them because it's a security issue). If you need to use certain headers or an uncommon http method then I'm not sure there's much you can do. I suppose you could redirect the script that's causing the request to your own script so you can just make the request to the correct url from the beginning.
Let me know if you find a way around this, as odds don't look too good for a solution.
It's a minified script on a third-party app that I don't control. Additionally, asset names are obfuscated and change often.
That sounds rough... You might need something higher calibur like a system wide proxy. Maybe https://www.charlesproxy.com/documentation/tools/rewrite/ I'm not sure it's possible to do what you need through a chrome extension. Let me know if you figure out a way though.