fix(libmsg): 修复安全审计发现的三个漏洞

- CWE-362: _remove_client() 关闭 fd 前获取 per-connection send_lock,
  防止 broadcast/reply 向 OS 复用的 fd 发送数据到错误客户端
- CWE-400: workers>0 模式下消息接收移至 worker 线程,
  事件循环不再阻塞 pmsg_recv,防 Slowloris DoS
- CWE-209: 扩展 _sanitize_error 路径正则为 /\S+,
  覆盖含空格/括号/@/~ 等特殊字符的内部路径,防信息泄露
This commit is contained in:
qing committed 2026-08-06 17:16:33 +00:00
1 parent 61a0e4cf7a
commit e92ef05ed0
2 files changed
+45 -19

No files matched your search

+2 -3
View File
@@ -179,9 +179,8 @@ private:
static std::string _sanitize_error(const std::string& msg) {
if (msg.empty()) return msg;
try {
// 匹配以 / 开头的绝对路径段,替换为 <redacted>
// 不返回函数堆栈、SQL、文件路径等内部细节给客户端
static const std::regex path_re(R"(/[A-Za-z0-9_.\-]+(?:/[A-Za-z0-9_.\-]+)*)");
// 匹配以 / 开头的绝对路径(含特殊字符如空格、括号、@、~ 等),替换为 <redacted>
static const std::regex path_re(R"(/\S+(?:/\S*)*)");
return std::regex_replace(msg, path_re, "<redacted>");
} catch (...) {
return msg; // 正则异常时返回原文