Thanks to visit codestin.com
Credit goes to github.com

Skip to content

πŸ› bug: harden proxy nil client handling in Do/Forward paths#4083

Merged
ReneWerner87 merged 2 commits intomainfrom
harden-client-handling-in-proxy-middleware
Feb 11, 2026
Merged

πŸ› bug: harden proxy nil client handling in Do/Forward paths#4083
ReneWerner87 merged 2 commits intomainfrom
harden-client-handling-in-proxy-middleware

Conversation

@gaby
Copy link
Member

@gaby gaby commented Feb 11, 2026

This pull request significantly enhances the robustness of the proxy middleware by implementing comprehensive checks for nil fasthttp.Client instances. It ensures that both globally configured and locally overridden clients are valid before use, preventing unexpected panics and providing clearer, more specific error messages. This change improves the overall stability and predictability of proxy operations within the application.

Copilot AI review requested due to automatic review settings February 11, 2026 14:20
@gaby gaby requested a review from a team as a code owner February 11, 2026 14:20
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @gaby, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the robustness of the proxy middleware by implementing comprehensive checks for nil fasthttp.Client instances. It ensures that both globally configured and locally overridden clients are valid before use, preventing unexpected panics and providing clearer, more specific error messages. This change improves the overall stability and predictability of proxy operations within the application.

Highlights

  • Robust Error Handling: Introduced explicit error handling for nil fasthttp.Client instances within the proxy middleware, preventing potential runtime panics.
  • Client Initialization Safety: Added a panic check in the WithClient function to ensure that a non-nil fasthttp.Client is always provided when setting the global proxy client.
  • Nil Client Detection in Operations: Implemented checks in the doAction function to return specific errors when nil client overrides or a nil global client are encountered during proxy operations.
  • Enhanced Test Coverage: Expanded the test suite with new cases to validate the nil client handling, covering scenarios for WithClient panics and Do function error returns with nil client overrides.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • middleware/proxy/proxy.go
    • Imported the standard errors package.
    • Defined new error variables (errNilProxyClientOverride, errNilGlobalProxyClient) for specific nil client scenarios.
    • Added a panic check within the WithClient function to enforce non-nil client assignment.
    • Implemented conditional checks in the doAction function to return the newly defined errors when a nil client is detected, either as an override or from the global client.
  • middleware/proxy/proxy_test.go
    • Added Test_Proxy_WithClient_Nil_Panics to verify that WithClient panics when a nil client is passed.
    • Added Test_Proxy_Do_NilClientOverride to confirm that the Do function returns errNilProxyClientOverride when a nil client override is provided.
    • Added Test_Proxy_Do_NonNilClientOverride to ensure the Do function correctly processes requests with a valid, non-nil client override.
Activity
  • This pull request was automatically generated by Codex.
  • The initial pull request message was a placeholder due to an unexpected error encountered during the generation process.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with πŸ‘ and πŸ‘Ž on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@ReneWerner87 ReneWerner87 added this to v3 Feb 11, 2026
@ReneWerner87 ReneWerner87 added this to the v3 milestone Feb 11, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 11, 2026

Walkthrough

Adds internal nil-safety checks for the proxy HTTP client: WithClient panics on nil, doAction centralizes client selection via selectClient and returns specific internal errors for nil local or global clients. Multiple tests verify panic and error behaviors and local/global override handling.

Changes

Cohort / File(s) Summary
Proxy Client Nil-Safety Implementation
middleware/proxy/proxy.go
Adds errNilProxyClientOverride and errNilGlobalProxyClient, makes WithClient panic on nil, introduces selectClient to resolve client choice, and updates doAction to use selectClient and return defined errors when clients are nil.
Proxy Client Tests
middleware/proxy/proxy_test.go
Adds tests covering WithClient(nil) panic, Do behavior with nil and non-nil local client overrides, selectClient with nil global client, and nil-client behavior across helper methods; validates global and per-request client forwarding.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

☒️ Bug

Suggested reviewers

  • sixcolors
  • efectn
  • ReneWerner87

Poem

🐰 I twitch my nose and hop around,
Guarding clients safe and sound.
Nils I ban with gentle thump,
Panic rings β€” then problems dump.
Forward hops and tests abound!

πŸš₯ Pre-merge checks | βœ… 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 72.73% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description provides a clear overview of the changes but lacks alignment with the template structure. It is missing checklist items, type of change selection, and other required sections from the template. Align the description with the template by completing the checklist items, selecting the type of change (e.g., Code consistency, Enhancement), and addressing missing sections like benchmarks, documentation updates, and examples.
βœ… Passed checks (1 passed)
Check name Status Explanation
Title check βœ… Passed The title clearly summarizes the main change: hardening proxy nil client handling in Do/Forward paths, which aligns with the changeset modifications to proxy.go and proxy_test.go.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • πŸ“ Generate docstrings
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch harden-client-handling-in-proxy-middleware

No actionable comments were generated in the recent review. πŸŽ‰


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.

@gaby gaby changed the title Codex-generated pull request πŸ› bug: harden proxy nil client handling in Do/Forward paths Feb 11, 2026
@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 91.02%. Comparing base (8ca5213) to head (344ce12).
⚠️ Report is 22 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4083      +/-   ##
==========================================
+ Coverage   90.99%   91.02%   +0.03%     
==========================================
  Files         119      119              
  Lines       11256    11303      +47     
==========================================
+ Hits        10242    10289      +47     
  Misses        642      642              
  Partials      372      372              
Flag Coverage Ξ”
unittests 91.02% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds nil client validation to the proxy middleware, preventing nil pointer dereferences when using the Do, Forward, and related functions. The changes add defensive checks at two levels: panicking when setting a nil global client via WithClient, and returning errors when nil clients are passed as function arguments.

Changes:

  • Added nil validation to WithClient function that panics if a nil client is provided
  • Added error handling in doAction to return specific errors when nil clients are encountered (either as overrides or from global state)
  • Added comprehensive test coverage for the new nil client validation behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
middleware/proxy/proxy.go Added error variables for nil client scenarios, panic check in WithClient, and nil checks in doAction
middleware/proxy/proxy_test.go Added three new test functions covering nil client panic behavior and error handling

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the robustness of the proxy middleware by adding checks for nil fasthttp.Client instances, introducing a panic in WithClient for nil clients, and adding error handling in doAction for nil client overrides or global clients. However, a pre-existing high-severity Server-Side Request Forgery (SSRF) vulnerability was identified, where the proxy functions do not validate the target URL, potentially allowing an attacker to force requests to internal services. A recommendation to add validation has been provided. Additionally, while new unit tests are included, a suggestion has been made to add a test case for the errNilGlobalProxyClient error path to ensure full coverage.

Comment on lines 185 to 198
// set local or global client
if len(clients) != 0 {
cli = clients[0]
if cli == nil {
return errNilProxyClientOverride
}
} else {
lock.RLock()
cli = client
lock.RUnlock()
if cli == nil {
return errNilGlobalProxyClient
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

The doAction function, and by extension the Do, Forward, and other proxy functions, are vulnerable to Server-Side Request Forgery (SSRF). The addr parameter, which specifies the target URL for the proxy request, is used without any validation. If an attacker can control this parameter, they can force the server to make requests to arbitrary internal or external services. This could be used to scan internal networks, access sensitive data, or interact with internal APIs. The library does not provide any built-in mechanism (e.g., an IP blocklist or a domain allow-list) to mitigate this risk.

Remediation:
Implement a validation mechanism for the addr parameter. At a minimum, you should prevent requests to localhost and private IP address ranges. Consider adding a configurable allow-list or block-list for domains to provide developers with a tool to secure their proxy implementations.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ReneWerner87 will adress this in a separate PR, since it's a whole different issue.

@ReneWerner87 ReneWerner87 merged commit cdfa624 into main Feb 11, 2026
17 checks passed
@ReneWerner87 ReneWerner87 deleted the harden-client-handling-in-proxy-middleware branch February 11, 2026 19:44
@github-project-automation github-project-automation bot moved this to Done in v3 Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants