Related Documentation
Made by
Kong Inc.
Supported Gateway Topologies
hybrid db-less traditional
Supported Konnect Deployments
hybrid cloud-gateways serverless
Compatible Protocols
ws wss
Minimum Version
Kong Gateway - 3.1
Tags

Validate individual WebSocket messages against a user-specified schema before proxying them.

The message schema can be configured by type (text or binary) and sender (client or upstream).

This plugin supports validation against JSON schema draft4.

How the WebSocket Validator plugin works

When an incoming message is invalid according to the schema, a close frame is sent to the sender (status: 1007) and the peer before closing the connection.

For example, here’s what it looks like when validating that client text frames:

  • Are valid JSON
  • Are a JSON object ({})
  • Have a name attribute (of any type)
 
sequenceDiagram
autonumber
    activate Client
    activate Kong
    Client->>Kong: text(`{ "name": "Alex" }`)
    activate Upstream
    Kong->>Upstream: text(`{ "name": "Alex" }`)
    Client->>Kong: text(`{ "name": "Kiran" }`)
    Kong->>Upstream: text(`{ "name": "Kiran" }`)
    Client->>Kong: text(`{ "missing_name": true }`)
    Kong->>Client: close(status=1007)
    Kong->>Upstream: close()
    deactivate Upstream
    deactivate Kong
    deactivate Client
  

The clients with the names Alex and Kiran pass validation, but when missing_name appears, it’s considered invalid and the plugin sends a close frame.

Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!