🐛 bug: address PR review comments for Unix-socket proxy trust#4089
🐛 bug: address PR review comments for Unix-socket proxy trust#4089gaby merged 3 commits intoupdate-proxy-trust-logic-in-req.gofrom
Conversation
…est race condition Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## update-proxy-trust-logic-in-req.go #4089 +/- ##
======================================================================
- Coverage 91.06% 90.97% -0.10%
======================================================================
Files 119 119
Lines 11309 11318 +9
======================================================================
- Hits 10299 10297 -2
- Misses 638 648 +10
- Partials 372 373 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
5e650fd
into
update-proxy-trust-logic-in-req.go
There was a problem hiding this comment.
Pull request overview
This PR refines Fiber’s trusted-proxy behavior around Unix domain sockets and hardens request IP handling by preventing RemoteIP()-related panics, while updating config/docs/tests to support an explicit Unix-socket trust toggle.
Changes:
- Added nil-guards around
fasthttp.RemoteIP()usage in request IP/local checks. - Introduced
TrustProxyConfig.UnixSocketand updated proxy-trust logic to use it for Unix socket connections. - Updated docs and Unix-socket proxy-trust tests to reflect the new configuration semantics.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
req.go |
Adds nil-safety for RemoteIP() and updates IsProxyTrusted() Unix-socket/type handling. |
app.go |
Extends TrustProxyConfig with a new UnixSocket option. |
ctx_test.go |
Updates Unix-socket proxy-trust tests for the new config flag and improves reliability. |
docs/whats_new.md |
Documents the new UnixSocket config option in the trusted proxy example. |
docs/api/ctx.md |
Documents UnixSocket under IsProxyTrusted configuration example. |
| // UnixSocket enables trusting Unix domain socket connections. | ||
| // When enabled, requests from Unix sockets are treated as trusted proxies. | ||
| // | ||
| // Default: false | ||
| UnixSocket bool `json:"unix_socket"` |
There was a problem hiding this comment.
Adding a new exported field to TrustProxyConfig is a source-breaking change for downstream users who may be using unkeyed composite literals (fiber.TrustProxyConfig{...}). Consider calling this out as a breaking change in release notes, or ensure docs/examples consistently use keyed fields to avoid this footgun.
| // Keep existing RemoteIP/IP-map/CIDR checks for TCP/UDP paths as-is. | ||
| default: | ||
| // Unknown address type: do not trust by default. | ||
| return false |
There was a problem hiding this comment.
The new default branch returns false for any RemoteAddr() type other than *net.UnixAddr, *net.TCPAddr, or *net.UDPAddr. Since fasthttp.RequestCtx.SetRemoteAddr can set arbitrary net.Addr implementations, this changes prior behavior by rejecting proxy trust even when RemoteIP() returns a valid IP that matches TrustProxyConfig. Consider falling back to the existing IP-based checks for unknown non-Unix address types (fail closed only when RemoteIP() is nil).
| Proxies: []string{"0.8.0.0", "1.1.1.1/30"}, // IP address or IP address range | ||
| Loopback: true, // Trust loopback addresses (127.0.0.0/8, ::1/128) | ||
| UnixSocket: true, // Trust Unix domain socket connections |
There was a problem hiding this comment.
The IsProxyTrusted docs in this section say that when TrustProxy is false it returns true, but the implementation returns false. Please correct the documentation text to match the actual behavior.
| Loopback: true, | ||
| // Trust Unix domain socket connections | ||
| UnixSocket: true, | ||
| } |
There was a problem hiding this comment.
This Go example won’t compile as written because the TrustProxyConfig: fiber.TrustProxyConfig{ ... } element in the outer fiber.Config{ ... } literal is missing a trailing comma after the closing }. Add the comma to keep the snippet valid.
| } | |
| }, |
| switch remoteAddr.(type) { | ||
| case *net.UnixAddr: | ||
| return config.TrustProxyConfig.Loopback | ||
| return config.TrustProxyConfig.UnixSocket |
There was a problem hiding this comment.
Switching Unix-socket trust from being controlled by TrustProxyConfig.Loopback to the new TrustProxyConfig.UnixSocket changes behavior for existing configs (Unix-socket requests will no longer be trusted when only Loopback is enabled). If this behavior change is intentional, it should be called out clearly in release notes/migration docs, or consider a compatibility fallback for one release cycle.
| return config.TrustProxyConfig.UnixSocket | |
| // For backward compatibility, also honor Loopback for Unix sockets. | |
| // Existing configs that only enabled Loopback will continue to trust | |
| // Unix-socket requests, while new configs can explicitly control this | |
| // via TrustProxyConfig.UnixSocket. | |
| return config.TrustProxyConfig.UnixSocket || config.TrustProxyConfig.Loopback |
Description
Addresses review feedback from PR #4088 by adding comprehensive nil protection for
RemoteIP()calls, refining type handling in proxy trust logic, improving test reliability, and introducing explicit Unix socket configuration semantics.Changes introduced
RemoteIP()invocations inIP(),extractIPFromHeader(), andIsFromLocal()to prevent panics with Unix sockets and other edge casesIsProxyTrusted()type switch to explicitly reject unknown address typesTrustProxyConfig.UnixSocketfield to replace semantic overloading ofLoopbacksettingUnixSocketfield documentation indocs/api/ctx.mdanddocs/whats_new.mdType of change
Checklist
/docs/directory for Fiber's documentation.✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.