Skip to content

Conversation

@edsiper
Copy link
Member

@edsiper edsiper commented Sep 17, 2025

When HTTP_PROXY is defined, we were very strict about asking for the protocol prefix http://. This PR change the validator and if the protocol is not defined it will just assume it's http.


Fluent 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

  • New Features
    • Enhanced proxy URL support: scheme-less URLs default to HTTP, IPv6 hosts (with brackets), and optional credentials (username:password).
  • Bug Fixes
    • More robust parsing with clear validation for hosts, ports, and credentials.
    • Improved error messages for invalid inputs and non-HTTP schemes.
    • Defaults port to 80 when unspecified.
  • Tests
    • Expanded test coverage for new URL formats and direct credential validation.
  • Chores
    • Internal error handling streamlined to prevent memory leaks.
    • No changes to public interfaces.

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
@coderabbitai
Copy link

coderabbitai bot commented Sep 17, 2025

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "utils: relax proxy URL parsing" is concise, focused, and accurately summarizes the primary change in the patch — relaxing proxy URL validation in the utils area to accept URLs without an explicit http:// scheme; it is clear and meaningful for someone scanning commit or PR history.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch utils-relax-proxy

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (4)
src/flb_utils.c (3)

1429-1435: Make scheme check case-insensitive and normalize output protocol.

Schemes are case-insensitive. Accept “HTTP://…” and normalize protocol to "http" to avoid leaking mixed-case to callers.

-        /* Only HTTP proxy is supported for now. */
-        if (strcmp(protocol, "http") != 0) {
-            flb_error("only HTTP proxy is supported.");
-            goto error;
-        }
+        /* Only HTTP proxy is supported (case-insensitive); normalize to "http". */
+        if (strcasecmp(protocol, "http") != 0) {
+            flb_error("only HTTP proxy is supported.");
+            goto error;
+        }
+        flb_free(protocol);
+        protocol = flb_strdup("http");
+        if (!protocol) {
+            flb_errno();
+            goto error;
+        }

1520-1552: Validate port is numeric (and optionally in range).

Currently non-numeric ports (e.g., "proxy.com:abc") pass through and will fail later. Add a digits-only check (and optionally 1..65535).

     }
 
-    if (!host || *host == '\0') {
+    if (!host || *host == '\0') {
         flb_error("HTTP proxy host is missing");
         goto error;
     }
 
+    /* Ensure port is numeric */
+    {
+        const unsigned char *pc = (const unsigned char *) port;
+        if (!pc || *pc == '\0') {
+            flb_error("invalid HTTP proxy port");
+            goto error;
+        }
+        while (*pc) {
+            if (!isdigit(*pc)) {
+                flb_error("invalid HTTP proxy port");
+                goto error;
+            }
+            pc++;
+        }
+        /* Optional: range check
+        char *endp = NULL;
+        long pnum = strtol(port, &endp, 10);
+        if (*endp != '\0' || pnum <= 0 || pnum > 65535) {
+            flb_error("HTTP proxy port out of range");
+            goto error;
+        }
+        */
+    }

1563-1576: Defensive: null the out-params on entry (non-blocking).

For a safer API, consider setting *out_* = NULL on entry so callers never observe indeterminate pointers on failure. Not required by current call sites/tests.

tests/internal/utils.c (1)

488-506: Add cases for scheme case-insensitivity and IPv6 (and one invalid port).

Boost confidence with a few more vectors tied to the new parser behavior.

 struct proxy_url_check proxy_url_checks[] = {
     {0, "http://foo:bar@proxy.com:8080",
      "http", "proxy.com", "8080", "foo", "bar"},
     {0, "http://proxy.com",
      "http", "proxy.com", "80", NULL, NULL},
     {0, "http://proxy.com:8080",
      "http", "proxy.com", "8080", NULL, NULL},
+    /* Case-insensitive scheme */
+    {0, "HTTP://proxy.com:8080",
+     "http", "proxy.com", "8080", NULL, NULL},
     {0, "proxy.com:8080",
      "http", "proxy.com", "8080", NULL, NULL},
     {0, "foo:bar@proxy.com:8080",
      "http", "proxy.com", "8080", "foo", "bar"},
     {0, "proxy.com",
      "http", "proxy.com", "80", NULL, NULL},
+    /* IPv6 bracketed host */
+    {0, "http://[2001:db8::1]:8080",
+     "http", "2001:db8::1", "8080", NULL, NULL},
+    {0, "http://[2001:db8::1]",
+     "http", "2001:db8::1", "80", NULL, NULL},
+    {0, "foo:bar@[2001:db8::1]:8080",
+     "http", "2001:db8::1", "8080", "foo", "bar"},
+    /* Invalid non-numeric port (should fail once port validation is added) */
+    {-1, "proxy.com:abc",
+     NULL, NULL, NULL, NULL, NULL},
     /* issue #5530. Password contains @ */
     {0, "http://example_user:example_pass_w_@_char@proxy.com:8080",
      "http", "proxy.com", "8080", "example_user", "example_pass_w_@_char"},
     {-1, "https://proxy.com:8080",
      NULL, NULL, NULL, NULL, NULL}
 };
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 60db310 and a45b907.

📒 Files selected for processing (2)
  • src/flb_utils.c (1 hunks)
  • tests/internal/utils.c (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/flb_utils.c (1)
include/fluent-bit/flb_mem.h (1)
  • flb_free (126-128)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (29)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit (Arm64), amd64_arm64, -DCMAKE_SYSTEM_NAME=Windows -DCMA...
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 32bit, x86, x86-windows-static, 3.31.6)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit, x64, x64-windows-static, 3.31.6)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_ARROW=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_COVERAGE=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, clang, clang++)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-centos-7
  • GitHub Check: PR - fuzzing test
🔇 Additional comments (4)
src/flb_utils.c (2)

1398-1450: Good: default scheme fallback and stricter input checks.

Using http as the default when no scheme is provided, while rejecting empty/invalid inputs, is the right trade-off for HTTP_PROXY. Memory ownership and error-path cleanup look correct.


1481-1518: IPv6 authority parsing: looks solid.

Bracketed IPv6 handling is correct (host extracted without brackets, port after ‘]’ supported). Clear error paths for malformed inputs.

tests/internal/utils.c (2)

488-506: Nice coverage for scheme-less and credentialed proxies.

The new vectors cover the relaxed parsing well and keep the https rejection. Good addition.


559-574: Assertion changes for username/password look correct.

Directly validating username/password improves signal vs. indirect checks. No issues.

@edsiper edsiper merged commit 6d68748 into master Sep 17, 2025
65 checks passed
@edsiper edsiper deleted the utils-relax-proxy branch September 17, 2025 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants