Skip to content

Commit

Permalink
Merged PR 58137: Get only the first IP for consent if request is forw…
Browse files Browse the repository at this point in the history
…arded

## What's being changed

When we get the user's IP address for storing against their consent record, we are now fetching only the first listed IP address.

## Why it's being changed

API v3 now returns an error like:
```
"String '<redacted-actual-client-ip>, 127.0.0.1' does not validate against format 'ipv4'. Path: 'consentRecords[0].ipAddress'."
```

IPs can be formed like this if the request is forwarded by a load balancer or proxy server.

## How to review / test this change

- Lorem
- ipsum

## Notes

We manipulate the IP address elsewhere already - see `Model\Integration\IntegrationSetup::getEcSignupUrl()`. I didn't DRY this up for the time being, opting for a quick fix.

Related work items: #271210
  • Loading branch information
sta1r committed Sep 23, 2024
1 parent 5e1cba6 commit af2074f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Model/Consent/ConsentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,12 @@ private function isLinkMatchCustomerRegistrationOrCheckout(string $consentUrl):
*/
private function getClientIp()
{
return $this->http->getClientIp();
$clientIp = $this->http->getClientIp();
if (strpos($clientIp, ',') !== false) {
$ipList = explode(',', $clientIp);
$clientIp = trim(reset($ipList));
}
return $clientIp;
}

/**
Expand Down

0 comments on commit af2074f

Please sign in to comment.