[security.websocket]
The Origin check on WebSocket upgrades, which stops other websites from opening sockets with your visitors' cookies.
gio.toml
[security.websocket]
check_origin = true # the defaultBrowsers let any page open a WebSocket to any server and send that server's cookies with it (cross-site WebSocket hijacking). The upgrade is a GET, so CSRF protection alone would not cover it: GioJS judges every upgrade like an unsafe request instead.
Reference
| Key | Default | Description |
|---|---|---|
check_originboolean | true | Check the Origin (and Sec-Fetch-Site) of every WebSocket upgrade with the rules of [security.csrf]: your own host, an origin in [security.csrf] trusted_origins, or a client with neither header (not a browser) is accepted; anything else gets 403 before the connection is upgraded. |
Behavior
- Independent of
[security.csrf] enabled: turning CSRF protection off because your forms carry tokens leaves this check on, since form tokens do nothing for WebSockets. - It shares the CSRF lists:
trusted_originsare accepted here too, andexemptpaths skip this check as well - exempt a public WebSocket API meant to be used from any site. - A refusal is a
403with a plain-text body naming the setting to change (cross-site WebSocket upgrade blocked by CSRF protection - ...).
Startup warnings
| When | Startup warning |
|---|---|
check_origin = false | [security.websocket] check_origin = false: any website can open WebSockets to this server with your visitors' cookies - prefer listing origins in [security.csrf] trusted_origins, or public endpoints in [security.csrf] exempt |
Examples
A public WebSocket API
Keep the check for the app's own sockets and open one path to every site:
gio.toml
[security.csrf]
exempt = ["/api/public-feed"]A client on another origin
gio.toml
[security.csrf]
trusted_origins = ["https://dashboard.example.com"]Good to know
- A socket accepted here still has to pass its route's
wsHandler, which can check the session and refuse it. See Authenticating connections. - With
[websocket] enabled = falseupgrades are answered501. This check still runs before that, so a cross-site upgrade gets403.
Related
Version history
| Version | Changes |
|---|---|
v0.1.0-beta.8 | Introduced, on by default; turning it off logs a startup warning. |