Commit Graph

134 Commits

Author SHA1 Message Date
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
Rob Wu
f07bdc4ea0 Add examples for modifying requests or responses 2016-05-14 23:16:45 +02:00
Rob Wu
bb4293a74d Version 0.4.0
- CI & 100% test coverage
- Do not crash when a malformed HTTP response is received.
- Remove getHandler (its documented form was broken anyway).
- Allow custom help file to be set.
- Add option to redirect same-origin requests instead of proxying them.
2016-03-19 19:17:18 +01:00
Rob Wu
e6695b8102 Add redirectSameOrigin
Some clients try to use CORS Anywhere, even for same-origin requests...
Add a new setting "redirectSameOrigin" to not waste server resources on
proxying such requests.

Fixes #42
2016-03-19 18:35:17 +01:00
Rob Wu
bacbbe0cb0 It's 2016
(and remove unnecessary section about Dependencies,
because it mentioned 3x in the previous section and package.json)
2016-02-26 18:26:40 +01:00
Rob Wu
66fdd6e662 100% test coverage :) 2016-02-26 18:23:29 +01:00
Rob Wu
411e95ac1d Merge pull request #40 from Rise-Vision/feature/custom-help-text
Feature/custom help text
2016-02-26 18:19:30 +01:00
rodrigopavezi
9f389e6f41 Added option for a custom help file 2016-02-26 14:16:20 -03:00
Rob Wu
ee93f70dc3 Increment threshold for memory failure on Node 0.x 2016-02-26 17:05:06 +01:00
Rob Wu
f081fe2ccf Fix tests: Explicitly start and close servers
Otherwise these tests fail on Node 0.10.x
2016-02-26 16:58:07 +01:00
Rob Wu
37f35fda35 Exclude coverage/ from linting 2016-02-26 16:32:47 +01:00
Rob Wu
fc9cf157d2 Remove getHandler
It is not supported, and its current form was not documented.
If you need to proxy a request without listening on a port, just
dispatch a 'request' event on the return value of createServer().
2016-02-26 16:21:59 +01:00