Files
wekan/server/lib/nextcloudTransport.js
T
Lauri Ojansivu 91bfd08097 Test real Nextcloud deployments and preserve signed SockJS identities
Keep verified gateway identities bound to their actual upgrade sockets before SockJS filters custom headers. Add repository-local Nextcloud 32-35 acceptance runs for authentication, isolation, uploads, lifecycle, source-built upgrades, restored volumes and mutual-TLS FRP. Harden release archive checks and exercise signing and workflow failures.

Thanks to xet7.
2026-10-11 22:46:45 +03:00

27 lines
1.2 KiB
JavaScript

'use strict';
const { nextcloudIdentity } = require('./nextcloudIdentity');
// SockJS deliberately exposes only a small header allowlist on DDP connections.
// Preserve verified identity from the actual upgrade socket before that filtering.
// Never accept identity from a DDP message or a browser-visible token.
function installNextcloudTransport(httpServer, streamServer, env = process.env) {
if (env.NEXTCLOUD_EXAPP !== 'true') return;
const handshakes = new WeakMap();
httpServer.prependListener('upgrade', (request, socket) => {
handshakes.delete(socket);
if (!nextcloudIdentity(request.headers, env)) return;
handshakes.set(socket, {
'x-wekan-nextcloud-user': request.headers['x-wekan-nextcloud-user'],
'x-wekan-nextcloud-signature': request.headers['x-wekan-nextcloud-signature'],
});
});
// The callback runs when SockJS creates its stream, before any DDP connect/login
// messages. Meteor's session then uses this same socket.headers object.
streamServer.register(socket => {
const rawSocket = socket._session?.recv?.connection;
const identity = rawSocket && handshakes.get(rawSocket);
if (identity) Object.assign(socket.headers, identity);
});
}
module.exports = { installNextcloudTransport };