Skip to content

Commit

Permalink
Validate websocket origin (#3569)
Browse files Browse the repository at this point in the history
WebSockets can be initiated from any site on the internet and still have
the user’s cookies and session. This pull request restricts the sites
which are allowed to open sockets to the app.

See W-14666893
  • Loading branch information
jstvz authored Jul 31, 2024
1 parent 17c47c8 commit 5411d78
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion metadeploy/routing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import AllowedHostsOriginValidator
from channels.sessions import SessionMiddlewareStack
from django.core.asgi import get_asgi_application
from django.urls import path
Expand All @@ -20,6 +21,8 @@
application = ProtocolTypeRouter(
{
"http": get_asgi_application(),
"websocket": SessionMiddlewareStack(AuthMiddlewareStack(websockets)),
"websocket": AllowedHostsOriginValidator(
SessionMiddlewareStack(AuthMiddlewareStack(websockets))
),
}
)

0 comments on commit 5411d78

Please sign in to comment.