Commit Graph

13 Commits

Author SHA1 Message Date
Daniel Sockwell 1765dc39ee Check oauth scopes and reject unauthorized requests 2019-07-04 13:27:11 -04:00
Daniel Sockwell f8a82caa2d Support passing access tokens via Sec-WebSocket-Protocol header
Previously, the access token needed to be passed via the query string;
with this commit, the token can be passed *either* through the query
string or the Sec-WebSocket-Protocol header.

This was done to correspond to the changes made to the streaming.js
version in [Improve streaming server security](https://github.com/tootsuite/mastodon/pull/10818).
However, I am not sure that it *does* increase security; as explained
at <https://support.ably.io/support/solutions/articles/3000075120-is-it-secure-to-send-the-access-token-as-part-of-the-websocket-url-query-params->,
there is generally no security advantage to passing sensitive information
via websocket headers instead of the query string—the entire connection
is encrypted and is not stored in the browser history, so the typical
reasons to keep sensitive info out of the query string don't apply.

I would welcome any corrections on this/reasons this change improves
security.
2019-07-04 10:57:15 -04:00
Daniel Sockwell 280cc60be9 Add hard-coded "sec-websocket-protocol" response header 2019-07-04 09:33:50 -04:00
Daniel Sockwell a6a7ebeae1 Add dotenv configuration 2019-05-10 06:22:26 -04:00
Daniel Sockwell 8ae9bbfac5 Revised WebSocket implementation 2019-05-10 01:47:29 -04:00
Daniel Sockwell 54ad55e0c0 Basic WebSocket support 2019-05-09 11:52:05 -04:00
Daniel Sockwell 6d037dd5af Working WS implemetation, but not cleaned up 2019-05-08 23:02:01 -04:00
Daniel Sockwell 4649f89442 Add unit tests, (some) integration tests, and documentation 2019-04-30 18:41:13 -04:00
Daniel Sockwell 9e921c1c97 Add ability for multiple clients to connect to the same pub/sub connection 2019-04-28 17:28:57 -04:00
Daniel Sockwell 425a9d0aae Allow seperate SSE responses to share Redis pubsub
This commit implements a shared stream of data from Redis, which
allows all SSE connections that send the same data to the client
to share a single connection to Redis.  (Previously, each client
got their own connection, which would significantly increase the
number of open Redis connections—especially since nearly all clients
will subscribe to `/public`.)
2019-04-26 20:00:11 -04:00
Daniel Sockwell f676e51ce4 Add limit on number of active streams
This commit tracks the number of active Pub/Sub streams and adds code to
keep the total number of streams below 400.  (When additional users
attempt to connect past that point, the server will wait for an slot
to open up).  This prevents "too many open file" panics and makes the
server better behaved in general.  However, we may need to revisit it
based on what capacity we want the server to have.

This commit also includes some general refactoring.
2019-04-23 14:07:49 -04:00
Daniel Sockwell e1257146cd Close Redis connections when SSE stream ends
This commit tracks the existence of the SSE stream and closes the
connection to the redis pub/sub channel when the stream is closed.  This
prevents the number of redis connections from growing over time.

Note, however, that the current code still subscribes to one redis
channel per SSE connection rather than reusing existing subscriptions.
This will need to be fixed in a later PR.
2019-04-21 09:21:44 -04:00
Daniel Sockwell 5011abaf77 Add language and notification filters 2019-04-19 17:06:29 -04:00