Security Overview

How encryption, authentication and permissioning work together

Security in deepstream is based on three interrelated concepts:

- encrypted connections
- user authentication
- granular permissions

Here’s how they work together:

Encrypted Connections

deepstream supports transport layer security for web-facing connections using HTTPS and WSS. To setup SSL on deepstream, you need to provide the following configuration keys:

  key: fileLoad(./my-key.key)
  cert: fileLoad(./my-key.key)

It’s highly recommended to always use a seperate process to do SSL termination. Usually via a load balancer (e.g. Nginx or HA Proxy). To learn more about this, head over to the Nginx Tutorial.


Every incoming connection needs to pass an authentication step. This happens when the client calls login(data, callback). deepstream comes with three built-in authentication mechanisms:

  • none allows every connection. Choose this option for public sites that don’t require access controls.
  • file reads authentication data from a static file. This is a good choice for public read / private write use cases, e.g. sports result pages that let every user visit, but only a few backend processes update the result.
  • http contacts a configurable HTTP webhook to ask if a user is allowed to connect. This is the most flexible option as it allows you to write a tiny http server in any language that can connect to databases, active directories, oAuth providers or whatever else your heart desires.

Apart from just accepting / denying incoming connections, the authentication step can also provide two extra bits of information:

  • clientData is returned to the client upon login. This is useful to provide user specific settings upon login, e.g. { "view": "author" } for a blog
  • serverData is kept privately on the server and passed to the permission handler whenever a client performs an action. This makes certain security concepts possible, e.g. role based authentication.
"system-settings": {
    //publicly readable
    "read": true,
    //writable only by admin
    "write": " === 'admin'"

Authentication FAQ

  • When exactly does authentication happen? When a deepstream client is created, it establishes a connection straight away. The connection however remains in a quarantine state until login() is called. This makes sure that auth-data is sent over an encrypted connection and helps to get the at times time-consuming connection establishment out of the way while the user is busy typing passwords.
  • Can I read usernames for auth purposes out of a deepstream record? There’s no built-in support for this at the moment, but it’s easy to use the http auth-type and write a server that reads from the same database or cache deepstream connects to.
  • Can a user connect more than once at the same time Yes. The same user can connect multiple times from separate browser windows or devices.


Permissioning is the act of deciding whether a specific action, e.g. writing to a record or subscribing to an event is allowed. To help with this, deepstream uses an expressive, JSON-based permissioning language called Valve. There’s a lot to say about Valve. Here’s a small Valve File that should give you a first impression, to learn more though head over to the permissioning tutorial


    create: true
    delete: true
    write: true
    read: true
    listen: true

    read: true
    create: " === $userid"
    write: " === $userid"

    write: "!oldData.value || data.value > oldData.value"
    create: true
    read: true

    delete: "$firstname.toLowerCase() === 'egon' && $lastname.toLowerCase() === 'miller'"

    create: true
    write: "_('item/' + data.itemId ).stock > 0"


    listen: true
    publish: true
    subscribe: true

    listen: true
    publish: true
    subscribe: true

    publish: false
    subscribe: false

    publish: " === 'client-a'"
    subscribe: " === 'client-b'"

    publish: "$topic === 'tea-cup-pigs'"

    publish: "typeof data === 'number' && data > 10"

    publish: "$city.toLowerCase() ==="


    provide: true
    request: true

    provide: " === 'client-a'"
    request: " === 'client-b'"

    request: "typeof data.firstname === 'string' && typeof data.lastname === 'string'"