jononomo

jononomo

For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error:

WebSocket connection to 'wss://web.my-app.convox/socket/websocket?userToken=726&vsn=1.0.0' failed: Error during WebSocket handshake: Unexpected response code: 403

I have also tried ws:// instead of wss:// and got the same result.

I used to have BasicAuth running in my app, but I have removed it.

My user_socket.ex file is as follows:

defmodule MyAppWeb.UserSocket do
	use Phoenix.Socket

	## Channels
	channel "vw:*", MyAppWeb.VowpalWabbitChannel

	## Transports
	transport :websocket, Phoenix.Transports.WebSocket, check_origin: false

	def connect(_params, socket) do
		{:ok, socket}
	end

	def id(_socket) do
		nil
	end
end

What can i do to connect to my websocket in a non-dev environment?

Thanks.

Showing Posts 12 to 3

namosca

namosca

Hi, I was having this problem and your answer worked. I had to change it in user_socket.ex and prod.exs.

baldmountain

baldmountain

@jononomo I just ran into this too. The way I fixed it is to use the check_origin option as suggested above, but instead of setting it false set it to a list of domains like

check_origin: ["//localhost", "//mycoolwebsite.com"]

where mycoolwebsite.com is the domain for your DigitalOcean Docker container.

Ryzey

Ryzey

Did you ever solve this? I am having the same problem. Websocket works on localhost but get 403 Forbidden when deployed on DigitalOcean in a Docker container.

jononomo

jononomo OP

@matiso Yes, my intention is to add the security back in one step at a time, but first I just want to be able to connect to my websocket.

matiso

matiso

From a security perspective, I would defintely not recommend disabling the origin check. It’s there for a reason, and disabling it to “just make it work” isn’t the right way to go.

IF your issue has to do with the origin, make sure to provide a whitelist of allowed origins, instead of completely disabling the check.

karmajunkie

karmajunkie

Yep, i missed that in your earlier message. Those are the only places you’d need to set it AFAIK. If its still an issue you’ll probably want to try to create a minimal reproduction repo and post a link here or ask on the slack phoenix channel.

Looking at your error, if you’re getting a 403 it may also be your authentication mechanism. Have you got any plugs like guardian that might be returning the 403 before your socket authenticates? You said earlier that you’d removed the Basic auth, so if that’s your only authentication you probably shouldn’t be getting a 403.

jononomo

jononomo OP

Isn’t this line doing it on the socket transport as well?

transport :websocket, Phoenix.Transports.WebSocket, check_origin: false
karmajunkie

karmajunkie

You’ll probably want to do that in your socket transport as well, see options on the transport documentation: https://hexdocs.pm/phoenix/Phoenix.Transports.WebSocket.html#content

jononomo

jononomo OP

Thanks, @karmajunkie – I have set check_origin to false in both my user_socket.ex file as follows:

transport :websocket, Phoenix.Transports.WebSocket, check_origin: false

and also in my prod.exs file as follows:

config :my_app, MyAppWeb.Endpoint,
  load_from_system_env: true,
  # url: [host: "example.com", port: 80],
  check_origin: false,
  cache_static_manifest: "priv/static/cache_manifest.json"

Is there any other place where I would need to set check_origin to false?

karmajunkie

karmajunkie

You probably want to set the check_origin option. By default I believe its whatever protocol, host, and port you set your host to. You’ll need to add any additional hosts to it there.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews