feat(webui): source trustProxy from runtime config (env still overrides)
Move the trust-proxy/client-ip resolver from a module-level direct read of SNOWLUMA_WEBUI_TRUST_PROXY into initWebUI, fed by runtime.json's trustProxy (loadRuntimeConfig already merges the env override on top). Default '' parses identically to the old undefined (trust socket peer only), so behavior is unchanged when unset.
This commit is contained in:
2 files changed
+9
-9
No files matched your search
@@ -51,6 +51,7 @@ async function main() {
|
||||
await initWebUI(runtimeConfig.webuiPort || 5099, oneBotManager, hookManager, notificationManager, {
|
||||
host: runtimeConfig.webuiHost,
|
||||
tlsEnabled: runtimeConfig.webuiTls?.enabled,
|
||||
trustProxy: runtimeConfig.trustProxy,
|
||||
});
|
||||
} catch (err) {
|
||||
log.error('Failed to start WebUI: ', err);
|
||||
|
||||
@@ -80,14 +80,6 @@ function purgeExpiredTokens() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the client IP for per-IP rate limiting. Default is the TCP
|
||||
* socket peer (cannot be spoofed by the client). Operators behind a
|
||||
* reverse proxy must opt in via the `SNOWLUMA_WEBUI_TRUST_PROXY` env
|
||||
* var; see `./client-ip.ts` for the accepted values.
|
||||
*/
|
||||
const trustProxyMode = parseTrustProxy(process.env.SNOWLUMA_WEBUI_TRUST_PROXY);
|
||||
const getClientIp = makeClientIpResolver(trustProxyMode);
|
||||
|
||||
async function fetchQqAvatar(uin: string): Promise<{ body: Uint8Array; contentType: string }> {
|
||||
const response = await fetch(`https://q1.qlogo.cn/g?b=qq&nk=${encodeURIComponent(uin)}&s=100`, {
|
||||
@@ -107,8 +99,15 @@ export async function initWebUI(
|
||||
oneBotManager: OneBotManager,
|
||||
hookManager?: HookManager,
|
||||
notificationManager?: NotificationManager,
|
||||
listener: { host?: string; tlsEnabled?: boolean } = {},
|
||||
listener: { host?: string; tlsEnabled?: boolean; trustProxy?: string } = {},
|
||||
): Promise<{ port: number }> {
|
||||
// Resolve the client IP for per-IP rate limiting from the configured
|
||||
// trust-proxy directive (runtime.json `trustProxy`, env-overridable via
|
||||
// SNOWLUMA_WEBUI_TRUST_PROXY which loadRuntimeConfig already merged in).
|
||||
// Default ('') = trust the TCP socket peer only (cannot be spoofed).
|
||||
const trustProxyMode = parseTrustProxy(listener.trustProxy);
|
||||
const getClientIp = makeClientIpResolver(trustProxyMode);
|
||||
|
||||
const auth = WebuiAuth.load();
|
||||
const initialPassword = auth.takeInitialPassword();
|
||||
if (auth.isDevMode()) {
|
||||
|
||||
Reference in new issue
Block a user