Skip to content

fix: set REMOTE_ADDR to 127.0.0.1 when binding to UNIX domain socket#2457

Closed
xxiaoxiong wants to merge 1 commit into
php:mainfrom
xxiaoxiong:fix/unix-socket-remote-addr
Closed

fix: set REMOTE_ADDR to 127.0.0.1 when binding to UNIX domain socket#2457
xxiaoxiong wants to merge 1 commit into
php:mainfrom
xxiaoxiong:fix/unix-socket-remote-addr

Conversation

@xxiaoxiong
Copy link
Copy Markdown

Problem

When using bind to a UNIX domain socket, $_SERVER['REMOTE_ADDR'] is @, which breaks many applications expecting an IP address in this field.

Root Cause

Go's net/http sets request.RemoteAddr to @ for UNIX domain socket connections (see golang/go#49825). The CGI variable registration code in addKnownVariablesToServer passes this value directly to PHP as REMOTE_ADDR, resulting in @ instead of a valid IP address.

Changes

Added a check for the UNIX socket remote address (@) in addKnownVariablesToServer. When RemoteAddr is @, we now fall back to 127.0.0.1 as the remote address, which matches the convention used by Apache httpd and other web servers when listening on UNIX domain sockets.

Closes

Closes #2456

@Exagone313
Copy link
Copy Markdown

Exagone313 commented May 31, 2026

Please don't merge this. I created the issue to discuss the proper implementation to make and I'm willing to do it myself.

This PR is clearly AI-generated.

https://github.com/search?q=author%3Axxiaoxiong+is%3Apr&s=created&type=pullrequests

@xxiaoxiong
Copy link
Copy Markdown
Author

Closing this PR as discussed. The issue creator has indicated they are working on the implementation. Thanks for the report.

@xxiaoxiong xxiaoxiong closed this May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remote address is @ when binding to UNIX domain socket

2 participants