majestic icon indicating copy to clipboard operation
majestic copied to clipboard

Connect over wss when loaded over https

Open sabrehagen opened this issue 5 years ago • 20 comments

When loading majestic over an https connection, the client attempts to connect over ws not wss.

74f76c73-3781-4cd6-b0d2-903cc6db78c2

It seems the apollo http link will require https too.

sabrehagen avatar Mar 26 '19 07:03 sabrehagen

Curious to know the use case behind using over an https connection?

Raathigesh avatar Mar 26 '19 08:03 Raathigesh

Feel free to reopen if this is a blocker but closing this for now.

Raathigesh avatar Apr 02 '19 10:04 Raathigesh

Yes, this is a fundamental blocker.

Curious to know the use case behind using over an https connection?

Are you implying you don't secure your HTTP communications?

sabrehagen avatar Apr 02 '19 13:04 sabrehagen

Majestic is meant to be used locally in the same way as a local dev server so I'm trying to understand the benefits of having a secure connection.

Raathigesh avatar Apr 03 '19 00:04 Raathigesh

I would never open a service over an unsecured connection. What people do in development reflects in production, as production is an artefact of development. Relying on network isolation as a substitute for secure http connections is a weakness waiting to be exploited.

On Wed, 3 Apr 2019, 11:19 AM Raathi Kugarajan <[email protected] wrote:

Majestic is meant to be used locally in the same way as a local dev server so I'm trying to understand the benefits of having a secure connection.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Raathigesh/majestic/issues/65#issuecomment-479268090, or mute the thread https://github.com/notifications/unsubscribe-auth/ABCzyO2xR4c-xiHWidjqCLjFlpEQY1cUks5vc_OlgaJpZM4cKzJM .

sabrehagen avatar Apr 03 '19 04:04 sabrehagen

@Raathigesh: Thank you very much for your work on Majestic, it's an awesome tool! :)

I am currently working to get it to run on a server. It's password protected but technically public-facing. This makes it a lot easier for our distributed team to run the same tests that lay centrally on the server. That way not everyone has to deep-dive into the inner workings of Majestic and Jest testing but can simply "click a button to check if everythings works" (= green).

Right now I have majestic running behind an nginx server with active HTTPS but the missing wss:// is the last remaining hurdle. So at least for me there's absolutely usecase for it and I'd love to see it implemented

justusbluemer avatar Jul 15 '19 13:07 justusbluemer

@justusbluemer I'm glad that you find the tool useful. Are you open to contributing the change?

Raathigesh avatar Jul 16 '19 00:07 Raathigesh

I'm running into this too. Same issue as @justusbluemer I get the initial decision not to include it, but seems like pretty simple thing to add, and without it its not possible to use over https connections.

NickBolles avatar Nov 11 '19 04:11 NickBolles

@NickBolles I'm not against it but didn't get the time or motivation to work on it yet. Reopening the issue. Feel free to send a PR if you are interested.

Raathigesh avatar Nov 12 '19 05:11 Raathigesh

For me this is crucial too. Running via an Nginx proxy.

I tried changing (in ui/apollo-client.ts) let WS_URL = "ws://localhost:4000"; to let WS_URL = "wss://localhost:4000/wss"; but that did not help.

Changing ws:// to wss:// should enable the websocket over the https proxy. And adding /wss helps in Nginx proxying the websocket the right way.

But my guess is adding /wss makes the websocket of Majestic fail?

robertheessels avatar Dec 11 '19 14:12 robertheessels

We need to show that UI-test are passing on the dev-server for the whole team. Please, do this.

pavelzubov avatar Jan 28 '20 09:01 pavelzubov

Feel free to send a PR if you are interested.

@Raathigesh I tried to change http and ws to secure type in client and server, but I don't have the necessary experience in graphql-yoga, maybe this requires additional config (I don't know values for https option in server.start). If you can give me the necessary instructions for make this work, I could send a PR with this.

pavelzubov avatar Jan 29 '20 06:01 pavelzubov

@pavelzubov Thanks for looking into it.

Yes, the https options can be provided through the start method of the server.

The doc also mentions a bit more about https option - https://github.com/prisma-labs/graphql-yoga#startoptions-options-callback-options-options--void----null-promisevoid

Raathigesh avatar Jan 29 '20 07:01 Raathigesh

@Raathigesh yes, I was read it) But, what I will write in cert field? I can't put my own certificate or suggest users to put their own in the config. I'm going the wrong way. I shouldn't change the graphql-yoga config. This should work in HTTP as before. Issue in that:

  • Majestic works over HTTP, we provide access to Majestic through a proxy, which adds a HTTPS.
  • Your UI expects HTTP connection and sends request to open an insecure web-socket.
  • But UI run over HTTPS for the browser, and ws-requests are blocked in HTTPS. We need wss-requests.

What we can change for solve this problem?

pavelzubov avatar Jan 30 '20 07:01 pavelzubov

@pavelzubov The URL to connect to the server is in https://github.com/Raathigesh/majestic/blob/master/ui/apollo-client.ts.

Is changing those URLs to wss be enough? If so, we could introduce a command-line argument which when provided will change the client URL to wss.

Raathigesh avatar Jan 30 '20 09:01 Raathigesh

@Raathigesh no, @robertheessels write about it above in https://github.com/Raathigesh/majestic/issues/65#issuecomment-564582818. I get the following message in console: image

pavelzubov avatar Jan 30 '20 10:01 pavelzubov

So that means we have to provide the cert and key to the graphql-yoga server. We can accept the paths to the cert and the key as command-line arguments and then provide those to the server.

But you also mentioned the below in your previous comment which is confusing me.

I'm going the wrong way. I shouldn't change the graphql-yoga config.

Raathigesh avatar Jan 30 '20 11:01 Raathigesh

@Raathigesh Oh, sorry, I made a mistake. I ran the code on localhost (on HTTP). This of course will return an error. On server changing URLs to wss and https works. I can send PR. This change applies for PRODUCTION, so I use protocol from window.location and condition for webSocket protocol inside if (PRODUCTION) condition :

let WS_URL = "ws://localhost:4000";
let HTTP_URL = "http://localhost:4000";
if (PRODUCTION) {
  const WS_PROTOCOL = window.location.protocol === "https:" ? "wss:" : "ws:";
  WS_URL = `${WS_PROTOCOL}//${window.location.host}`;
  HTTP_URL = `${window.location.protocol}//${window.location.host}`;
}

pavelzubov avatar Jan 30 '20 13:01 pavelzubov

@pavelzubov That looks good to me. Let's do that 👍

Raathigesh avatar Jan 30 '20 22:01 Raathigesh

@Raathigesh I make PR: #182 We ran into difficulties and I think that these page will be useful for Majestic users who will try use it on HTTPS and nginx: https://www.nginx.com/blog/websocket-nginx/ Without this websockets in Majestic will not work.

pavelzubov avatar Feb 07 '20 11:02 pavelzubov