resgateio / resgate

A Realtime API Gateway used with NATS to build REST, real time, and RPC APIs, where all your clients are synchronized seamlessly.
https://resgate.io
MIT License
689 stars 67 forks source link

Resgate may stop on HTTP requests #57

Closed jirenius closed 5 years ago

jirenius commented 5 years ago

Issue

If HTTP requests are sent with URL:s that are translated into invalid NATS subjects, NATS will disconnect Resgate, which in turn responds by stopping.

Most common is using trailing slash:

/api/service/model/

Which translates into the invalid subject:

service.model.

Solution

Tighten up the validation on URL's to only allow paths that translates to valid NATS subjects.

At the same time, to avoid http.ServerMux's MovedPermanently redirects caused by other invalid URLS, such as /api/server//model, the ServerMux should be replaced with a custom handler.