Address issues with IPv6 binding

dd55b2770a8203ebfa52f76cb5a963e69be37127

Kristan Schlikow <kristian@schlikow.de>

Signed
1 files changed, +12 -4Ignore whitespace
server.js+12 -4
@@ -716,7 +716,7 @@ app.use('/api/azure', azureRouter);
716716const ipv6_regex = /^(?:(?:[a-fA-F\d]{1,4}:){7}(?:[a-fA-F\d]{1,4}|:)|(?:[a-fA-F\d]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|:[a-fA-F\d]{1,4}|:)|(?:[a-fA-F\d]{1,4}:){5}(?::(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,2}|:)|(?:[a-fA-F\d]{1,4}:){4}(?:(?::[a-fA-F\d]{1,4}){0,1}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,3}|:)|(?:[a-fA-F\d]{1,4}:){3}(?:(?::[a-fA-F\d]{1,4}){0,2}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,4}|:)|(?:[a-fA-F\d]{1,4}:){2}(?:(?::[a-fA-F\d]{1,4}){0,3}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,5}|:)|(?:[a-fA-F\d]{1,4}:){1}(?:(?::[a-fA-F\d]{1,4}){0,4}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,6}|:)|(?::(?:(?::[a-fA-F\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,7}|:)))(?:%[0-9a-zA-Z]{1,})?$/m;
717717const tavernUrlV6 = new URL(
718718 (cliArguments.ssl ? 'https://' : 'http://') +
719719 (listen ? (ipv6_regex.test(listenAddress) ? `[${listenAddress}]` : '[::]') : '[::1]') +
720720 (':' + server_port),
721721);
722722
@@ -789,8 +789,12 @@ const preSetupTasks = async function () {
789789 */
790790async function getAutorunHostname(useIPv6, useIPv4) {
791791 if (autorunHostname === 'auto') {
792- if (listen && (ipv4_regex.test(listenAddress) || ipv6_regex.test(listenAddress))) {
792+ if (listen) {
793- return listenAddress;
793+ if (ipv4_regex.test(listenAddress)) {
794+ return listenAddress;
795+ } else if (ipv6_regex.test(listenAddress)) {
796+ return `[${listenAddress}]`;
797+ }
794798 }
795799
796800 let localhostResolve = await canResolve('localhost', useIPv6, useIPv4);
@@ -855,10 +859,14 @@ const postSetupTasks = async function (v6Failed, v4Failed, useIPv6, useIPv4) {
855859 console.log('\n' + getSeparator(plainGoToLog.length) + '\n');
856860
857861 if (listen) {
858862 if (ipv4_regex.test(listenAddress) || ipv6_regex.test(listenAddress)) {
859863 console.log(
860864 `SillyTavern is listening on the address ${listenAddress}. If you want to limit it only to internal localhost ([::1] or 127.0.0.1), change the setting in config.yaml to "listen: false". Check "access.log" file in the SillyTavern directory if you want to inspect incoming connections.\n`,
861865 );
866+ } else if (ipv6_regex.test(listenAddress)) {
867+ console.log(
868+ `SillyTavern is listening on the address [${listenAddress}]. If you want to limit it only to internal localhost ([::1] or 127.0.0.1), change the setting in config.yaml to "listen: false". Check "access.log" file in the SillyTavern directory if you want to inspect incoming connections.\n`,
869+ );
862870 } else {
863871 console.log(
864872 '[::] or 0.0.0.0 means SillyTavern is listening on all network interfaces (Wi-Fi, LAN, localhost). If you want to limit it only to internal localhost ([::1] or 127.0.0.1), change the setting in config.yaml to "listen: false". Check "access.log" file in the SillyTavern directory if you want to inspect incoming connections.\n',