I'm working on an Angular web application. I need to make a POST request with a XML body to a server I don't have control over. The request needs an Authorization
header. I tried the following:
- Send the request directly: It only works when the application is served on
http://localhost
. Otherwise, the browser shows the following error:Access to XMLHttpRequest at 'server.com' from origin 'my-server.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
. - Use a browser extension that adds the missing header to responses: Unsafe, because the extension adds
Access-Control-Allow-Origin: *
to responses from all domains and that header allows requests from any domain. - Disable browser security: I ran Chrome using this command:
chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security
. Works when the application is running on a HTTPS server. However, it's unsafe, for the same reasons stated for the previous approach. - Use a third-party proxy: Works for a few requests, but the server blocks the proxy IP because the requests of all clients pass through the same proxy.
My project requires to bypass browser security without compromising security for non-related domains. My project also requires a different IP to be sent to the server by each client. That's required so that if a client overuses the feature, it won't affect other clients.
Is there a way I can add Access-Control-Allow-Origin: my-server.com
to all responses or add the header only for a specific server? Is there a way I can redirect each request to a different IP so that the server won't block all my clients? Are there any other workarounds?