mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-12-01 03:21:51 +08:00
security: harden egress probe from PR56
This commit is contained in:
1 parent
ff7839928a
commit
2d5f41d5b8
4 files changed
+312
-25
No files matched your search
@@ -45,6 +45,14 @@ export default function SystemSettingsPage() {
|
||||
// 出口探测:测一次真实请求,拿到"直连 / 经全局代理"两条出口 IP。
|
||||
const [egressTesting, setEgressTesting] = React.useState(false);
|
||||
const [egressReport, setEgressReport] = React.useState<EgressReport | null>(null);
|
||||
// 请求序号:改了输入/保存/切捕获之后,在途请求回来时序号已经变了,直接丢弃。
|
||||
// 不这么做会出现"结果刚被清空,又被上一次的响应填回来"。
|
||||
const egressSeq = React.useRef(0);
|
||||
// 清空结果并作废在途请求。
|
||||
const clearEgressReport = () => {
|
||||
egressSeq.current += 1;
|
||||
setEgressReport(null);
|
||||
};
|
||||
// 探测地址:留空用公网回显;隔离网填内网回显服务。
|
||||
const [egressProbeUrl, setEgressProbeUrl] = React.useState("");
|
||||
const [testing, setTesting] = React.useState(false);
|
||||
@@ -199,7 +207,7 @@ export default function SystemSettingsPage() {
|
||||
.then((s) => {
|
||||
apply(s);
|
||||
// 捕获开关一变,② 的链路就变了,旧结果不能留。
|
||||
setEgressReport(null);
|
||||
clearEgressReport();
|
||||
})
|
||||
.catch(() => setTrafficCapture(!v)) // revert on failure
|
||||
.finally(() => setSaving(false));
|
||||
@@ -331,7 +339,7 @@ export default function SystemSettingsPage() {
|
||||
.then((s) => {
|
||||
apply(s);
|
||||
// 保存后链路变了,旧结果(尤其"尚未保存")立刻失效。
|
||||
setEgressReport(null);
|
||||
clearEgressReport();
|
||||
if (showEgressIp) void probeEgress().catch(() => undefined);
|
||||
toast.success(globalProxyInput.trim() ? "已保存全局代理" : "已清除全局代理(改为直连)");
|
||||
})
|
||||
@@ -341,6 +349,7 @@ export default function SystemSettingsPage() {
|
||||
|
||||
// 测表单里当前的值,不要求先保存;后端返回直连 / 经代理两条。
|
||||
const testEgress = () => {
|
||||
const seq = ++egressSeq.current;
|
||||
setEgressTesting(true);
|
||||
setEgressReport(null);
|
||||
api
|
||||
@@ -350,6 +359,7 @@ export default function SystemSettingsPage() {
|
||||
...(egressProbeUrl.trim() ? { probe_url: egressProbeUrl.trim() } : {}),
|
||||
})
|
||||
.then((rep) => {
|
||||
if (seq !== egressSeq.current) return; // 期间改过配置,这份结果已经过期
|
||||
setEgressReport(rep);
|
||||
if (rep.ok) {
|
||||
// 先取 ②:直连那行永远成功,先命中它会把直连 IP 当成出口报出去。
|
||||
@@ -361,8 +371,12 @@ export default function SystemSettingsPage() {
|
||||
toast.error("出口探测失败");
|
||||
}
|
||||
})
|
||||
.catch((e) => toast.error("探测失败:" + (e as Error).message))
|
||||
.finally(() => setEgressTesting(false));
|
||||
.catch((e) => {
|
||||
if (seq === egressSeq.current) toast.error("探测失败:" + (e as Error).message);
|
||||
})
|
||||
.finally(() => {
|
||||
if (seq === egressSeq.current) setEgressTesting(false);
|
||||
});
|
||||
};
|
||||
|
||||
const toggleEgressVisibility = async (nextEnabled: boolean) => {
|
||||
@@ -515,8 +529,8 @@ export default function SystemSettingsPage() {
|
||||
disabled={!loaded || savingGlobalProxy}
|
||||
onChange={(e) => {
|
||||
setGlobalProxyInput(e.target.value);
|
||||
|
||||
setEgressReport(null);
|
||||
// 旧结果对应的是上一次的地址,留着会让人以为新值已经测过。
|
||||
clearEgressReport();
|
||||
}}
|
||||
/>
|
||||
<Button type="button" onClick={saveGlobalProxy} disabled={!loaded || savingGlobalProxy}>
|
||||
@@ -569,7 +583,7 @@ export default function SystemSettingsPage() {
|
||||
value={egressProbeUrl}
|
||||
onChange={(e) => {
|
||||
setEgressProbeUrl(e.target.value);
|
||||
setEgressReport(null);
|
||||
clearEgressReport();
|
||||
}}
|
||||
/>
|
||||
<span className="text-muted-foreground leading-relaxed">
|
||||
|
||||
@@ -2384,6 +2384,28 @@ function route(m: string, path: string, seg: string[], q: URLSearchParams, b: Re
|
||||
if (path === "/settings/basic-auth" && m === "PUT")
|
||||
throw new Error("演示模式不支持修改 HTTP Basic Auth,请在实际部署中配置");
|
||||
if (path === "/settings/web-search/test") return { ok: true, count: 5, backend: D.settings.web_search_backend };
|
||||
if (path === "/settings/proxy/test")
|
||||
return {
|
||||
ok: true,
|
||||
capture: false,
|
||||
configured: "",
|
||||
agent_proxy: "",
|
||||
checks: [
|
||||
{
|
||||
key: "direct",
|
||||
label: "① 直连 IP(不经过代理)",
|
||||
result: { ok: true, exit_ip: "203.0.113.7", via: "direct", via_label: "直连", latency_ms: 12, probes: [] },
|
||||
},
|
||||
{
|
||||
key: "global",
|
||||
label: "② 经全局代理的出口 IP",
|
||||
skipped: true,
|
||||
skip_reason: "输入框为空,未配置代理",
|
||||
result: { ok: false, latency_ms: 0, probes: [] },
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
if (path === "/settings/python/detect") return { python_interpreter: "/usr/bin/python3" };
|
||||
if (path === "/chat")
|
||||
return { reply: "(demo)我已把该建议注入为一条高优意图,work agent 会尽快执行。", mode: "hint" };
|
||||
|
||||
Reference in new issue
Block a user