fix(security): 防止HTTP响应头注入漏洞

This commit is contained in:
xiongziliang
2026-09-20 23:13:54 +08:00
parent 3e5bd1cfdc
commit 5b5de37a17
2 changed files with 33 additions and 2 deletions

View File

@@ -814,7 +814,13 @@ void HttpSession::sendResponse(int code,
for (auto &pr : header) {
str += pr.first;
str += ": ";
str += pr.second;
// Strip CR and LF from header values to prevent HTTP response splitting (CWE-113).
// Any injected \r or \n is silently removed; other characters pass through unchanged.
for (char c : pr.second) {
if (c != '\r' && c != '\n') {
str += c;
}
}
str += "\r\n";
}
str += "\r\n";