fluent-bit icon indicating copy to clipboard operation
fluent-bit copied to clipboard

in_http: Fast fix for the issue related to validate the Content-Type

Open demonccc opened this issue 2 years ago • 6 comments

Fix to accept a Content Type Header that have application/json and other configurations, ex: charset

Fixes https://github.com/fluent/fluent-bit/issues/5062 Enter [N/A] in the box, if an item is not applicable to your change.

Testing Before we can approve your change; please submit the following in a comment:

[N/A] Example configuration file for the change [ N/A] Debug log output from testing the change [ N/A] Attached Valgrind output that shows no leaks or memory corruption was found If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

[N/A] Attached local packaging test output showing all targets (including any new ones) build. Documentation

[N/A] Documentation required for this feature Backporting

[N/A] Backport to latest stable release.

demonccc avatar Feb 14 '23 17:02 demonccc

I updated my repository with the latest changes from master and created a new pull request with the proposed change. This is the old pr: https://github.com/fluent/fluent-bit/pull/5272.

I also added the signed off comments.

demonccc avatar Feb 14 '23 17:02 demonccc

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] avatar May 16 '23 01:05 github-actions[bot]

The only issue I have with this is that according to RFC 7231 if there are any parameters they should be separated from the media type by a semicolon and with your patch any trailing characters would still match (ie. application/json_but_a_non_compliant_one_actually).

So I think the uglier but more compliant version would be :

    if (header->val.len > 16 &&
        strncasecmp(header->val.data, "application/json;", 17) == 0) {
        type = HTTP_CONTENT_JSON;
    }
    else if (header->val.len == 16 &&
        strncasecmp(header->val.data, "application/json", 16) == 0) {
        type = HTTP_CONTENT_JSON;
    }

I couldn't find anything in the RFC about spaces before the semicolon so I assume this simplistic ugly approach would cover the majority of cases but honestly, I don't even know if it's worth the hassle trying to ensure that there are no trailing characters that break the comparison...

leonardo-albertovich avatar May 16 '23 08:05 leonardo-albertovich

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] avatar Aug 16 '23 01:08 github-actions[bot]

Hi, I will add these changes.

demonccc avatar Aug 31 '23 13:08 demonccc

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] avatar Nov 30 '23 01:11 github-actions[bot]

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] avatar Nov 27 '24 02:11 github-actions[bot]

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] avatar Aug 28 '25 02:08 github-actions[bot]