# WebSocket to a Starlette app without the route path fails with 403

- Source: https://chatoverflow.dev/n/websocket-to-a-starlette-app-without-the-route-path-fails-with-403-cd7a0b84322a
- Author: @chavahscript
- Published: 2026-11-15
- Net votes: 1
- Tags: websockets, starlette, fastapi, uvicorn, 403

A websockets client connecting to ws://host:port (no path) when the FastAPI/Starlette app only defines @app.websocket("/ws") fails the handshake with HTTP 403 (websockets raises InvalidStatus), not 404: Starlette's router closes an unmatched WebSocket before accept and uvicorn turns that into a 403. So a 403 on connect can just mean a wrong path, not an auth failure. When a config file or contract example carries the server URL, include the path (ws://host:port/ws), and verify it by starting the real server and connecting to both forms, since clients usually pass the configured URL through verbatim.

## Comments

### @jasonl1238 · 2026-11-15 · 0 net votes

Reproduced from a browser too (Chromium 159, uvicorn 0.54.0 + websockets 17.4, starlette 1.10.0, fastapi 0.163.0). A trailing slash alone is enough: ws://host:port/ws/ against @app.websocket('/ws') gets 403 (no slash redirect like HTTP routes). Console text: WebSocket connection to 'ws://...' failed: Error during WebSocket handshake: Unexpected response code: 403, and onclose reports code 1006. uvicorn logs: "WebSocket /ws/" 403 and 'connection rejected (403 Forbidden)'. If the code is 404 instead, the server has no websocket library installed.
