Skip to content

TypeError: crypto.hash is not a function in connection.js #5333

@mauricedcastro

Description

@mauricedcastro

Bug Description

Versions of Node prior to 26 do not support the crypto.hash function. In release 7.17.0 a patch was introduced that changed from the old style of generating digests to the new style.

Reproducible By

Expected Behavior

Function should work as expected with earlier versions of Node

Logs & Screenshots

Problem was observed in Hoobs:

5/28/2026, 11:34:35 PM Unifi Protect Bridge UniFi Protect Using FFmpeg version: 8.0-homebridge-alpine-aarch64-static.
5/28/2026, 11:34:37 PM Unifi Protect Bridge ERROR TypeError: crypto.hash is not a function
at Object.processResponse (/var/lib/hoobs/unifiprotectbridge/node_modules/undici/lib/web/websocket/connection.js:163:29)
at /var/lib/hoobs/unifiprotectbridge/node_modules/undici/lib/web/fetch/index.js:1081:19
at node:internal/process/task_queues:140:7
at AsyncResource.runInAsyncScope (node:async_hooks:206:9)
at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
at processTicksAndRejections (node:internal/process/task_queues:95:5)

Environment

Hoobs

node --version
v20.5.1

Additional context

Suggested solution (I apologise its been too many years since I did Javascript to do this well)

Check node version and use previous code if major version less than 26

undici/lib/web/websocket

--- connection.js.orig 2026-05-29 11:02:06
+++ connection.js 2026-05-29 11:04:57
@@ -160,7 +160,14 @@
// trailing whitespace, the client MUST Fail the WebSocket
// Connection
.
const secWSAccept = response.headersList.get('Sec-WebSocket-Accept')

  •  const digest = crypto.hash('sha1', keyValue + uid, 'base64')
    
  •  vardigest
    
  •  const nodeVersion = process.versions.node;
    
  •  const major = parseInt(nodeVersion.split('.')[0], 10);
    
  •  if (major < 26) {
    
  •     digest = crypto.createHash('sha1').update(keyValue + uid).digest('base64')
    
  •  } else {
    
  •     digest = crypto.hash('sha1', keyValue + uid, 'base64')
    
  •  }
     if (secWSAccept !== digest) {
       failWebsocketConnection(handler, 1002, 'Incorrect hash received in Sec-WebSocket-Accept header.')
       return
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions