From e09f072f55a011dfd351ea11fbd1a83fb0d00850 Mon Sep 17 00:00:00 2001 From: xcbyy <2578898740@qq.com> Date: Tue, 20 Oct 2026 16:04:09 +0800 Subject: [PATCH] =?UTF-8?q?security:=20/api/health=20=E6=9A=B4=E9=9C=B2?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E6=A8=A1=E5=BC=8F=E4=B8=8E=E6=B2=99=E7=AE=B1?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=BC=80=E5=85=B3=EF=BC=88=E4=BE=BF=E4=BA=8E?= =?UTF-8?q?=E5=8F=91=E7=8E=B0=E7=94=9F=E4=BA=A7=E8=B7=91=E6=88=90=20develo?= =?UTF-8?q?pment=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - health 新增 mode(production/development) 与 sandboxPayAllowed - 便于部署自检:非 production 时身份校验放宽且允许沙箱支付,属资损级配置风险 - 新增 runtime-mode-selfcheck.spec.ts(102 套件/691 用例全绿) --- server/src/index.ts | 3 +++ server/tests/runtime-mode-selfcheck.spec.ts | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 server/tests/runtime-mode-selfcheck.spec.ts diff --git a/server/src/index.ts b/server/src/index.ts index 361b67f..888c110 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -202,6 +202,9 @@ app.get('/api/health', (_req: Request, res: Response) => { database: 'connected', uptime: process.uptime(), build: '2026-10-19', + // 运行模式自检:非 production 时用户身份校验会放宽、且允许沙箱支付(严禁用于公网) + mode: IS_PRODUCTION ? 'production' : 'development', + sandboxPayAllowed: ALLOW_SANDBOX_PAY, features: { userToken: true, adminPasswordGate: true, diff --git a/server/tests/runtime-mode-selfcheck.spec.ts b/server/tests/runtime-mode-selfcheck.spec.ts new file mode 100644 index 0000000..c13b368 --- /dev/null +++ b/server/tests/runtime-mode-selfcheck.spec.ts @@ -0,0 +1,18 @@ +// 已读取AGENTS.md +import * as fs from 'fs'; +import * as path from 'path'; + +/** + * 第八十六批:/api/health 暴露运行模式,避免"生产跑成 development"却无人察觉。 + * 背景:线上 NODE_ENV 未设为 production 时,resolveSecureUserId 会退回客户端声明身份, + * 且 ALLOW_SANDBOX_PAY 为 true(可无支付推进订单),属资损级配置风险。 + */ +describe('第八十六批运行模式自检闸门', () => { + const root = path.resolve(__dirname, '../../'); + const indexCode = fs.readFileSync(path.join(root, 'server/src/index.ts'), 'utf-8'); + + it('/api/health 返回 mode 与 sandboxPayAllowed', () => { + expect(indexCode).toContain("mode: IS_PRODUCTION ? 'production' : 'development'"); + expect(indexCode).toContain('sandboxPayAllowed: ALLOW_SANDBOX_PAY'); + }); +});