-
Notifications
You must be signed in to change notification settings - Fork 1.9k
in_http: minimal http response and Improved Content-Type detection #11408
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: master
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughEndpoint root response reduced to a minimal JSON payload {"status":"ok"}. Content-Type detection for incoming requests updated to case-insensitive prefix checks for Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 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.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
plugins/in_http/http_prot.c (1)
771-774: Inconsistent handling: URL-encoded still requires exact length.The JSON check was updated to use
>= 16(prefix match), but the URL-encoded check still requires exact length== 33. This meansapplication/x-www-form-urlencoded; charset=utf-8will be rejected on HTTP/1.x but accepted on HTTP/2 (line 1228 uses prefix match).For consistency with the JSON fix and HTTP/2 behavior, consider changing to a prefix match:
Suggested fix
- if (header->val.len == 33 && + if (header->val.len >= 33 && strncasecmp(header->val.data, "application/x-www-form-urlencoded", 33) == 0) {
🧹 Nitpick comments (1)
plugins/in_http/http_prot.c (1)
1224-1230: HTTP/2 content-type checks are consistent with each other but differ slightly from HTTP/1.x.Both JSON and URL-encoded use prefix matching here (no length guard), which is more permissive than HTTP/1.x. While
strncasecmpis safe with shorter strings (stops at null terminator), consider adding a length guard for consistency with line 767, or removing the length guard from line 767 to match this style.
4a773b5 to
e88030a
Compare
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.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
plugins/in_http/http_prot.c (1)
1219-1230: Mirror the delimiter guard for HTTP/2 Content-Type parsing.Same prefix-only behavior here; add a delimiter check so parameters are allowed but invalid tokens are rejected.
🔧 Proposed fix
struct flb_http *ctx; + size_t ct_len; @@ - if (strncasecmp(request->content_type, "application/json", 16) == 0) { + ct_len = strlen(request->content_type); + + if (ct_len >= 16 && + strncasecmp(request->content_type, "application/json", 16) == 0 && + (ct_len == 16 || + (ct_len > 16 && + (request->content_type[16] == ';' || + isspace((unsigned char) request->content_type[16]))))) { type = HTTP_CONTENT_JSON; } - if (strncasecmp(request->content_type, "application/x-www-form-urlencoded", 33) == 0) { + if (ct_len >= 33 && + strncasecmp(request->content_type, "application/x-www-form-urlencoded", 33) == 0 && + (ct_len == 33 || + (ct_len > 33 && + (request->content_type[33] == ';' || + isspace((unsigned char) request->content_type[33]))))) { type = HTTP_CONTENT_URLENCODED; }
🤖 Fix all issues with AI agents
In `@plugins/in_http/http_prot.c`:
- Around line 767-774: The prefix checks accept tokens like "application/jsonp";
tighten them by validating the character after the matched prefix: after
confirming strncasecmp(header->val.data, "application/json", 16) == 0, also
require that header->val.len == 16 or that the next byte header->val.data[16] is
';' or whitespace (use isspace from ctype.h); similarly, after strncasecmp(...
"application/x-www-form-urlencoded", 33) == 0 require header->val.len == 33 or
header->val.data[33] is ';' or whitespace before setting type =
HTTP_CONTENT_JSON or HTTP_CONTENT_URLENCODED respectively.
e88030a to
2a692d9
Compare
Return minimal status information without exposing sensitive details like version, edition, and build flags in the monitoring HTTP server root endpoint. Signed-off-by: Arbin <arbin.cheng@coins.ph>
After confirming strncasecmp match for application/json or application/x-www-form-urlencoded, validate that the character after the matched prefix is acceptable (either end of string, semicolon, or whitespace). This fixes rejection of valid Content-Type with parameters like 'application/json; charset=utf-8' and prevents accepting invalid values like 'application/jsonp'. Also add type == -1 check before urlencoded validation to avoid redundant checks when JSON type was already matched. Signed-off-by: Arbin <arbin.cheng@coins.ph>
2a692d9 to
209274c
Compare
|
@edsiper & @cosmo0920 let me know your comments, THX,. |
Summary
This PR modifies the HTTP server root endpoint (
/) to return minimal information instead of exposing sensitive system details.Changes
Before:
{ "fluent-bit": { "version": "5.0.0", "edition": "Community", "flags": ["FLB_HAVE_SYS_WAIT_H", "FLB_HAVE_SIMD", ...] } }After:
{ "status": "ok" }Motivation
The HTTP server's root endpoint previously exposed sensitive information including:
This information disclosure could be leveraged by attackers to:
This change reduces the attack surface by providing only a minimal health status response.
Modified Files
src/http_server/flb_hs_endpoints.c: Simplified endpoint_root() function to return minimal statusTesting
Example configuration file for the change
Debug log output from testing the change
Attached Valgrind output that shows no leaks or memory corruption was found
Packaging
ok-package-testlabel to test for all targetsDocumentation
Documentation required for this feature
Backporting
Notes
/api/v1/metrics,/api/v1/health, etc.) remain unchangedFluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.