The only way I can think to do this offhand would be to have the asterisk internal http server listen only on the loopback or private address and run an nginx reverse-proxy that’s bound to the external address and forwards to the asterisk internal http server. You’d then set a rule in nginx to only allow /ws.
But doesn’t PJSIP have its own bind address and port? It never uses HTTP/HTTPS for anything (except of course for initiating WebSocket connections), so I don’t see why anything in http.conf should have anything to do with it.
No. The bind and tls parameters in a websocket transport in pjsip.conf are ignored. The internal web server defined in http.conf is used for both ARI and WebRTC communications.
I find that a rather surprising oversight from a security viewpoint.
The only way I can think of to work around this is to have your own intermediary server. This will accept websocket-only connections from clients, and in turn it will make websocket-only connections to Asterisk.
Would that work? Is there a chance that any of the content might be (accidentally) interpreted by ARI?
That’s what I suggested above with nginx acting as a reverse proxy.
ARI REST endpoints and its event websocket are password protected so even if an /ari URL somehow made it through the reverse-proxy it wouldn’t do much good.
Thanks for the replies. Nginx was also the only thing I could come up with, I was hoping there was something else. I will try doing it with Nginx, hopefully it won’t have issues forwarding websocket traffic. Will come back with my findings.
I agree its not too good from a security viewpoint, the proxy solution sounds good enough but it would be nicer if we can deal with it directly in asterisk. ari.conf already has a parameter for allowed CORS origins, I wonder what the devs think of including something similar but for IP addresses. Sort of like the ACL for PJSIP endpoints.
The thing with proxying through a standard web server is, can you ensure that the connection will only be passed on after it has been upgraded to WebSocket, and not before?