Motivation
- Ensure HTTP header field-names conform to RFC to protect against malformed or potentially hostile headers.
- Avoid potential ambiguous framing by refusing requests containing both
Transfer-EncodingandContent-Length.
Implementation Details
- Header field-names token character whitelist and validation using
find_first_not_ofwith an error of"Invalid HTTP header field-name"thrown upon failure. - Check in
HTTPRequest::LoadBodythrowing"Message contains both Transfer-Encoding and Content-Length headers"when both headers are found.
Tests
- Tests for invalid header token characters added to
src/test/httpserver_tests.cpp. - Tests for rejecting requests containing
Transfer-Encoding: chunkedandContent-Lengthadded tosrc/test/httpserver_tests.cpp.
Testing
- HTTP server tests from
src/test/httpserver_tests.cppincluding the new ones for header tokens validation and ambiguous framing were run successfully. - The old header parser and request body tests were run successfully along with the new tests.