Improve client IP detection#24046
Draft
cconard96 wants to merge 2 commits intoglpi-project:mainfrom
Draft
Conversation
0d8a7af to
a10b71b
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new, centralized client IP detection utility intended to be safer when GLPI is deployed behind one or more reverse proxies, and updates several entry points to use it.
Changes:
- Added
Glpi\Toolbox\IPUtilities::getClientIP()and new reverse-proxy configuration constants (GLPI_TRUSTED_REVERSE_PROXIES,GLPI_REVERSE_PROXY_HEADERS). - Deprecated
Toolbox::getRemoteIpAddress()and migrated API/auth/agent/middleware code paths to the new utility. - Updated PHPStan constants configuration and changelog to reflect the new settings.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
src/Glpi/Toolbox/IPUtilities.php |
New helper for client IP detection with reverse proxy support. |
src/Toolbox.php |
Deprecates legacy getRemoteIpAddress() in favor of IPUtilities. |
src/Glpi/Application/SystemConfigurator.php |
Adds default values for the new reverse-proxy constants. |
src/Glpi/Api/API.php |
Switches API client IP handling to IPUtilities. |
src/Glpi/Api/HL/Middleware/IPRestrictionRequestMiddleware.php |
Uses IPUtilities for OAuth client IP restriction checks. |
src/Auth.php |
Uses IPUtilities for login event IP logging. |
src/Agent.php |
Uses IPUtilities for agent remote address capture. |
tests/functional/ToolboxTest.php |
Adjusts test to avoid deprecation noise from the legacy method. |
stubs/glpi_constants.php |
Adds stubs for the new constants (for static analysis). |
phpstan.neon.dist |
Registers the new constants as dynamic for PHPStan. |
CHANGELOG.md |
Documents the improved client IP detection and new constants. |
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.
Checklist before requesting a review
Description
Adds a new method of determining the client's IP address.
Currently, GLPI checks for some proxy-related headers first in some cases and then fall back to
REMOTE_ADDR.This pull request adds a more secure determination and HTTP headers could be spoofed by the client.
GLPI_TRUSTED_REVERSE_PROXIESconstant. They should additionally modify the newGLPI_REVERSE_PROXY_HEADERSconstant to include the header used by their proxy(s) and only those headers.REMOTE_ADDRagainst the trusted proxy IPs.REMOTE_ADDRis a trusted proxy, only then will GLPI check theGLPI_REVERSE_PROXY_HEADERSin the order they were defined.REMOTE_ADDRis not a trusted proxy, that value is assumed to be the client IP.