145 Commits

Author SHA1 Message Date
Tony Tang
7e3115fad0 feat: make vercel compatible
Signed-off-by: Tony Tang <tonytang@lilith.com>
2025-10-15 11:36:13 +08:00
Rob Wu
70aaa22b3f Merge pull request #376 from alex-lushiku/patch-1
Fix typo
2021-09-04 22:42:08 +02:00
Noodles
c84078bcff Fix typo 2021-08-31 21:01:43 +02:00
Rob Wu
02f0cbd929 Add LICENSE file based on README.md #297 2021-03-22 21:36:23 +01:00
Rob Wu
34ec83b25c Show "400 Missing slash" when needed #238 2021-03-22 21:18:31 +01:00
Rob Wu
207e1e9ed9 Add Node 15.x to Travis 2021-03-22 12:31:24 +01:00
Rob Wu
d33bd647de Migrate travis-ci from .org to .com 2021-03-22 12:29:14 +01:00
Rob Wu
a9143e7244 Fix test expectation for old node 2021-03-22 12:16:06 +01:00
Rob Wu
3c87a51664 Support NODE_TLS_REJECT_UNAUTHORIZED=0 to ignore client errors #341
Apparently `NODE_TLS_REJECT_UNAUTHORIZED` is only effective if
`rejectUnauthorized` was not overridden by the code:
85e6089c4d/lib/_tls_wrap.js (L1583-L1591)

But the underlying library does override it:
https://github.com/http-party/node-http-proxy/blob/v1.11.1/lib/http-proxy/common.js#L53-L55

Fix this by overriding the option via the library's "secure" option.
2021-03-21 23:38:32 +01:00
Rob Wu
d10efb1b46 Version 0.4.4
- Omit unnecessary `Access-Control-Max-Age` (#277)
- Remove more Heroku-specific headers (#278)
- Add `handleInitialRequest` option (#335)
- Document access requirements for public demo (#301)
- Update gTLD list
2021-03-17 21:31:11 +01:00
Rob Wu
94a325b225 Update gTLD list 2021-03-17 21:30:38 +01:00
Rob Wu
1bd95282ad Add note about availability of public demo server
Referencing #301
2021-03-17 21:18:23 +01:00
Rob Wu
4c18680552 Expand handleInitialRequest documentation #335 2021-03-17 21:12:42 +01:00
Rob Wu
9f1af82434 Add handleInitialRequest option to support #301
The custom filtering logic is not part of the public repository, to
keep the project clean.
2021-02-01 22:20:35 +01:00
Rob Wu
528ad7109f Remove obsolete values from server.js's removeHeaders
`X-Heroku-Dynos-In-Use`, `X-Heroku-Queue-Depth` and
`X-Heroku-Queue-Wait-Time` have already been dropped in 2013:
https://devcenter.heroku.com/changelog-items/218
2020-09-28 23:28:54 +02:00
Rob Wu
c8a2091310 Merge pull request #278 from bulk88/no_heroku_headers_to_origin
remove Heroku specific Req headers from being sent to Origin
2020-09-28 23:27:51 +02:00
bulk88
7271e29f21 remove Heroku specific Req headers from being sent to Origin
-saves bytes, and avoids triggering IDS/WAF alarms since browser finger
 printing will prove these headers are unnatural and on SSL must be a MITM
 attack

-leave x-forwarded-* intact since they can be used to block CORS proxy
 abuse if the not-CORS origin webmaster really has to block the proxy
 and they are not unique to Heroku platform
2020-09-28 06:19:06 -04:00
Rob Wu
3bab870d3f Merge pull request #277 from bulk88/no_AC_max_age_header_on_get_post_meth
only send Access-Control-Max-Age if preflight request, not POST/GET
2020-09-27 22:44:37 +02:00
bulk88
b3a13b026c only send Access-Control-Max-Age if preflight request, not POST/GET
-Access-Control-Max-Age header only has meaning for preflights, not
 POST or GET, saves wire bytes by excluding it from POST/GET/etc,
 and future problems if ACMA on a content HTTP method is given
 meaning by W3C or a browser vendor

-fix expectNoHeader() test helper func ,this was a no-op before by
 accident and would NEVER fail,
 supertest/test.js:Test.prototype._assertFunction requires an retval of
 class type Error if test fail, not a string or a number or Object
2020-09-27 15:21:40 -04:00
Rob Wu
a0309e6c47 Version 0.4.3
- Reject invalid URLs in redirects (fixes regression from 0.4.2) (#234)
- Update memory tests for recent Node versions.
2020-05-06 23:26:35 +02:00
Rob Wu
a9e06a9dab Reject invalid redirects
Fixes #234.
2020-05-06 23:25:17 +02:00
Rob Wu
0a3b8e965f Pass --max-http-header-size in supported versions only 2020-05-02 19:52:05 +02:00
Rob Wu
2579fb6c0d test-memory: fix test by passing --max-http-header-size
The test broke because Node lowered the maximum header size to defend
against large headers ( CVE-2018-12121 ).

In the test, we do actually want to pass large headers, because all
processing in CORS Anywhere is based on headers (the request body would
just be forwarded to the destination server).

The test failed intermittently with ECONNRESET or "socket hang up"
because the server (under test) would close the socket upon receiving
a request with too large request headers.
2020-05-02 19:20:08 +02:00
Rob Wu
001fbef926 Update test expectation for Node 12.x 2020-05-02 19:19:35 +02:00
Rob Wu
a21400378c Version 0.4.2
- Reject invalid URLs earlier instead of trying to continue with the
  request (and failing anyway).
- Explicitly close the response when an error occurs for Node 13+.
- Update tests to cover up to Node 14 (was up to 9).
2020-05-02 17:58:26 +02:00
Rob Wu
4ddb796e28 Explicit early out for invalid URLs 2020-05-02 17:55:57 +02:00
Rob Wu
20d5d0480e test-memory: destroy response to free socket
Starting from Node 12, the test started to fail because of
intermittent socket errors, such as ECONNRESET and "socket hang up".

Destroying the response before triggering a new request resolves it.
2020-05-02 17:20:16 +02:00
Rob Wu
7222fce684 Extend supported Node.js from <=9 to <=14 2020-05-02 16:45:42 +02:00
Rob Wu
4814647a9d Reject invalid requests instead of crashing (#142) 2018-10-31 23:58:21 +01:00
Rob Wu
462f844e22 Fix failing test in test/test-ratelimit 2018-10-31 12:28:55 +01:00
Rob Wu
2ee31471ce Version 0.4.1
- Add ability to rate-limit/block requests by origin (#45).
- Avoid crashing on invalid HTTP status codes (#95).
- Support and test coverage for latest Node.js versions (up to 9).
- Support `Access-Control-Max-Age` via `corsMaxAge` option.
- Listen on `0.0.0.0:8080` by default instead of `127.0.0.1:8080`.
  (use `HOST` and `PORT` environment variables to override this).
- Update gTLD list.
2017-12-01 14:05:34 +01:00
Rob Wu
b419acc6e5 Explicitly list all files for the npm package 2017-12-01 14:05:25 +01:00
Rob Wu
7b6ce1a3df Fix failing tests for 0.10.x, 4.x and 5.x
Travis build failed on "Uncaught TypeError: Object.keys called on non-object".
That's a real error (res._headers was initially null until a header is set).
2017-11-11 02:08:44 +01:00
Rob Wu
d2b5dd38bb Add Node 9.x to Travis
Locally tested that the tests pass with Node 9.0.0 and 9.1.0
Also modified a test expectation for Node 9.0.0+
2017-11-11 01:32:39 +01:00
Rob Wu
6741f810f9 Remove engines.npm (#92)
NPM 5.5.1 is not compatible with Node.js 9.1.0.
Let's use the npm that ships with node.
2017-11-11 01:32:29 +01:00
Rob Wu
53101b9a21 Update gTLD list 2017-11-11 00:34:56 +01:00
Rob Wu
4a46541da4 Catch error due to invalid status code (#95) 2017-11-08 22:23:58 +01:00
Rob Wu
143eff177c Merge pull request #77 from gnjack/maxAge
Allow caching of CORS headers by setting Access-Control-Max-Age header
2017-07-16 11:10:36 +02:00
Jack Tench
49d429dd60 Do not send Access-Control-Max-Age header if corsMaxAge is 0 (default) 2017-07-14 13:22:53 +01:00
Jack Tench
10df7c9f4a Rename maxAge to corsMaxAge and set the default corsMaxAge to 0.
Set corsAnywhereRequestState before calling withCORS and use the state instead of a parameter to get corsMaxAge.
2017-07-14 12:29:15 +01:00
Jack Tench
881392cfaf Add maxAge config option. If set, an Access-Control-Max-Age header with this value (in seconds) will be added. 2017-07-13 19:13:37 +01:00
Rob Wu
70400ab166 Monkey-patch nock, add Node v8 to test matrix 2017-07-13 18:58:29 +02:00
Rob Wu
f016bd71f5 Update test expectation for "100 GET requests 50k"
Locally Node v7 and v8 also have higher memory expectations,
so just use the same maximum memory value for v0.x and non-v0.x.
2017-07-13 18:57:26 +02:00
Rob Wu
99133b02b4 Explicit Node versions in Travis build matrix
This communicates more clearly for which versions of Node.js
the tests have run.

8 is not listed because tests are failing due to the nock HTTP mocking
library being incompatible with Node v8.
2017-07-13 18:09:52 +02:00
Rob Wu
ded44cb5d0 Upgrade supertest + nock to recent version
The most recent version that was explicitly marked as compatible with
Node.js 0.10.x
2017-07-13 17:32:45 +02:00
Rob Wu
dcc64052e3 Change response handling hook
When proxyReq is aborted (by us - in response to a redirect response),
it can ultimately trigger an "error" event of type ECONNRESET.
This error was unconditionally propagated to the error handler:
https://github.com/nodejitsu/node-http-proxy/blob/v1.11.1/lib/http-proxy/passes/web-incoming.js#L134-L140

Our proxy error handler responds by writing a response + error code,
which prevents the response from being overwritten.

I found this after upgrading the nock library to 5.2.1+, which contains
510e31c73e
The redirect tests that were previously passing in Node 0.10.x were
failing, with errors like "Can't set headers after they are sent.".

The new implementation makes sure that the proxied response is not
forwarded to the original response.
2017-07-13 17:08:31 +02:00
Rob Wu
81ed058784 Update mocha to ^3.4.2
to unlock goodies such as --inspect / --inspect-brk
2017-07-13 12:45:44 +02:00
Alexander Pinnecke
97c6e53020 Fixed example in README to bind correct host 2017-02-03 15:03:05 +01:00
Rob Wu
efc13eec1f Correctly parse environment list in server.js
Previously an unset value resulted in [""] instead of [].
2016-05-31 20:33:05 +02:00
Rob Wu
6c4234f2b3 Add rate-limiting functionality #45
- Add checkRateLimit option to the API.
- Extend the default server.js with environment variables
  CORSANYWHERE_WHITELIST (re-using originWhitelist) and
  CORSANYWHERE_RATELIMIT (using the new checkRateLimit option)
  to make it easy to enforce usage limits.
- Document that Heroku doesn't want open proxies.
2016-05-31 00:52:26 +02:00