mirror of
https://github.com/znc/znc.git
synced 2026-08-10 19:02:51 +02:00
HTTPSock: extract IsValidHeaderField helper and add tests (#2010)
This commit is contained in:
+5
-2
@@ -762,14 +762,17 @@ void CHTTPSock::SetContentType(const CString& sContentType) {
|
||||
m_sContentType = sContentType;
|
||||
}
|
||||
|
||||
bool CHTTPSock::IsValidHeaderField(const CString& s) {
|
||||
return s.find_first_of("\r\n") == CString::npos;
|
||||
}
|
||||
|
||||
void CHTTPSock::AddHeader(const CString& sName, const CString& sValue) {
|
||||
// Reject CR/LF in either half so we never emit a malformed header or
|
||||
// give a caller (e.g. a future module) a cheap response-splitting
|
||||
// primitive. No in-tree caller reaches this with attacker-controlled
|
||||
// bytes today; this is a defensive guard, not a fix for an existing
|
||||
// exploit.
|
||||
if (sName.find_first_of("\r\n") != CString::npos) return;
|
||||
if (sValue.find_first_of("\r\n") != CString::npos) return;
|
||||
if (!IsValidHeaderField(sName) || !IsValidHeaderField(sValue)) return;
|
||||
m_msHeaders[sName] = sValue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user