Skip to content

Commit

Permalink
Add the IP Type to Client IP (#20337)
Browse files Browse the repository at this point in the history
  • Loading branch information
tianzhu007 authored Mar 27, 2024
1 parent c24b6ef commit 6249680
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions server/routerlicious/packages/routerlicious-base/src/alfred/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,23 @@ export function create(
: "";
additionalProperties.hashedClientIPAddress = hashedClientIP;

const clientIPAddress = req.ip ? req.ip : "";
const ipv4Regex = /^(\d{1,3}\.){3}\d{1,3}$/;
const ipv6Regex = /^([\da-f]{1,4}:){7}[\da-f]{1,4}$/i;
if (
ipv4Regex.test(clientIPAddress) &&
clientIPAddress.split(".").every((part) => Number(part) <= 255)
) {
additionalProperties.clientIPType = "IPv4";
} else if (
ipv6Regex.test(clientIPAddress) &&
clientIPAddress.split(":").every((part) => part.length <= 4)
) {
additionalProperties.clientIPType = "IPv6";
} else {
additionalProperties.clientIPType = "";
}

const XAzureClientIP = "x-azure-clientip";
const hashedAzureClientIP = req.headers[XAzureClientIP]
? shajs("sha256").update(`${req.headers[XAzureClientIP]}`).digest("hex")
Expand Down

0 comments on commit 6249680

Please sign in to comment.