Add opt-in mod_remoteip support for X-Forwarded-For handling#513
Open
cuppett wants to merge 1 commit intosclorg:masterfrom
Open
Add opt-in mod_remoteip support for X-Forwarded-For handling#513cuppett wants to merge 1 commit intosclorg:masterfrom
cuppett wants to merge 1 commit intosclorg:masterfrom
Conversation
Adds HTTPD_ENABLE_REMOTEIP environment variable that enables Apache mod_remoteip to properly handle X-Forwarded-For headers when running behind reverse proxies, load balancers, or in Kubernetes/OpenShift environments. When enabled, configures Apache to trust private IP ranges commonly used in Docker/container networks. Changes: - Added pre-start scripts (40-remoteip.sh) for PHP versions 7.4, 8.0, 8.1, 8.2, 8.3 - Updated README documentation for all versions - Added comprehensive test coverage (3 test methods) - Fixed test/run-pytest to support Python 3.14 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
Pull Request validationFailed🔴 Review - Missing review from a member (1 required) Success🟢 CI - All checks have passed |
Contributor
Author
|
@phracek not sure if you are monitoring this repository closely. Let me know if this is able to be merged or needed. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds opt-in Apache
mod_remoteipsupport via theHTTPD_ENABLE_REMOTEIP=1environment variable to properly handleX-Forwarded-Forheaders when running behind reverse proxies, load balancers, or in Kubernetes/OpenShift environments.Why Enable This?
When PHP containers run behind reverse proxies (Nginx, HAProxy, Kubernetes Ingress, OpenShift Routes, cloud load balancers), Apache sees the proxy's IP address instead of the actual client's IP address. This causes issues with:
10.0.0.5) instead of real client IP$_SERVER['REMOTE_ADDR']: Returns proxy IP instead of client IPWhat This Changes
With mod_remoteip Enabled
Apache will:
X-Forwarded-Forheader from trusted proxy IPsREMOTE_ADDRwith the real client IP from the header$_SERVER['REMOTE_ADDR']Example Impact on Logs
Before (proxy IP logged):
After (real client IP logged):
Security Considerations
This feature only trusts
X-Forwarded-Forheaders from private IP ranges:10.0.0.0/8- Private networks172.16.0.0/12- Private networks192.168.0.0/16- Private networks169.254.0.0/16- Link-local127.0.0.0/8- LoopbackThis prevents external clients from spoofing their IP address via forged headers.
Implementation
This implementation follows the approach used in docker-library/wordpress but adapted for RHEL-based httpd (vs Debian's apache2).
Changes
40-remoteip.shfor PHP versions 7.4, 8.0, 8.1, 8.2, 8.3 that conditionally enable mod_remoteipHTTPD_ENABLE_REMOTEIPenvironment variabletest/run-pytestConfiguration Applied
When
HTTPD_ENABLE_REMOTEIP=1is set:Usage
Docker:
Kubernetes/OpenShift:
Test Results
All new tests passing:
🤖 Generated with Claude Code