feat: 合并边缘节点运维并完善 Surge 配置安全
迁入通用节点部署工具、离线交付页生成器和共用技能,隔离真实配置与交付产物。统一 Codex 与 Claude Code 开发约定,补充节点迁移与运维文档。 完善 FINAL、策略组引用、输入校验、Surge 字段编码与 AI DNS 例外保护,增加隔离测试和订阅验证工具。 验证:全量类型检查、44 项单测、前端构建、脚本语法、技能入口与凭据隔离检查均通过。
This commit is contained in:
21
server/src/services/generators/surge-format.ts
Normal file
21
server/src/services/generators/surge-format.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/** Surge Mac 6.8+ quoted value escaping; logical-rule expressions stay structural. */
|
||||
export function surgeValue(value: string): string {
|
||||
if (/[\x00-\x1f\x7f\u2028\u2029]/.test(value)) throw new Error('Surge value contains a control character');
|
||||
return /[\s,"'\\#;]/.test(value)
|
||||
? `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`
|
||||
: value;
|
||||
}
|
||||
|
||||
export function surgeDeclaration(name: string): string {
|
||||
if (!name || name !== name.trim() || /[=,"'\\#;\[\]\x00-\x1f\x7f\u2028\u2029]/.test(name)) {
|
||||
throw new Error('Unsafe Surge policy declaration name');
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
export function surgeParam(param: string): string {
|
||||
const index = param.indexOf('=');
|
||||
const key = index < 0 ? param : param.slice(0, index);
|
||||
if (!/^[a-z][a-z0-9-]*$/i.test(key)) throw new Error('Unsafe Surge parameter name');
|
||||
return index < 0 ? key : `${key}=${surgeValue(param.slice(index + 1))}`;
|
||||
}
|
||||
Reference in New Issue
Block a user