From 40032ec09185b8218af66f50ba67fec5965e0cf6 Mon Sep 17 00:00:00 2001 From: nocode Date: Wed, 23 Sep 2026 22:00:55 +0200 Subject: [PATCH] fix(config): warn when a public address is announced but only loopback is bound MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `WEB_HOST=127.0.0.1` is the right default behind a reverse proxy on the same machine, and the wrong one inside a container or on a hosting panel, where the process has to bind the allocation. The guidance only mentioned the first case, so a `.env` written from the wizard could leave the dashboard listening where nothing could reach it — every request timing out with nothing saying why. The wizard now flags the contradiction between a loopback bind and a public URL, and both the help text and `.env.example` name the container case. Co-Authored-By: Claude Opus 5 (1M context) --- .env.example | 5 +++-- src/web/services/env-schema.js | 19 +++++++++++++++++-- tests/web-configuration.test.js | 24 ++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index fbc64ce..158f675 100644 --- a/.env.example +++ b/.env.example @@ -75,8 +75,9 @@ GITEA_WEBHOOK_SECRET= # Site d'administration servi par le bot : `npm run setup` pour l'assistant .env, # puis http://WEB_HOST:WEB_PORT une fois le bot démarré. WEB_ENABLED=false -# 127.0.0.1 par défaut : n'expose rien hors de la machine. Mettre 0.0.0.0 seulement -# derrière un reverse proxy HTTPS. +# 127.0.0.1 derrière un reverse proxy installé sur la même machine. +# 0.0.0.0 dans un conteneur ou sur un panel d'hébergement (Pterodactyl, Docker) : +# sinon le site n'écoute que sur la boucle locale et reste injoignable. WEB_HOST=127.0.0.1 WEB_PORT=3080 # URL publique du tableau de bord, utilisée pour la redirection OAuth2 Discord. diff --git a/src/web/services/env-schema.js b/src/web/services/env-schema.js index 81a78bb..8fab04b 100644 --- a/src/web/services/env-schema.js +++ b/src/web/services/env-schema.js @@ -101,7 +101,7 @@ export const SECTIONS = Object.freeze([ 'Toujours dans **OAuth2 → Redirects**, ajoute exactement l’URL affichée dans **Paramètres → Tableau de bord** : c’est l’adresse par laquelle tu ouvres le site, suivie de `/auth/callback`.', 'Si le site répond sur un port différent de celui annoncé par ton hébergeur, c’est bien le port que tu utilises dans le navigateur qu’il faut déclarer.', 'Génère `WEB_SESSION_SECRET` avec le bouton ci-dessous.', - 'Laisse `WEB_HOST` sur `127.0.0.1` et place un reverse proxy HTTPS devant, sauf en développement local.', + 'Choisis `WEB_HOST` : `127.0.0.1` derrière un reverse proxy local, `0.0.0.0` dans un conteneur ou sur un panel d’hébergement.', ], links: [{ label: 'OAuth2 du Developer Portal', url: 'https://discord.com/developers/applications' }], }, @@ -438,7 +438,7 @@ export const VARIABLES = Object.freeze([ key: 'WEB_HOST', section: 'web', label: 'Interface d’écoute', - help: 'Garde `127.0.0.1` et place un reverse proxy HTTPS devant. `0.0.0.0` expose le site sur le réseau.', + help: 'Derrière un reverse proxy installé sur la même machine, garde `127.0.0.1`. Dans un conteneur ou sur un panel d’hébergement (Pterodactyl, Docker…), il faut `0.0.0.0` : sinon le site n’écoute que sur la boucle locale et reste injoignable de l’extérieur.', type: 'text', default: '127.0.0.1', restartRequired: true, @@ -711,6 +711,21 @@ export function crossCheck(values) { if (!read('WEB_SESSION_SECRET')) { warnings.push('Sans `WEB_SESSION_SECRET`, toutes les sessions sont perdues à chaque redémarrage.'); } + const publicHost = (() => { + try { + return new URL(read('WEB_PUBLIC_URL')).hostname; + } catch { + return ''; + } + })(); + const localOnly = ['127.0.0.1', 'localhost', '::1']; + + if (read('WEB_HOST') === '127.0.0.1' && publicHost && !localOnly.includes(publicHost)) { + warnings.push( + `\`WEB_HOST=127.0.0.1\` n'écoute que sur la boucle locale, alors que le site est annoncé sur « ${publicHost} » : il sera injoignable, sauf si un reverse proxy tourne sur la même machine. Dans un conteneur ou sur un panel d'hébergement, mets \`0.0.0.0\`.`, + ); + } + if (read('WEB_HOST') === '0.0.0.0' && !read('WEB_PUBLIC_URL').startsWith('https://')) { warnings.push('`WEB_HOST=0.0.0.0` sans HTTPS expose les cookies de session en clair sur le réseau.'); } diff --git a/tests/web-configuration.test.js b/tests/web-configuration.test.js index 38af388..a4953e2 100644 --- a/tests/web-configuration.test.js +++ b/tests/web-configuration.test.js @@ -88,6 +88,30 @@ describe('env schema', () => { assert.ok(warnings.some((warning) => warning.includes('rejetés'))); }); + it('warns when a public address is announced but only loopback is bound', () => { + // The failure it prevents: the site answers on the loopback while a domain + // points at it, so every request times out and nothing says why. + const warnings = crossCheck({ + WEB_ENABLED: 'true', + WEB_HOST: '127.0.0.1', + WEB_PUBLIC_URL: 'https://bot.example.org', + DISCORD_CLIENT_SECRET: 'x', + WEB_SESSION_SECRET: 'y', + }); + assert.ok(warnings.some((warning) => warning.includes('boucle locale'))); + }); + + it('stays quiet when the loopback matches the announced address', () => { + const warnings = crossCheck({ + WEB_ENABLED: 'true', + WEB_HOST: '127.0.0.1', + WEB_PUBLIC_URL: 'http://localhost:3080', + DISCORD_CLIENT_SECRET: 'x', + WEB_SESSION_SECRET: 'y', + }); + assert.ok(!warnings.some((warning) => warning.includes('boucle locale'))); + }); + it('warns when the dashboard is exposed without HTTPS', () => { const warnings = crossCheck({ WEB_ENABLED: 'true',