fix(security,config): enforce 0600 file permissions, dynamic account store path, and HTTP origin protection

This commit is contained in:
gitea committed 2026-09-29 23:34:06 +08:00
1 parent bd585db889
commit d0af46b445
5 files changed
+143 -19

No files matched your search

+30 -6
View File
@@ -16,10 +16,12 @@ describe("HTTP Server - 嵌入式服务与 REST 网关", () => {
await new Promise<void>((resolve) => server.close(() => resolve()));
});
test("GET / 返回服务概览与 CORS 标头", async () => {
const res = await fetch(`${baseUrl}/`);
test("GET / 返回服务概览与本地 CORS 标头", async () => {
const res = await fetch(`${baseUrl}/`, {
headers: { Origin: "http://localhost:3000" },
});
expect(res.status).toBe(200);
expect(res.headers.get("access-control-allow-origin")).toBe("*");
expect(res.headers.get("access-control-allow-origin")).toBe("http://localhost:3000");
const json = (await res.json()) as any;
expect(json.name).toBe("hose-use");
expect(json.version).toBe(VERSION);
@@ -78,6 +80,19 @@ describe("HTTP Server - 嵌入式服务与 REST 网关", () => {
expect(json.stdout).toContain(`hose-use v${VERSION}`);
});
test("POST /api/cli 拒绝来自非授信外部 Origin 的跨站命令执行请求 (防 CSRF RCE)", async () => {
const res = await fetch(`${baseUrl}/api/cli`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Origin: "https://evil.example.com",
},
body: JSON.stringify({ command: "version" }),
});
expect(res.status).toBe(403);
expect(res.headers.get("access-control-allow-origin")).toBeNull();
});
test("GET /v1/corps 返回企业列表与运行模式", async () => {
const res = await fetch(`${baseUrl}/v1/corps`);
expect(res.status).toBe(200);
@@ -87,10 +102,19 @@ describe("HTTP Server - 嵌入式服务与 REST 网关", () => {
expect(Array.isArray(json.corps)).toBe(true);
});
test("OPTIONS /v1/corps 处理 CORS 跨域预检", async () => {
const res = await fetch(`${baseUrl}/v1/corps`, { method: "OPTIONS" });
test("OPTIONS /v1/corps 允许本地 Origin 预检并拦截未知外部 Origin", async () => {
const res = await fetch(`${baseUrl}/v1/corps`, {
method: "OPTIONS",
headers: { Origin: "http://127.0.0.1:8888" },
});
expect(res.status).toBe(204);
expect(res.headers.get("access-control-allow-methods")).toContain("GET");
expect(res.headers.get("access-control-allow-origin")).toBe("*");
expect(res.headers.get("access-control-allow-origin")).toBe("http://127.0.0.1:8888");
const blocked = await fetch(`${baseUrl}/v1/corps`, {
method: "OPTIONS",
headers: { Origin: "https://attacker.example.com" },
});
expect(blocked.status).toBe(403);
});
});