New setting to listen C2S connection on non-localhost interfaces (#377).

This commit is contained in:
John Livingston
2024-05-27 16:32:40 +02:00
parent 345ec0ba56
commit 5a14e3f755
7 changed files with 50 additions and 2 deletions

View File

@ -161,6 +161,7 @@ async function getProsodyConfig (options: RegisterServerOptionsV5): Promise<Pros
'prosody-muc-expiration',
'prosody-c2s',
'prosody-c2s-port',
'prosody-c2s-interfaces',
'prosody-room-allow-s2s',
'prosody-s2s-port',
'prosody-s2s-interfaces',
@ -278,7 +279,18 @@ async function getProsodyConfig (options: RegisterServerOptionsV5): Promise<Pros
if (!/^\d+$/.test(c2sPort)) {
throw new Error('Invalid c2s port')
}
config.useC2S(c2sPort)
const c2sInterfaces = ((settings['prosody-c2s-interfaces'] as string) || '127.0.0.1, ::1')
.split(',')
.map(s => s.trim())
// Check that there is no invalid values (to avoid injections):
c2sInterfaces.forEach(networkInterface => {
if (networkInterface === '*') return
if (networkInterface === '::') return
if (networkInterface.match(/^\d+\.\d+\.\d+\.\d+$/)) return
if (networkInterface.match(/^[a-f0-9:]+$/)) return
throw new Error('Invalid c2s interfaces')
})
config.useC2S(c2sPort, c2sInterfaces)
}
if (enableComponents) {

View File

@ -337,8 +337,9 @@ class ProsodyConfigContent {
}
}
useC2S (c2sPort: string): void {
useC2S (c2sPort: string, c2sInterfaces: string[]): void {
this.global.set('c2s_ports', [c2sPort])
this.global.set('c2s_interfaces', c2sInterfaces)
}
useS2S (