You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The default implementation of CORS Anywhere (server.js) does not restrict the target URLs. The ability to enforce restrictions based on the destination URLs has been requested in #67. Since I am going to add this to improve security, I should also do something with another glaring issue:
Normally resources from servers on localhost or a local private network are not really open to the web. CORS Anywhere is designed to allow any website to read public data from any other website (credentials are explicitly stripped). However, information in a private network is likely not supposed to be public information, so such requests should be rejected by default.
Implementation plan
Public API
Support a new option, dnsLookup, with the following signature:
To get the current behavior (i.e. allow any IP), use the following implementation of dnsLookup:
vardns=require('dns');require('cors-anywhere').createServer({// ...dnsLookup: function(hostname,callback){// This is the default behavior of lookupAndConnect in Node.js "net" module.dns.lookup(hostname,{hints: dns.ADDRCONFIG},callback);},// ...}).listen(port,host);// <--- Assuming that host/port are set elsewhere.
Implementation details in CORS Anywhere
The result of the lookup should be assigned to proxyOptions.target in the proxyRequest function.
This will still work fine for both HTTP and HTTPS, because the actual host name is set in the "Host" request header. Node.js's HTTPS/TLS/NET modules use this value for validating certificates (and SNI).
if(!req.corsAnywhereRequestState.dnsLookup){// Start proxying the requestproxy.web(req,res,proxyOptions);return;}vartargetUrl=url.parse(proxyOptions.target);req.corsAnywhereRequestState.dnsLookup(targetUrl.hostname,function(err,address){if(err){// TODO: Should errors just be propagated, or should we support something like// err.statusCode, err.statusText and err.message to customize the HTTP response?proxy.emit('error',err,req,res);return;}targetUrl.host=null;// Null .host so that .hostname + .port is used.targetUrl.hostname=address;proxyOptions.target=url.format(targetUrl);proxy.web(req,res,proxyOptions);});
The text was updated successfully, but these errors were encountered:
My use case for wanting this is to be able to deploy a staging version of a website outside the normal infrastructure. The backend services only support requests from the prod website. I therefore set up a CORS proxy, but I don't want it to be used for anything other than this one purpose.
Any updates on this? I'd much appreciate the ability to block request to the server's local area network, perhaps have it as the default behaviour. Thank you!
The default implementation of CORS Anywhere (server.js) does not restrict the target URLs. The ability to enforce restrictions based on the destination URLs has been requested in #67. Since I am going to add this to improve security, I should also do something with another glaring issue:
Normally resources from servers on localhost or a local private network are not really open to the web. CORS Anywhere is designed to allow any website to read public data from any other website (credentials are explicitly stripped). However, information in a private network is likely not supposed to be public information, so such requests should be rejected by default.
Implementation plan
Public API
Support a new option,
dnsLookup
, with the following signature:To get the current behavior (i.e. allow any IP), use the following implementation of
dnsLookup
:Implementation details in CORS Anywhere
proxyOptions.target
in theproxyRequest
function.The implementation can look like this (replacing
cors-anywhere/lib/cors-anywhere.js
Lines 122 to 123 in 143eff1
(and also using
location.href
instead oflocation
atcors-anywhere/lib/cors-anywhere.js
Line 87 in 143eff1
The text was updated successfully, but these errors were encountered: