ipc: fix --authentication on iOS clients (don't rely on headers to pass credentials)

misc: remove "new Buffer()" deprecation warning
This commit is contained in:
jean-emmanuel 2023-09-06 23:44:21 +02:00
parent 6b96d208c9
commit 04e4e95c04
4 changed files with 8 additions and 6 deletions

View file

@ -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

View file

@ -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('/', '_')}\`
</script></body>`))
.pipe(res)