Problem/Motivation
I have found that when a site uses more than one proxy server or Varnish or Cloudflare, module EU Cookie Compliance (GDPR Compliance) adds to DB Incorrect user's IP address after click to button "Accept all" or "Reject all".
Steps to reproduce
- check on project with Cloudflare, few proxy servers or locally can test with Varnish container
- install module and configure EU Cookie Compliance (GDPR Compliance) module
- open site by anonymous from Varnish container path and press button "Allow all" on popup cookie window
- check IP address in table "eu_cookie_compliance_basic_consent" of DB and see IP of Cloudflare, proxy server or Varnish container, not a user's IP address.
Proposed resolution
It is related to realization of method Plugin/ConsentStorage/BasicConsentStorage.php:registerConsent that get header "REMOTE_ADDR" when trusted proxies were not set via "setTrustedProxies()".
$ip_address = \Drupal::request()->getClientIp();
https://github.com/symfony/http-foundation/blob/6.3/Request.php#L788
I propose to get the first IP address from header "X-Forwarded-For", because if a request is chained through more than one proxy server, then each proxy adds the IP of the preceding one to the existing X-Forwarded-For header so that the entire chain is preserved. The first IP address in header "X-Forwarded-For" equals the user's IP address.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | after_changes.png | 143.38 KB | ankondrat4 |
| #4 | before_changes.png | 125.08 KB | ankondrat4 |
Issue fork eu_cookie_compliance-3404608
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
ankondrat4 commentedComment #4
ankondrat4 commentedI have added condition to get first IP address from header "X-Forwarded-For" if this header is available.
Merge request were created, please review.
Comment #5
svenryen commentedLooks good, merging.
Thanks for contributing!
Comment #7
svenryen commented