Skip to content

Client is always accepted for undeclared namespaces #822

@llunn

Description

@llunn

Describe the bug
This issue is manifesting itself through flask-socketio, but I believe the source of the issue belongs here. When a client connects using a namespace that is not declared, the namespace is simply added and the client connects with no ability to execute code against the connection in order to reject it.

The end result is that it is possible to pollute the connection pool with phantom clients, and the server cannot detect when new clients connect.

The source of issue I believe is here:

if namespace not in self.rooms:

To Reproduce

  1. Stand up a bare bones server instance.
  2. Define an on_connect handler for '/'
  3. Define zero or more class based namespaces and register them
  4. Connect a client using a namespace that the server is not aware of.
  5. Client connection is blindly accepted, regardless of always_connect value.

Expected behavior
One of:

  1. Connections to namespaces that do not exist are flat out rejected; or
  2. Connections to namespaces that do not exist produce an exception; or
  3. Connect event is delegated to to / namespace connect, with relevant details on the namespace attempted to connect to.

In all cases, it is also expected that the / namespace connect event fires, which is also not occurring.

Logs

(58685) wsgi starting up on http://0.0.0.0:5000
(58685) accepted ('127.0.0.1', 50507)
1_szfyPlEneUJwA3AAAA: Sending packet OPEN data {'sid': '1_szfyPlEneUJwA3AAAA', 'upgrades': [], 'pingTimeout': 20000, 'pingInterval': 25000}
kombu backend initialized.
1_szfyPlEneUJwA3AAAA: Received request to upgrade to websocket
1_szfyPlEneUJwA3AAAA: Upgrade to websocket successful
1_szfyPlEneUJwA3AAAA: Received packet MESSAGE data 0/celery,{"authToken":"bGVlQHRvcnVzb2Z0LmNvbTo2MUE1MUI1NTrMnz4SGR56ssXsYgxiiGHGa5ck6g"}
/celery
1_szfyPlEneUJwA3AAAA: Sending packet MESSAGE data 0/celery,{"sid":"hOsZtTCikRL7RTIfAAAB"}
(58685) accepted ('192.168.0.60', 50513)
DTnpUXYe8iuRM0UdAAAC: Sending packet OPEN data {'sid': 'DTnpUXYe8iuRM0UdAAAC', 'upgrades': [], 'pingTimeout': 20000, 'pingInterval': 25000}
DTnpUXYe8iuRM0UdAAAC: Received request to upgrade to websocket
DTnpUXYe8iuRM0UdAAAC: Upgrade to websocket successful
DTnpUXYe8iuRM0UdAAAC: Received packet MESSAGE data 0/remote,{"authToken":"bGVlQHRvcnVzb2Z0LmNvbTo2MUE1MUI1NTrMnz4SGR56ssXsYgxiiGHGa5ck6g","userCtx":{"name":"[email protected]","roles":["confide-analytics","emmit-admin","confide-admin"]}}
/remote
DTnpUXYe8iuRM0UdAAAC: Sending packet MESSAGE data 0/remote,{"sid":"DhB9khVI587ck8pjAAAD"}
(58685) accepted ('192.168.0.60', 50558)

Additional context
If this is not intended behaviour, a possible easy solution is to add an else to to the if else if block of Server._trigger_event

If more detail is required, please let me know!

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions