Skip to content

🐛 bug: keep IsFromLocal loopback-only and add unix-socket helper#4270

Merged
ReneWerner87 merged 3 commits into
mainfrom
add-helper-function-for-unix-socket-check
May 10, 2026
Merged

🐛 bug: keep IsFromLocal loopback-only and add unix-socket helper#4270
ReneWerner87 merged 3 commits into
mainfrom
add-helper-function-for-unix-socket-check

Conversation

@gaby
Copy link
Copy Markdown
Member

@gaby gaby commented May 10, 2026

Motivation

  • Fix an authentication/authorization bypass where requests arriving over Unix domain sockets were treated as local by IsFromLocal(), enabling external requests forwarded by a public reverse proxy to be mistaken for localhost.
  • Preserve an explicit opt-in model for trusting Unix-socket proxies while still allowing apps to detect Unix-socket transport if they intend to.
  • Provide a clear API for consumers to make an explicit, auditable decision when handling Unix-socket connections.

Description

  • Reverted the unconditional *net.UnixAddr => true branch from IsFromLocal() so it only returns true for loopback IPs (req.go).
  • Added a new helper IsFromUnixSocket() on Req that returns true when the remote address is a Unix domain socket (req.go).
  • Exported the new method in generated interfaces (req_interface_gen.go, ctx_interface_gen.go) and added documentation for IsFromUnixSocket() in docs/api/ctx.md.
  • Updated tests in ctx_test.go to assert Unix-socket addresses are no longer treated as local and added Test_Ctx_IsFromUnixSocket_RemoteAddr to validate the new helper on both Ctx and Req.

Copilot AI review requested due to automatic review settings May 10, 2026 05:27
@gaby gaby requested a review from a team as a code owner May 10, 2026 05:28
@gaby gaby requested review from ReneWerner87, efectn and sixcolors May 10, 2026 05:28
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 10, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4e5a530d-0c39-4a84-b9c1-ddb5028c1c54

📥 Commits

Reviewing files that changed from the base of the PR and between 031c7db and 716b359.

📒 Files selected for processing (1)
  • req.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • req.go

Walkthrough

Adds IsFromUnixSocket() to Req and Ctx interfaces, implements DefaultReq.IsFromUnixSocket(), changes DefaultReq.IsFromLocal() to consider only loopback IP, updates tests to reflect the separation, and adds API documentation for Ctx.IsFromUnixSocket().

Changes

Unix Socket Detection Separation

Layer / File(s) Summary
Interface Contracts
req_interface_gen.go, ctx_interface_gen.go
Req and Ctx interfaces gain new IsFromUnixSocket() bool method and documentation.
Core Implementation
req.go
DefaultReq.IsFromLocal() now returns true only for loopback RemoteIP(); new DefaultReq.IsFromUnixSocket() returns true when RemoteAddr() is *net.UnixAddr.
Tests
ctx_test.go
Test_Ctx_IsFromLocal_RemoteAddr updated to expect false for Unix socket remote addresses; added Test_Ctx_IsFromUnixSocket_RemoteAddr to validate TCP vs Unix socket behavior.
Documentation
docs/api/ctx.md
Added Ctx.IsFromUnixSocket() API documentation with signature and example usage.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • gofiber/fiber#4088: Modifies request-origin logic in req.go—specifically Unix-socket and IsFromLocal handling and related tests.
  • gofiber/fiber#4051: Adjusts handling for net.Addr variants and Unix socket-related request behaviors.

Suggested reviewers

  • sixcolors
  • ReneWerner87
  • efectn

"A rabbit hops across the code,
Splitting sockets where they go,
Loopback keeps its cozy throne,
Unix sockets stand alone,
Tests and docs sing soft hello."

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: fixing IsFromLocal() to be loopback-only and adding a new IsFromUnixSocket() helper method.
Description check ✅ Passed The pull request description provides clear motivation, detailed description of changes, and explains the security fix without strictly following the template sections.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-helper-function-for-unix-socket-check

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.1)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


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.

@ReneWerner87 ReneWerner87 added this to v3 May 10, 2026
@ReneWerner87 ReneWerner87 added this to the v3 milestone May 10, 2026
@gaby gaby added the aardvark label May 10, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.25%. Comparing base (30b1caa) to head (716b359).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4270   +/-   ##
=======================================
  Coverage   91.25%   91.25%           
=======================================
  Files         130      130           
  Lines       12753    12753           
=======================================
  Hits        11638    11638           
  Misses        702      702           
  Partials      413      413           
Flag Coverage Δ
unittests 91.25% <100.00%> (ø)

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
Copy Markdown
Contributor

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/api/ctx.md`:
- Around line 1267-1281: Run the Markdown linter by executing "make markdown" to
validate and fix any lint issues introduced when updating the IsFromUnixSocket
documentation; after running the linter, review and commit the
generated/modified Markdown fixes (ensure the docs/api/ctx.md entry for
IsFromUnixSocket remains consistent with project style and examples) so
CI/markdown checks pass.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c6c6689e-baad-4738-a127-d7d7c63e077b

📥 Commits

Reviewing files that changed from the base of the PR and between 30b1caa and f0de0c1.

📒 Files selected for processing (5)
  • ctx_interface_gen.go
  • ctx_test.go
  • docs/api/ctx.md
  • req.go
  • req_interface_gen.go

Comment thread docs/api/ctx.md
Copy link
Copy Markdown
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 PR tightens Fiber’s “local request” detection to avoid treating Unix-domain-socket traffic as inherently trusted, closing an authz bypass risk when public reverse proxies forward requests over a Unix socket. It also adds an explicit helper to let applications intentionally detect Unix-socket transport.

Changes:

  • Makes Req.IsFromLocal() loopback-IP only (removes the previous unconditional Unix-socket “local” behavior).
  • Adds IsFromUnixSocket() on Req/Ctx to explicitly detect Unix-domain-socket remote addresses.
  • Updates generated interfaces, API docs, and unit tests to cover the new/changed behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
req.go Removes Unix-socket special-casing from IsFromLocal() and introduces IsFromUnixSocket().
req_interface_gen.go Exposes IsFromUnixSocket() on the generated Req interface.
ctx_interface_gen.go Exposes IsFromUnixSocket() on the generated Ctx interface (via promoted methods).
docs/api/ctx.md Documents the new Ctx.IsFromUnixSocket() API.
ctx_test.go Updates IsFromLocal Unix-socket expectations and adds coverage for IsFromUnixSocket() on both Ctx and Req.

Copy link
Copy Markdown
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 introduces the IsFromUnixSocket method to the Ctx and Req interfaces and updates the IsFromLocal method to exclusively check for loopback IP addresses. Feedback highlights that IsFromUnixSocket needs to be implemented in DefaultCtx to satisfy the interface and prevent compilation errors. Additionally, suggestions were made to update the documentation for IsFromLocal to reflect its changed behavior and to provide a more illustrative example for the new method in the API documentation.

Comment thread req.go
Comment thread req.go Outdated
Comment thread docs/api/ctx.md
gaby and others added 2 commits May 10, 2026 01:33
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@ReneWerner87 ReneWerner87 merged commit 7855220 into main May 10, 2026
22 checks passed
@ReneWerner87 ReneWerner87 deleted the add-helper-function-for-unix-socket-check branch May 10, 2026 12:04
@github-project-automation github-project-automation Bot moved this to Done in v3 May 10, 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