安全审计:登记登录、登出、登录失败、修改本人密码、初始化、导出与备份下载

- 新增 server/security-audit.js:统一写入 {ip, userAgent(≤200字)} 及少量说明,写入失败只打印错误、不改变响应
- 登录失败用合成身份“未登录”(role=system),记录登录名(≤50字)与原因 unknown_user / password_not_set / wrong_password;判断顺序与原条件一致,未知账号照常计算哈希
- 修改本人密码失败会整体回滚:分发器新增 ctx.afterRollback,回滚后另行写入失败记录
- 导出库存流水Excel记录实际使用的筛选条件;下载备份记录文件名
- 员工业务数据判定忽略 auth:*、export、backup 审计,登录不影响员工删除资格
- 两处“只读不改库”测试改为忽略安全审计行

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
黄健铭andClaude Opus 5.5 committed 2026-12-04 12:44:30 -08:00
1 parent 2305900178
commit a965becde3
9 files changed
+360 -39

No files matched your search

+5 -3
View File
@@ -966,7 +966,6 @@ test('员工旧人数幂等回执也拒绝读取,缓存与原写入不改', as
const tables = [
'daily_people_counts',
'operations',
'audit',
'orders',
'payments',
'expenses',
@@ -974,7 +973,10 @@ test('员工旧人数幂等回执也拒绝读取,缓存与原写入不改', as
'movements',
'team_fund_cash',
],
before = contents(l, tables);
// 登录的安全审计不属于业务数据。
snapshot = () =>
contents(l, tables) + JSON.stringify(l.rows("SELECT * FROM audit WHERE entity NOT LIKE 'auth:%' ORDER BY id")),
before = snapshot();
for (const sample of samples) {
const cookie = await login(sample.member);
assert.equal((await call('/api/people-count', cookie, sample.body, sample.key)).status, 403);
@@ -982,7 +984,7 @@ test('员工旧人数幂等回执也拒绝读取,缓存与原写入不改', as
}
const cookie = await login('assistant');
assert.equal((await call('/api/people-count', cookie, errorBody, errorKey)).status, 403);
assert.equal(contents(l, tables), before, '拒绝访问不改原operations、人数或账务');
assert.equal(snapshot(), before, '拒绝访问不改原operations、人数或账务');
});
test('员工不能通过旧人数、订单簿或日报取得总数和基准日期', async t => {