修复源码信息泄漏以及token无限期问题
This commit is contained in:
1 parent
13be4bd8ca
commit
efae81b230
3 files changed
+46
-13
No files matched your search
+14
-5
@@ -161,15 +161,23 @@ protected:
|
||||
|
||||
virtual std::string build_message() const {
|
||||
std::string result;
|
||||
|
||||
|
||||
// 错误码
|
||||
if (m_code != 0) {
|
||||
result += "[Error " + std::to_string(m_code) + "] ";
|
||||
}
|
||||
|
||||
|
||||
// 错误消息
|
||||
result += m_message;
|
||||
|
||||
|
||||
/* ===== 以下「位置信息」与「嵌套异常」暂时以注释方式保留 =====
|
||||
* 原因:黑盒检测发现 what() 的返回值会透传到 HTTP 响应体,
|
||||
* 导致泄露源码文件路径、行号、C++ 模板类型签名(函数名),
|
||||
* 便于攻击者定位代码、确认技术栈、构造针对性 payload(P0-3)。
|
||||
* 排障:完整信息仍由各 handler 通过 std::cerr 输出到服务端日志。
|
||||
* 恢复:如需调试可临时取消下方注释;生产环境必须保持注释状态,
|
||||
* 并确保 what() 不直接进入客户端响应。
|
||||
* ====================================================================
|
||||
// 位置信息
|
||||
if (!m_file.empty()) {
|
||||
result += " (at " + m_file;
|
||||
@@ -181,12 +189,13 @@ protected:
|
||||
}
|
||||
result += ")";
|
||||
}
|
||||
|
||||
|
||||
// 嵌套异常
|
||||
if (m_nested) {
|
||||
result += "\n Caused by: " + std::string(m_nested->what());
|
||||
}
|
||||
|
||||
* ==================================================================== */
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
#include <format>
|
||||
@@ -13,7 +14,7 @@ public:
|
||||
auto now = system_clock::now();
|
||||
auto zone = current_zone();
|
||||
zoned_time zt{zone, now};
|
||||
return std::vformat(format, std::make_format_args(zt));
|
||||
return std::vformat("{:" + format + "}", std::make_format_args(zt));
|
||||
}
|
||||
|
||||
// 解析时间字符串为 system_clock::time_point(本地时间 → UTC)
|
||||
|
||||
+30
-7
@@ -697,9 +697,14 @@ http::response<http::string_body> handleLogin(
|
||||
|
||||
catch (const HttpException& e) {
|
||||
|
||||
// 详细错误信息(e.what() 含源码路径/行号/C++ 模板类型)暂时以注释方式保留
|
||||
// 原因:黑盒检测发现透传到客户端会泄露内部实现,便于攻击者定位代码(P0-3)
|
||||
// 排障:完整信息仍输出到服务端 stderr
|
||||
std::cerr << "[handleLogin HttpException] " << e.what() << std::endl;
|
||||
json::value jv_r = {
|
||||
{"success", false},
|
||||
{"message", e.what()}
|
||||
/* {"message", e.what()}, */ // 泄露源码信息,已禁用
|
||||
{"message", "Invalid Username or Password"}
|
||||
};
|
||||
res.set(http::field::content_type, "application/json");
|
||||
res.result(e.status());
|
||||
@@ -799,9 +804,12 @@ http::response<http::string_body> handleRegister(
|
||||
}
|
||||
|
||||
catch (const HttpException& e) {
|
||||
// 详细错误信息(e.what() 含源码路径/行号/C++ 模板类型)暂时以注释方式保留(同 handleLogin)
|
||||
std::cerr << "[handleRegister HttpException] " << e.what() << std::endl;
|
||||
json::value jv_r = {
|
||||
{"success", false},
|
||||
{"message", e.what()}
|
||||
/* {"message", e.what()}, */ // 泄露源码信息,已禁用
|
||||
{"message", "Registration failed"}
|
||||
};
|
||||
res.set(http::field::content_type, "application/json");
|
||||
res.result(e.status());
|
||||
@@ -810,9 +818,19 @@ http::response<http::string_body> handleRegister(
|
||||
|
||||
catch (const std::exception& e) {
|
||||
const auto& ti = typeid(e);
|
||||
res.set(http::field::content_type, "text/plain");
|
||||
// 详细错误信息(ti.name() 含 mangled 类型名、e.what() 含内部细节)暂时以注释方式保留
|
||||
// 原因:mangled 类型名会确认技术栈与 STL 容器,e.what() 可能泄露内部路径(P0-3)
|
||||
// 排障:完整信息仍输出到服务端 stderr
|
||||
std::cerr << "[handleRegister std::exception] <" << ti.name() << "> " << e.what() << std::endl;
|
||||
res.set(http::field::content_type, "application/json");
|
||||
res.result(http::status::internal_server_error);
|
||||
res.body() = std::string("<") + ti.name() + "> " + e.what();
|
||||
json::value jv_r = {
|
||||
{"success", false},
|
||||
/* {"err_name", ti.name()}, // 泄露 C++ 类型信息,已禁用 */
|
||||
/* {"err_message", e.what()} // 泄露内部细节,已禁用 */
|
||||
{"message", "Internal Server Error"}
|
||||
};
|
||||
res.body() = json::serialize(jv_r);
|
||||
}
|
||||
|
||||
res.prepare_payload();
|
||||
@@ -940,12 +958,17 @@ http::response<http::string_body> handleProxy(
|
||||
|
||||
catch (const std::exception& e) {
|
||||
const auto& ti = typeid(e);
|
||||
res.set(http::field::content_type, "text/plain");
|
||||
// 详细错误信息(ti.name() 含 mangled 类型名、e.what() 含内部细节)暂时以注释方式保留
|
||||
// 原因:mangled 类型名会确认技术栈与 STL 容器,e.what() 可能泄露内部路径(P0-3)
|
||||
// 排障:完整信息仍输出到服务端 stderr
|
||||
std::cerr << "[handleProxy std::exception] <" << ti.name() << "> " << e.what() << std::endl;
|
||||
res.set(http::field::content_type, "application/json");
|
||||
res.result(http::status::internal_server_error);
|
||||
json::value jv_r = {
|
||||
{"success", false},
|
||||
{"err_name", ti.name()},
|
||||
{"err_message", e.what()}
|
||||
/* {"err_name", ti.name()}, // 泄露 C++ 类型信息,已禁用 */
|
||||
/* {"err_message", e.what()} // 泄露内部细节,已禁用 */
|
||||
{"message", "Internal Server Error"}
|
||||
};
|
||||
res.body() = json::serialize(jv_r);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user