Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the IP Type to Client IP #20337

Merged
merged 3 commits into from
Mar 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading