Skip to content

feat: add listen address configuration option#94

Closed
yingzeliangzi wants to merge 1 commit intolich0821:masterfrom
yingzeliangzi:master
Closed

feat: add listen address configuration option#94
yingzeliangzi wants to merge 1 commit intolich0821:masterfrom
yingzeliangzi:master

Conversation

@yingzeliangzi
Copy link

目前项目默认监听0.0.0.0公网ip且未定义auth_token 新增自定义监听地址并设置默认监听127.0.0.1 防止未经授权的公网访问
Screenshot_2026-01-15_13-40-02
Screenshot_2026-01-15_13-40-33

Copilot AI review requested due to automatic review settings January 15, 2026 05:41
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds configurable listen address support to improve security by defaulting to localhost (127.0.0.1) instead of binding to all interfaces (0.0.0.0). This prevents unauthorized public network access when no auth_token is configured.

Changes:

  • Added ListenAddr field to configuration with 127.0.0.1 as the default
  • Created UpdateNetwork method to update both port and listen address atomically
  • Updated UI to display and configure listen address with preset buttons for common values

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
internal/config/config.go Added ListenAddr field, getter/setter methods, validation, and storage persistence
internal/service/settings.go Added UpdateNetwork method and listen address validation in UpdateConfig
internal/proxy/proxy.go Modified server startup to bind to configured listen address instead of all interfaces
cmd/server/main.go Added environment variable support for CCNEXUS_LISTEN_ADDR and updated logging
cmd/server/webui/api/config.go Updated API endpoints to handle listen address in requests/responses
cmd/server/webui/ui/js/api.js Modified updatePort to accept optional listenAddr parameter
cmd/desktop/app.go Added UpdateNetwork method wrapper
cmd/desktop/frontend/wailsjs/* Generated Wails bindings for UpdateNetwork method
cmd/desktop/frontend/src/*.js Updated UI to support listen address configuration with presets
cmd/desktop/frontend/src/i18n/*.js Added translations for listen address UI elements
cmd/desktop/frontend/src/style.css Added CSS styles for listen address preset buttons

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return;
}

if (!listenAddr || /\s/.test(listenAddr)) {
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation only checks for empty values and whitespace. Consider validating that the listen address is a valid IP address or hostname. Invalid addresses like "999.999.999.999" or malformed hostnames will pass this check and only fail at runtime when the server attempts to bind.

Copilot uses AI. Check for mistakes.
Comment on lines +129 to +131
if strings.TrimSpace(c.ListenAddr) == "" {
return fmt.Errorf("invalid listen address")
}
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation only checks for empty/whitespace values but does not verify that the address is a valid IP address or hostname. Consider using net.ParseIP or similar validation to ensure the listen address is valid before attempting to bind to it. This would provide better error messages at configuration time rather than runtime.

Copilot uses AI. Check for mistakes.
Comment on lines +97 to +100
if strings.TrimSpace(req.ListenAddr) == "" {
WriteError(w, http.StatusBadRequest, "Invalid listen address")
return
}
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation only checks for empty/whitespace values but does not verify that the address is a valid IP address or hostname. Consider adding proper validation to ensure the listen address format is valid before saving it to configuration.

Copilot uses AI. Check for mistakes.
Comment on lines +86 to +88
if strings.TrimSpace(listenAddr) == "" {
return fmt.Errorf("invalid listen address")
}
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation only checks for empty/whitespace values. Consider adding validation to ensure the listen address is a valid IP address or hostname format using net.ParseIP or similar methods.

Copilot uses AI. Check for mistakes.
listenAddrLabel: '监听地址:',
listenAddrPlaceholder: '例如:127.0.0.1',
listenAddrPresetPublic: '公网 0.0.0.0',
listenAddrPresetLAN: '局域网 192.168.0.0',
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The preset value '192.168.0.0' is a network address, not a valid host IP to bind to. This should likely be '192.168.0.1' or another valid host address in the private range. Binding to .0.0 addresses (network addresses) may fail or produce unexpected behavior depending on the OS.

Suggested change
listenAddrPresetLAN: '局域网 192.168.0.0',
listenAddrPresetLAN: '局域网 192.168.0.1',

Copilot uses AI. Check for mistakes.
listenAddrLabel: 'Listen address:',
listenAddrPlaceholder: 'e.g., 127.0.0.1',
listenAddrPresetPublic: 'Public 0.0.0.0',
listenAddrPresetLAN: 'LAN 192.168.0.0',
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The preset value '192.168.0.0' is a network address, not a valid host IP to bind to. This should likely be '192.168.0.1' or another valid host address in the private range. Binding to .0.0 addresses (network addresses) may fail or produce unexpected behavior depending on the OS.

Suggested change
listenAddrPresetLAN: 'LAN 192.168.0.0',
listenAddrPresetLAN: 'LAN 192.168.0.1',

Copilot uses AI. Check for mistakes.
<input type="text" id="listenAddrInput" placeholder="${t('modal.listenAddrPlaceholder')}">
<div class="listen-addr-presets">
<button class="preset-chip" onclick="window.setListenAddrPreset('0.0.0.0')">${t('modal.listenAddrPresetPublic')}</button>
<button class="preset-chip" onclick="window.setListenAddrPreset('192.168.0.0')">${t('modal.listenAddrPresetLAN')}</button>
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The preset value '192.168.0.0' is a network address, not a valid host IP to bind to. This should likely be '192.168.0.1' or use '0.0.0.0' to bind to all interfaces on the local machine. Network addresses ending in .0.0 are typically reserved and may not bind correctly.

Suggested change
<button class="preset-chip" onclick="window.setListenAddrPreset('192.168.0.0')">${t('modal.listenAddrPresetLAN')}</button>
<button class="preset-chip" onclick="window.setListenAddrPreset('192.168.0.1')">${t('modal.listenAddrPresetLAN')}</button>

Copilot uses AI. Check for mistakes.
import { t } from '../i18n/index.js';
import { escapeHtml } from '../utils/format.js';
import { addEndpoint, updateEndpoint, removeEndpoint, testEndpoint, testEndpointLight, updatePort } from './config.js';
import { addEndpoint, updateEndpoint, removeEndpoint, testEndpoint, testEndpointLight, updateNetwork } from './config.js';
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import testEndpoint.

Suggested change
import { addEndpoint, updateEndpoint, removeEndpoint, testEndpoint, testEndpointLight, updateNetwork } from './config.js';
import { addEndpoint, updateEndpoint, removeEndpoint, testEndpointLight, updateNetwork } from './config.js';

Copilot uses AI. Check for mistakes.
@lich0821
Copy link
Owner

@hea7enn 佬怎么看?

@hea7enn
Copy link
Contributor

hea7enn commented Jan 17, 2026

本身就是本地代理服务,无需考虑公网问题,直接关闭吧

@yingzeliangzi
Copy link
Author

不过我这边测试如果有公网ip 确实可以无授权访问使用的
Screenshot_2026-01-17_11-09-00

@hea7enn
Copy link
Contributor

hea7enn commented Jan 17, 2026

但是个人电脑一般也不会专门去开个公网,还提供地址给别人,这种极小概率事件 没必要还单独做个功能 ,不太实用

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants