Gathering detailed insights and metrics for @royli/cors-anywhere
Gathering detailed insights and metrics for @royli/cors-anywhere
Gathering detailed insights and metrics for @royli/cors-anywhere
Gathering detailed insights and metrics for @royli/cors-anywhere
CORS Anywhere is a NodeJS reverse proxy which adds CORS headers to the proxied request.
npm install @royli/cors-anywhere
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (97.09%)
HTML (2.91%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
9,197 Stars
144 Commits
6,444 Forks
113 Watchers
2 Branches
8 Contributors
Updated on Jul 12, 2025
Latest Version
0.4.4
Package Id
@royli/cors-anywhere@0.4.4
Unpacked Size
107.69 kB
Size
30.15 kB
File Count
20
NPM Version
6.14.4
Node Version
12.18.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
CORS Anywhere is a NodeJS proxy which adds CORS headers to the proxied request.
The url to proxy is literally taken from the path, validated and proxied. The protocol part of the proxied URI is optional, and defaults to "http". If port 443 is specified, the protocol defaults to "https".
This package does not put any restrictions on the http methods or headers, except for cookies. Requesting user credentials is disallowed. The app can be configured to require a header for proxying a request, for example to avoid a direct visit from the browser.
1// Listen on a specific host via the HOST environment variable 2var host = process.env.HOST || '0.0.0.0'; 3// Listen on a specific port via the PORT environment variable 4var port = process.env.PORT || 8080; 5 6var cors_proxy = require('cors-anywhere'); 7cors_proxy.createServer({ 8 originWhitelist: [], // Allow all origins 9 requireHeader: ['origin', 'x-requested-with'], 10 removeHeaders: ['cookie', 'cookie2'] 11}).listen(port, host, function() { 12 console.log('Running CORS Anywhere on ' + host + ':' + port); 13}); 14
Request examples:
http://localhost:8080/http://google.com/
- Google.com with CORS headershttp://localhost:8080/google.com
- Same as previous.http://localhost:8080/google.com:443
- Proxies https://google.com/
http://localhost:8080/
- Shows usage text, as defined in libs/help.txt
http://localhost:8080/favicon.ico
- Replies 404 Not foundLive examples:
To use the API, just prefix the URL with the API URL. Take a look at demo.html for an example. A concise summary of the documentation is provided at lib/help.txt.
If you want to automatically enable cross-domain requests when needed, use the following snippet:
1(function() { 2 var cors_api_host = 'cors-anywhere.herokuapp.com'; 3 var cors_api_url = 'https://' + cors_api_host + '/'; 4 var slice = [].slice; 5 var origin = window.location.protocol + '//' + window.location.host; 6 var open = XMLHttpRequest.prototype.open; 7 XMLHttpRequest.prototype.open = function() { 8 var args = slice.call(arguments); 9 var targetOrigin = /^https?:\/\/([^\/]+)/i.exec(args[1]); 10 if (targetOrigin && targetOrigin[0].toLowerCase() !== origin && 11 targetOrigin[1] !== cors_api_host) { 12 args[1] = cors_api_url + args[1]; 13 } 14 return open.apply(this, args); 15 }; 16})();
If you're using jQuery, you can also use the following code instead of the previous one:
1jQuery.ajaxPrefilter(function(options) { 2 if (options.crossDomain && jQuery.support.cors) { 3 options.url = 'https://cors-anywhere.herokuapp.com/' + options.url; 4 } 5});
The module exports createServer(options)
, which creates a server that handles
proxy requests. The following options are supported:
getProxyForUrl
- If set, specifies which intermediate proxy to use for a given URL.
If the return value is void, a direct request is sent. The default implementation is
proxy-from-env
, which respects the standard proxy
environment variables (e.g. https_proxy
, no_proxy
, etc.).originBlacklist
- If set, requests whose origin is listed are blocked.['https://bad.example.com', 'http://bad.example.com']
originWhitelist
- If set, requests whose origin is not listed are blocked.['https://good.example.com', 'http://good.example.com']
checkRateLimit
- If set, it is called with the origin (string) of the request. If this
function returns a non-empty string, the request is rejected and the string is send to the client.redirectSameOrigin
- If true, requests to URLs from the same origin will not be proxied but redirected.
The primary purpose for this option is to save server resources by delegating the request to the client
(since same-origin requests should always succeed, even without proxying).requireHeader
- If set, the request must include this header or the API will refuse to proxy.['Origin', 'X-Requested-With']
.removeHeaders
- Exclude certain headers from being included in the request.["cookie"]
setHeaders
- Set headers for the request (overwrites existing ones).{"x-powered-by": "CORS Anywhere"}
corsMaxAge
- If set, an Access-Control-Max-Age request header with this value (in seconds) will be added.600
- Allow CORS preflight request to be cached by the browser for 10 minutes.helpFile
- Set the help file (shown at the homepage)."myCustomHelpText.txt"
For advanced users, the following options are also provided.
httpProxyOptions
- Under the hood, http-proxy
is used to proxy requests. Use this option if you really need to pass options
to http-proxy. The documentation for these options can be found here.httpsOptions
- If set, a https.Server
will be created. The given options are passed to the
https.createServer
method.For even more advanced usage (building upon CORS Anywhere), see the sample code in test/test-examples.js.
A public demo of CORS Anywhere is available at https://cors-anywhere.herokuapp.com. This server is only provided so that you can easily and quickly try out CORS Anywhere. To ensure that the service stays available to everyone, the number of requests per period is limited, except for requests from some explicitly whitelisted origins.
If you expect lots of traffic, please host your own instance of CORS Anywhere, and make sure that the CORS Anywhere server only whitelists your site to prevent others from using your instance of CORS Anywhere as an open proxy.
For instance, to run a CORS Anywhere server that accepts any request from some example.com sites on port 8080, use:
export PORT=8080
export CORSANYWHERE_WHITELIST=https://example.com,http://example.com,http://example.com:8080
node server.js
This application can immediately be run on Heroku, see https://devcenter.heroku.com/articles/nodejs for instructions. Note that their Acceptable Use Policy forbids the use of Heroku for operating an open proxy, so make sure that you either enforce a whitelist as shown above, or severly rate-limit the number of requests.
For example, to blacklist abuse.example.com and rate-limit everything to 50 requests per 3 minutes, except for my.example.com and my2.example.com (which may be unlimited), use:
export PORT=8080
export CORSANYWHERE_BLACKLIST=https://abuse.example.com,http://abuse.example.com
export CORSANYWHERE_RATELIMIT='50 3 my.example.com my2.example.com'
node server.js
Copyright (C) 2013 - 2016 Rob Wu rob@robwu.nl
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 3/27 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More