-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Header parser incorrectly accepts NUL and CR within header values #1908
Comments
@kenballus thanks for the report! |
@kenballus I have merged my pull request for this. Could you test with the latest httplib.h? If you confirm it works, I'll bump the version to v0.17.1, since it's a pretty critical bug. Thanks! |
Confirmed that the new patch works as intended, replacing CR, LF, and NUL with SP. If you're interested, here's what other implementations do in this situation: NUL in header valueReject with 400
Close the connection without responding
Accept the header as-is (violates RFC)
Truncate the header value (violates RFC)
Translate to SP
CR in header valueReject with 400
Close the connection without responding
Accept the header as-is (violates RFC)
Translate to SP
LF in header valueReject with 400
Close the connection without responding
Accept the header as-is (violates RFC)
Translate to SP
Treat it as a line ending
|
Interesting chart! It looks the majority of implementations reject such requests with 400. I can change the current cpp-httplib behavior to return 400. What do you think? |
If it were me, I'd make it respond 400, but you know your users better than I do. If you think cpp-httplib's use cases warrant extra parsing leniency, then translating to SP might be the right call. |
@yhirose I decided to reject such requests. I'll bump up the version to v0.17.1 soon. |
From RFC 9110:
cpp-httplib does not enforce this rule for CR and NUL. You can see this by running a simple example that echoes back header values (such as this), and sending it a request containing NUL and CR within a header value:
The text was updated successfully, but these errors were encountered: