| 14 | } |
| 15 | |
| 16 | void HTTPHeaderFilter::checkAndNormalizeHeaders(HTTPHeaderEntries & entries) const |
| 17 | { |
| 18 | std::lock_guard guard(mutex); |
| 19 | |
| 20 | for (auto & entry : entries) |
| 21 | { |
| 22 | if (entry.name.contains('\n') || entry.value.contains('\n')) |
| 23 | throw Exception(ErrorCodes::BAD_ARGUMENTS, "HTTP header \"{}\" has invalid character", entry.name); |
| 24 | /// Strip whitespace and control characters from header name for validation |
| 25 | std::string & normalized_name = entry.name; |
| 26 | normalized_name.erase( |
| 27 | std::remove_if( |
| 28 | normalized_name.begin(), |
| 29 | normalized_name.end(), |
| 30 | [](char c) { return std::iscntrl(static_cast<unsigned char>(c)) || std::isspace(static_cast<unsigned char>(c)); }), |
| 31 | normalized_name.end()); |
| 32 | |
| 33 | if (forbidden_headers.contains(normalized_name)) |
| 34 | throw Exception(ErrorCodes::BAD_ARGUMENTS, "HTTP header \"{}\" is forbidden in configuration file, " |
| 35 | "see <http_forbid_headers>", entry.name); |
| 36 | |
| 37 | for (const auto & header_regex : forbidden_headers_regexp) |
| 38 | if (re2::RE2::FullMatch(normalized_name, header_regex)) |
| 39 | throw Exception(ErrorCodes::BAD_ARGUMENTS, "HTTP header \"{}\" is forbidden in configuration file, " |
| 40 | "see <http_forbid_headers>", entry.name); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | void HTTPHeaderFilter::setValuesFromConfig(const Poco::Util::AbstractConfiguration & config) |
| 45 | { |