mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Update index.ts
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
import net from "node:net";
|
import net from "node:net";
|
||||||
|
|
||||||
|
import RE2 from "re2";
|
||||||
|
|
||||||
import { ForbiddenRequestError } from "../errors";
|
import { ForbiddenRequestError } from "../errors";
|
||||||
|
|
||||||
export enum IPType {
|
export enum IPType {
|
||||||
@@ -7,6 +9,8 @@ export enum IPType {
|
|||||||
IPV6 = "ipv6"
|
IPV6 = "ipv6"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PORT_REGEX = new RE2(/^\d+$/);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strips port from IP address if present.
|
* Strips port from IP address if present.
|
||||||
* Handles both IPv4 (e.g. 1.2.3.4:1234) and IPv6 (e.g. [2001:db8::1]:8080) formats.
|
* Handles both IPv4 (e.g. 1.2.3.4:1234) and IPv6 (e.g. [2001:db8::1]:8080) formats.
|
||||||
@@ -19,14 +23,14 @@ const stripPort = (ip: string): { ipAddress: string } => {
|
|||||||
if (endBracketIndex === -1) return { ipAddress: ip };
|
if (endBracketIndex === -1) return { ipAddress: ip };
|
||||||
const ipPart = ip.slice(1, endBracketIndex);
|
const ipPart = ip.slice(1, endBracketIndex);
|
||||||
const portPart = ip.slice(endBracketIndex + 2);
|
const portPart = ip.slice(endBracketIndex + 2);
|
||||||
if (!portPart || !/^\d+$/.test(portPart)) return { ipAddress: ip };
|
if (!portPart || !PORT_REGEX.test(portPart)) return { ipAddress: ip };
|
||||||
return { ipAddress: ipPart };
|
return { ipAddress: ipPart };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle IPv4 with port (e.g. 1.2.3.4:1234)
|
// Handle IPv4 with port (e.g. 1.2.3.4:1234)
|
||||||
if (ip.includes(":")) {
|
if (ip.includes(":")) {
|
||||||
const [ipPart, portPart] = ip.split(":");
|
const [ipPart, portPart] = ip.split(":");
|
||||||
if (!portPart || !/^\d+$/.test(portPart)) return { ipAddress: ip };
|
if (!portPart || !PORT_REGEX.test(portPart)) return { ipAddress: ip };
|
||||||
return { ipAddress: ipPart };
|
return { ipAddress: ipPart };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user