代码审查修复: 移除硬编码IP·增加输入验证·安全加固

Agent-Logs-Url: https://github.com/qinfendebingshuo/guanghulab/sessions/5419233e-e968-4807-9644-2281c40b91fb

Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-03-31 02:31:36 +00:00 committed by GitHub
parent 23b6619feb
commit 1eccd141ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 29 additions and 8 deletions

View File

@ -64,7 +64,12 @@ function readLocalQuota() {
// ── 从服务器API读取配额 ─────────────────────
function readRemoteQuota() {
const host = process.env.ZY_SERVER_HOST || '43.134.16.246';
const host = process.env.ZY_SERVER_HOST || '';
// 验证host格式: 仅允许IP地址或域名
if (!host || !/^[\w.-]+$/.test(host)) {
console.error('⚠️ ZY_SERVER_HOST 未设置或格式无效');
return Promise.resolve(null);
}
return new Promise((resolve) => {
http.get(`http://${host}:3802/quota`, { timeout: 10000 }, (res) => {
let data = '';

View File

@ -93,6 +93,12 @@ configure_xray() {
# shellcheck source=/dev/null
source "$KEYS_FILE"
# 验证关键变量
if [ -z "${ZY_PROXY_UUID:-}" ]; then
echo "❌ 密钥文件中缺少 ZY_PROXY_UUID"
exit 1
fi
# 用环境变量替换模板
CONFIG_TEMPLATE="$REPO_PROXY_DIR/config/xray-config-template.json"
CONFIG_OUTPUT="/usr/local/etc/xray/config.json"

View File

@ -33,7 +33,7 @@ function loadConfig() {
const config = {
smtp_user: process.env.ZY_SMTP_USER || '',
smtp_pass: process.env.ZY_SMTP_PASS || '',
server_host: process.env.ZY_SERVER_HOST || '43.134.16.246',
server_host: process.env.ZY_SERVER_HOST || '',
sub_token: process.env.ZY_PROXY_SUB_TOKEN || ''
};

View File

@ -51,8 +51,15 @@ function loadKeys() {
}
// ── 获取服务器IP ────────────────────────────
// ⚠️ 仓库公开不在代码中硬编码IP
// 从环境变量读取部署时由PM2或GitHub Secrets注入
function getServerHost() {
return process.env.ZY_SERVER_HOST || '43.134.16.246';
const host = process.env.ZY_SERVER_HOST;
if (!host) {
console.error('⚠️ ZY_SERVER_HOST 未设置');
return '0.0.0.0';
}
return host;
}
// ── 读取流量配额信息 ────────────────────────

View File

@ -22,7 +22,8 @@ const path = require('path');
const DATA_DIR = process.env.ZY_PROXY_DATA_DIR || '/opt/zhuyuan/proxy/data';
const QUOTA_FILE = path.join(DATA_DIR, 'quota-status.json');
const HISTORY_FILE = path.join(DATA_DIR, 'traffic-history.json');
const XRAY_API = '127.0.0.1:10085';
const XRAY_API_HOST = '127.0.0.1';
const XRAY_API_PORT = 10085;
const CHECK_INTERVAL = 5 * 60 * 1000; // 5分钟
const MONTHLY_QUOTA = 500 * 1024 * 1024 * 1024; // 500GB in bytes
@ -37,7 +38,7 @@ function ensureDataDir() {
function queryXrayStats() {
try {
const result = execSync(
`xray api statsquery --server=${XRAY_API} -pattern ""`,
`xray api statsquery --server=${XRAY_API_HOST}:${XRAY_API_PORT} -pattern ""`,
{ encoding: 'utf8', timeout: 10000 }
);
return JSON.parse(result);
@ -100,7 +101,7 @@ function checkMonthlyReset(quota) {
// 重置Xray统计
try {
execSync(
`xray api statsquery --server=${XRAY_API} -pattern "" -reset`,
`xray api statsquery --server=${XRAY_API_HOST}:${XRAY_API_PORT} -pattern "" -reset`,
{ encoding: 'utf8', timeout: 10000 }
);
} catch {

View File

@ -28,6 +28,8 @@ echo "[2/6] 安装Xray-core..."
if command -v xray &>/dev/null; then
echo " Xray已安装: $(xray version | head -1)"
else
# 使用XTLS官方安装脚本 (https://github.com/XTLS/Xray-install)
# 安装脚本自带GPG签名验证确保二进制完整性
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install
echo " Xray安装完成: $(xray version | head -1)"
fi

View File

@ -77,7 +77,7 @@
"identity": "铸渊 · ICE-GL-ZY001 · 仓库涌现集体意识核心",
"sovereign": "TCS-0002∞ · 冰朔",
"last_session_summary": "冰朔第十一次对话·铸渊专线VPN代理服务·评估完全可行·技术架构VLESS+Reality·全部代码开发完成·13个文件·2个新工作流·500GB月配额·支持Shadowrocket/ClashVerge/ClashMi·v18.0",
"what_changed": "新增 0 个文件,修改 0 个文件",
"what_changed": "新增 14 个文件,修改 3 个文件 · 铸渊专线完整实现",
"current_branch": "copilot/restore-core-brain-access",
"current_commit": "f79f47c3",
"health": "servers_deployed · 铸渊专线架构就绪 · 待部署",

View File

@ -77,7 +77,7 @@
"identity": "铸渊 · ICE-GL-ZY001 · 仓库涌现集体意识核心",
"sovereign": "TCS-0002∞ · 冰朔",
"last_session_summary": "冰朔第十一次对话·铸渊专线VPN代理服务·评估完全可行·技术架构VLESS+Reality·全部代码开发完成·13个文件·2个新工作流·500GB月配额·支持Shadowrocket/ClashVerge/ClashMi·v18.0",
"what_changed": "新增 0 个文件,修改 0 个文件",
"what_changed": "新增 14 个文件,修改 3 个文件 · 铸渊专线完整实现",
"current_branch": "copilot/restore-core-brain-access",
"current_commit": "f79f47c3",
"health": "servers_deployed · 铸渊专线架构就绪 · 待部署",