From 04e4e95c04b367afdca4089aa699f943c3997838 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Wed, 6 Sep 2023 23:44:21 +0200 Subject: [PATCH] ipc: fix `--authentication` on iOS clients (don't rely on headers to pass credentials) misc: remove "new Buffer()" deprecation warning --- CHANGELOG.md | 1 + src/client/ipc/index.js | 2 +- src/server/ipc/server.js | 10 +++++----- src/server/server.js | 1 + 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7464cfb8..1676929b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - bug fixes - custom module: `receive()` not passing boolean arguments properly + - fix `--authentication` on iOS clients - editor - display current widget value in the `value` property's help modal diff --git a/src/client/ipc/index.js b/src/client/ipc/index.js index 2023622a..fe00f4bc 100644 --- a/src/client/ipc/index.js +++ b/src/client/ipc/index.js @@ -73,7 +73,7 @@ class Ipc extends EventEmitter { open() { - this.socket = new WebSocket(protocol + window.location.host + '/' + uuid) + this.socket = new WebSocket(protocol + window.location.host + '/' + uuid + '/' + window.AUTH) this.socket.onclose = this.socket.onerror = ()=>{ if (!this.connected()) this.close() diff --git a/src/server/ipc/server.js b/src/server/ipc/server.js index 28d827f7..61cabb4a 100644 --- a/src/server/ipc/server.js +++ b/src/server/ipc/server.js @@ -16,18 +16,18 @@ class Ipc extends EventEmitter { this.server.on('connection', (socket, req)=>{ + var url = req.url.split('/'), + auth = url.pop().replace('_', '/'), + id = url.pop() + if (settings.read('authentication')) { - if (!req.headers.authorization) return - if (req.headers.authorization.search('Basic ') !== 0) return - var auth = new Buffer(req.headers.authorization.split(' ')[1], 'base64').toString() - if (settings.read('authentication') !== auth) { + if (settings.read('authentication') !== Buffer.from(auth, 'base64').toString()) { console.log(`(WARNING) Client connexion refused for ${req.connection.remoteAddress} (authentication failed)`) socket.close() return } } - var id = req.url.split('/').pop() if (!id) return diff --git a/src/server/server.js b/src/server/server.js index 918845a6..3b19ef9f 100644 --- a/src/server/server.js +++ b/src/server/server.js @@ -105,6 +105,7 @@ function httpRoute(req, res) { window.IP=${JSON.stringify(ip)} window.ENV=${JSON.stringify(clientOptions)} window.READ_ONLY=${JSON.stringify(settings.read('read-only'))} + window.AUTH=\`${(req.headers.authorization || '').replace('Basic ', '').replace('/', '_')}\` `)) .pipe(res)