-
Notifications
You must be signed in to change notification settings - Fork 371
http: do not search outside the header value #7606
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
base: main
Are you sure you want to change the base?
Conversation
Performance Measurements ⏳
|
src/waltz/http/fd_http_server.c
Outdated
| for( ulong i=0UL; i<num_headers; i++ ) { | ||
| if( FD_LIKELY( headers[ i ].name_len==22UL && !strncasecmp( headers[ i ].name, "Sec-WebSocket-Protocol", 22UL ) && strstr( headers[ i ].value, "compress-zstd" ) ) ) { | ||
| // Use `memmem` as the header is not guaranteed to be null terminated | ||
| // `memmem` also matches "randomprefix_compress-zstd_randomsuffix" but that's fine, we don't want to fully parse the header value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to just check value_len == 13 and use strncasecmp here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that there might be cases where there are multiple protocols specified in the header, but the existing code and documentation quite explicitly say that this should just be a single value.
Changed to use value_len == 13 and strncmp, because the header field value is usually case-sensitive.
mmcgee-jump
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
Header values in picohttp are not null-terminated so `strstr` would happily search outside the header value and exceed the length of the header value. This could lead to DoS in artifical circumstances which don't apply to fd in practice. There is always a null byte in memory _somewhere_ after the header value even if it is not actually part of the header value. This is because `fd_http_server_ws_frame`s are allocated after the request buffer that contains the headers and the ws_frames contain four bytes of padding that is zero, because the whole memory we're operating on, has been allocated with `mmap` anonymously which zeroes the memory QED.
05a7711 to
b06639f
Compare
Performance Measurements ⏳
|
Header values in picohttp are not null-terminated so
strstrwould happily search outside the header value and exceed the length of the header value.This could lead to DoS in artifical circumstances which don't apply to fd in practice. There is always a null byte in memory somewhere after the header value even if it is not actually part of the header value. This is because
fd_http_server_ws_frames are allocated after the request buffer that contains the headers and the ws_frames contain four bytes of padding that is zero, because the whole memory we're operating on, has been allocated withmmapanonymously which zeroes the memory QED.Drive-by fix: the
Upgradeheader field's token has to contain the value "websocket", but should be treated as an ASCII case-insensitive value: https://datatracker.ietf.org/doc/html/rfc6455#section-4.2.1