Commit Graph
36 Commits
Author SHA1 Message Date
qing b33c5e6d1d fix(gateway): 修复P0安全问题,错误消息脱敏
- 将4处暴露内部处理步骤的错误消息替换为用户友好文案
- 修正拼写错误 "Registe" -> "Registration"
- 修正注册失败HTTP状态码 400 -> 500
- 更新安全审计文档至2026-08-07版本
- P0严重问题全部修复,安全评级提升至A-

修复内容:
- "Login (Query Step) Failed" -> "Login failed, please try again later"
- "Login (Update Step) Failed" -> "Login failed, please try again later"
- "Registe Failed" -> "Registration failed, please try again later"
- "Reset Failed" -> "Password reset failed, please try again later"
2026-08-07 22:53:26 +08:00
qing edbb7ef1c6 fix(db2): 修复第六轮审计定位的 4 个问题并更新审计文档
- ND-1(P2): start() 引入 CleanupGuard RAII 守卫,rpc.start() 异常路径
  下清理线程被优雅回收,消除 std::terminate 硬崩溃
- ND-4(P3): where/limit/offset 类型不符立即抛错,不再静默忽略
- ND-5(P3): _bind_value 对超 INT64_MAX 的 uint64 抛错,防截断溢出
- ND-6(P3): in 运算符非数组值抛错,仅空数组保留恒假语义
- 记录 2 项已知限制 ND-2/ND-3(无结果集上限、无 WHERE 全表更新/删除)

审计文档更新至 26/26(100%) 修复、30 项安全机制;clang++/g++ 双编译验证通过
2026-08-07 21:42:06 +08:00
qing 3ace5931e6 fix(db2): security audit round 5 - fix all remaining P3 issues
- P3-7: replace gmtime() with thread-safe gmtime_r() in utc_now()
- P3-9: validate columns array elements are strings before as_string()
- P3-10: use sqlite3_close_v2() instead of sqlite3_close() in DbConn dtor
- P3-11: introduce safe_stoi() helper wrapping all 9 std::stoi call sites
  with field-name-aware error messages
- P3-12: log _log_internal exceptions to stderr instead of silent swallow
- P3-13: log _do_cleanup COUNT prepare failures to stderr; simplify
  finalize to single exit point
- P3-14: reject invalid order_by elements (non-object, missing column)
  instead of silently skipping
- P3-15: reject non-string action field instead of defaulting to "select"
- P3-16: validate order_by column is string and desc is boolean

All 22 audit issues now resolved (100%).
2026-08-07 21:33:13 +08:00
qing e2f05f9a43 fix(libmsg): security audit round 4 - eliminate residual race + atomic server_fd
- P1-3: introduce ConnectionLock (mutex + atomic active) to close the residual
  CWE-362 race where _remove_client closes fd before reply/broadcast acquires
  the lock; senders now check active after locking and abort if fd was closed
- P2-7: make _server_fd std::atomic<int> to remove the data-race UB between
  stop() and _event_loop
- P2-8: validate on_message is non-null in MsgServer::start()
- P3-2: distinguish missing _route vs wrong-typed _route in RpcServer
- P3-3: set TCP_NODELAY/SO_SNDTIMEO before registering fd in _clients
- doc: add SO_SNDTIMEO precondition note to pmsg_send
2026-08-07 21:27:05 +08:00
qing 63c22a3d60 fix(libmsg): security audit round 3 - add server send timeout + harden RPC validation 2026-08-07 21:13:14 +08:00
qing 3c50a862d3 fix(libmsg): complete security audit round 2 - fix P0 race + harden input validation
- P0: fix _close_all_clients() race condition (CWE-362) - hold per-connection send_lock
  before close() to prevent messages being sent to wrong client after fd reuse
- P2: add comprehensive input validation for all public APIs
  (timeout/port/workers/max_connections/batch_size etc. bounds checking)
- P2: add UTF-8 payload validation (isValidUtf8) aligning with Python pymsg behavior,
  rejecting overlong encodings, surrogate pairs, truncated/invalid sequences
- P2: document pmsg_recv(int) precondition and recommend deadline mode
- add constructor validation for MsgClient/MsgServer/AsyncQueue/RpcClient/RpcServer
- add add_route() validation for empty route name and null handler
- update security audit report with round 2 findings and fixes (8 issues total, 100% fixed)
2026-08-07 21:01:34 +08:00
qing 9256a8157b fix(db2): add numeric config range validation (fix P2-3/P3-8)
- Add range checks in load_config() for all numeric config values:
  * listen_port: 1-65535
  * workers: >= 1
  * cleanup_interval: >= 1 (prevents busy loop DoS when misconfigured to 0/negative)
  * retention_days: >= 0
  * max_records: >= 1
- Fix unused lambda capture 'this' in RpcServer error handler
  (-Wunused-lambda-capture with -Wall -Werror)
- Update security audit doc: mark P2-3/P3-8 fixed, mark production ready

Verified: g++ -std=c++20 -O3 -Wall -Werror compiles with zero warnings.
2026-08-07 20:48:22 +08:00
qing 761cfd4987 fix(db2): 修复剩余P3问题(limit/offset负值、WHERE/IN规模上限)
- limit/offset 增加非负校验
- WHERE 条件数上限 64,单个 IN 元素上限 1000
- 审计文档:11/11 问题全部修复
2026-08-07 07:46:46 +00:00
qing 2f7a99c2a4 fix(db2): schema缓存基于schema_version自动失效,更新审计文档
- 缓存项携带 PRAGMA schema_version,DDL变更后自动重新反射
- 修复P3-1低危问题,剩余未修复P3问题降至2项
2026-08-07 07:26:29 +00:00
qing 176fb13908 fix(db2): 修复空values和未知运算符问题,更新审计文档
P3-5: INSERT/UPDATE 空 values 前置校验,不再生成无效 SQL
P3-6: 未知 WHERE 运算符立即报错,不再静默跳过

审计文档:新增并发性分析章节,更新进度至 8/11 已修复

剩余 3 项 P3(schema缓存失效、limit负值、条件数上限)待后续迭代
2026-08-07 07:07:55 +00:00
qing ec626dc8d5 fix(db2): 修复清理时间戳格式偏差,增加配置完整性校验
P2-1: 清理 SQL 改用 strftime 统一 T 分隔格式,消除保留期约 1 天偏移
P2-2: load_config 对 7 个必需字段做必填校验,缺失则 exit(1)

审计进度:已修复 6/9(P0×2 P1×1 P2×2 P3×1),剩余 3 项 P3
2026-08-07 06:55:31 +00:00
qing 00421182e4 fix(db2): 按 JSON 类型分别绑定 SQLite 参数,修复类型丢失
- _coerce_value 改为返回 json::value,保留 int/double/bool/null 原始类型
- 新增 _bind_value,按类型调用 sqlite3_bind_int64/double/text/null
- WhereClause::params 改为 vector<json::value>,删除 is_null 向量
- INSERT/UPDATE/SELECT/DELETE 统一使用按类型绑定

修复 P1-1(所有值绑定为 TEXT)和 P3-2(_coerce_value null 处理误导)
2026-08-06 18:23:30 +00:00
qing cb31db1078 docs(security): 更新 libsqlite3 审计报告修复状态
- P0-3 参数化 exec 已修复
- P1-2/P1-3/P1-4 绑定类型与异常信息已修复
- P2-2/P2-3 读取接口与文档已修复
- 修正 P2 问题数量统计(6 项而非 5 项)
2026-08-06 18:14:01 +00:00
qing 1c55443d43 docs(security): 新增 libsqlite3 安全审计报告
- 记录 P0/P1/P2 级别问题与修复状态
- 已修复 double free / 移动语义、close_v2、const 引用等 5 项问题
2026-08-06 18:07:14 +00:00
qing a4611ec737 docs(security): 新增 libmsg 安全审计报告,更新文档索引
新增 docs/security/libmsg_SECURITY_AUDIT_20260806.md,记录 SAST
扫描发现的 3 个漏洞(CWE-362/400/209)及对应修复方案,更新
docs/INDEX.md 加入 libmsg 审计文档入口。
2026-08-06 17:18:27 +00:00
qing 7f288f1c09 docs(security): 修正安全审计文档与代码不一致
- core: MQ kill/exec 实际未禁用,修正错误声明;HttpTask.cpp 行号 L53→L58
- gateway: 更新 20+ 处行号偏移(_KEYGEN/handleProxy/is_safe_target 等)
- aibox: shell=True 4处→3处,handle_connection/WebSocket 行号更新
- DEPS: WebSocketServer.cpp 已删除,fuzz 需求转移至 HttpServer_WsSession
- 加固计划: Phase 1.1 (127.0.0.1 绑定) 标记为已完成
- captcha/libhttp: 修正轻微行号偏移
2026-08-06 15:25:07 +00:00
qing 3460a157d0 docs: 新增 libth 安全审计与 aibox 开放版开发计划 2026-08-04 19:02:22 +08:00
qing fe618be1fa fix(captcha): 验证码存储容量上限防 OOM (P1-1)
新增 MAX_STORE_SIZE(默认 10000,可配置 max_store/CAPTCHA_MAX_STORE),
_handle_image 在清理过期项后检查容量,超限拒绝生成并返回错误,
防止攻击者高频生成验证码填满内存。
2026-08-04 18:40:36 +08:00
qing 4d9bb5d940 fix(libhttp): WebSocket 发送/代理队列上限防 OOM (P1-6)
- 新增 setMaxWsQueueSize()(default 1000),每个入队点检查
- wsSend / onProxyReadClient / onProxyReadBackend 超限关闭连接
- 更新审计文档 P1-6 状态、README v3.4.3
2026-08-04 18:27:50 +08:00
qing 37c6d401d6 fix(libhttp): 服务器读超时防 Slowloris (P1-4)
- 新增 setHeaderTimeout()(default 10s) / setReadTimeout()(default 30s),对齐 WAF
- doSSLHandshake 设置头超时覆盖握手,doRead 拆分为 async_read_header (头超时) + async_read (体超时)
- doWsRead 每次读取设置空闲超时,自动清理长期空闲连接
- 更新审计文档 P1-4 状态、README v3.4.2
2026-08-04 17:39:27 +08:00
qing 507054c4b2 fix(libhttp): WebSocket 单条消息大小限制防 OOM (P1-3)
- 新增 setMaxWsMessageSize/getMaxWsMessageSize(默认 16MB,与 Beast 默认一致)
- 服务端 doWsUpgrade/doWssUpgrade 与代理流 onProxyConnect/onProxySslHandshake 创建后调用 read_message_max
- 超限消息由 Beast 在分配内存前拒绝并关闭连接
- 更新审计文档 P1-3 状态、README v3.4.1
2026-08-04 16:03:06 +08:00
qing 85e0d0740b fix(libhttp): HttpClient 响应大小限制防 OOM
- request_stream_sync 改为真流式,按块回调不二次缓冲
- 新增 set_max_response_size/get_max_response_size(默认 10MB,对齐 WAF)
- write_callback 超限返回 0 中止传输并抛异常
- 更新审计文档 P1-2 状态、README v3.4.0、INDEX 移除不存在的文档
2026-08-04 15:12:06 +08:00
qing 53ddcb364f feat(aibox): 创建/安装技能工具统一生成 .md 扩展名 + 下线旧版 smtp.py
- CreateSkillTool/InstallSkillTool 改为生成带 .md 扩展名的技能文件,与人格技能文件规范一致
- 同步更新 7_extension_skills.md 模板与工具描述
- 删除旧版 smtp.py(P0-1)并同步审计文档与 README
2026-08-04 08:26:57 +08:00
qing fb485ebac4 fix(libhttp): 修复P1-5静态文件路径遍历 + 同步审计文档
- 新增 isSafeStaticPath() 校验静态文件路径,拒绝 ..、空字节、非/开头及URL编码遍历(%2e/%2f/%5c)
- handleRequest 静态文件服务前校验 target_path
- 审计文档标记 P1-5 已修复
2026-08-04 00:04:55 +08:00
qing da4957c52d fix(libhttp): 请求体大小限制可配置并超限返回 413 (P1-1) 2026-08-03 23:57:00 +08:00
qing b37bf255d9 fix(libhttp): 删除遗留 WebSocketServer/WebSocketClient 并同步 CMakeLists 与 Makefile 2026-08-03 23:46:10 +08:00
qing 2f5fe8baaa docs(security): 新增 libhttp 模块安全审计报告 2026-08-03 23:42:32 +08:00
qing 2e3f07bf4f docs(gateway): 审计文档行号纠偏并补充 CORS 白名单死代码根因
- 修正 gateway 审计文档中因代码演进漂移的行号引用(handleProxy/handleLogout/wrapperHttp/限流/TLS/路径防护等)

- 补充 P2-3 CORS 根因:_CORS_ORIGINS 白名单已读取但 OPTIONS 预检由 libhttp 处理,白名单未生效

- 修正 README 中 OPTIONS 预检描述(反射请求 Origin 而非通配 *)及 CORS 配置失效提示
2026-08-03 23:37:47 +08:00
qing 028e0e0806 docs(security): 删除全局审计文档并将问题并入各模块文档
- 各模块专属 P0/P1/P2 问题已分发到 docs/security/ 下各模块审计文档

- gateway 补充 P1-6(反向代理响应无大小限制)、P2-3(CORS 通配)、P2-4(HTTP 无超时)

- 删除全局 SECURITY_AUDIT_20260801.md,避免重复
2026-08-03 23:32:28 +08:00
qing dd4fef6dee fix(pymsg): 异常信息脱敏与JSON深度/大数字限制,防信息泄露与DoS 2026-08-03 22:30:17 +08:00
qing 87f209af73 fix(pymsg): 增加连接数与线程池队列上限,防资源耗尽
- P1-1: MsgServer 新增 max_connections(默认1000),_accept_client 超限
  直接拒绝并关闭新连接,防连接耗尽攻击
- P1-2: 新增 _BoundedThreadPoolExecutor + max_queue_size(默认1000),
  慢 handler 时任务排队超限即拒绝并断开连接,防内存无限增长
同步更新审计报告 P1-1/P1-2 状态,修复率 18.75% -> 25%
2026-08-03 22:25:32 +08:00
qing 47ab9f2fe6 fix(pymsg): 使用 deadline 模式修复 recv 总超时绕过(Slowloris DoS)
_recv_exact 从单次 sock.settimeout() 改为整体 deadline 模式:
header 与 payload 共享同一 total deadline,每次 recv_into 前按剩余
时间收紧超时,逐字节发送无法刷新 deadline,半开连接被及时关闭。
同步更新 pymsg 安全审计报告 P0-1 状态,修复率 6.25% -> 12.5%。
2026-08-03 22:15:44 +08:00
qing f53085b2a6 fix(static): 禁用 yhdet 系列功能并迁移数据库访问到 db 服务
- 注释禁用 yhdet OAuth 相关常量、辅助函数和视图函数(yhdet_callback/yhdet_login/yhdet_verify/proxy_send_code),消除 P0-2/P0-3/P0-4/NEW-1/NEW-2 风险

- YHDET_SECRET 置空并标注已失效;PRIVATE_SECRET 与 YHDET_PRIVATE_API 一并注释

- 新增 _db_call() 辅助函数,api_check_user 改经 pymsg 调 db 服务,不再直连 SQLite

- 修复注册页验证码:点击获取邮箱验证码时图形验证码输入框被清空的问题

- 更新 static 安全审计报告,修复率 25% → 65%
2026-08-03 22:05:02 +08:00
qing 5fbe3ed5e4 docs(security): 更新全部模块审计报告,添加代码验证记录
逐模块对照实际代码验证审计报告中的问题修复状态,添加代码验证记录、逐条验证结果、修复率统计。合并aibox两份审计报告,删除重复文件。修复率:confs 61% > dnfs 60% > ai_review 50% > smtp 37.5% > db 33% > core 12.5% > gateway 12.5% > pymsg 6.25% > static 5% > captcha/aibox/BotOps 0%
2026-08-03 14:12:45 +08:00
qing d3158c2420 docs: add date suffix to remaining documentation files
- Rename SECURITY_HARDENING_PLAN.md -> SECURITY_HARDENING_PLAN_20260803.md
- Rename aibox_SECURITY_AUDIT.md -> aibox_SECURITY_AUDIT_full_20260801.md
- Update INDEX.md links accordingly
2026-08-03 13:26:38 +08:00
qing a7a78d1424 docs: aggregate project documentation under docs/ with unified index
- Move all per-module security audit reports to docs/security/
- Move code review logs to docs/reviews/, analysis reports to docs/reports/
- Add docs/INDEX.md as single entry point for all project documentation
- Add documentation management conventions section to README.md
- Clean up empty per-module docs/ directories
2026-08-03 13:21:48 +08:00