Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat(validator): enhance URL validation for trailing-dot FQDNs
Victor Hugo dos Santos36bb0c934fc5
diff --git a/backend/src/lib/validator/safe-request.test.ts b/backend/src/lib/validator/safe-request.test.tsindex efa961ad5b..8929e1b756 100644--- a/backend/src/lib/validator/safe-request.test.ts+++ b/backend/src/lib/validator/safe-request.test.ts@@ -116,6 +116,16 @@ describe("safe-request SSRF helpers", () => {await expect(validateAndPinUrl("http://host.docker.internal")).rejects.toThrow(/Local IPs not allowed/i);});+ it("rejects the trailing-dot FQDN form `localhost.`", async () => {+ await expect(validateAndPinUrl("http://localhost./")).rejects.toThrow(/Local IPs not allowed/i);+ expect(lookupMock).not.toHaveBeenCalled();+ });++ it("rejects the trailing-dot FQDN form `host.docker.internal.`", async () => {+ await expect(validateAndPinUrl("http://host.docker.internal./")).rejects.toThrow(/Local IPs not allowed/i);+ expect(lookupMock).not.toHaveBeenCalled();+ });+it("rejects RFC1918 / loopback IPs by default", async () => {setLookup([{ address: PRIVATE_IP_V4, family: 4 }]);await expect(validateAndPinUrl("https://example.com")).rejects.toThrow(/Local IPs not allowed/i);diff --git a/backend/src/lib/validator/safe-request.ts b/backend/src/lib/validator/safe-request.tsindex 18a9664ef1..b2ddd1ca4a 100644--- a/backend/src/lib/validator/safe-request.ts+++ b/backend/src/lib/validator/safe-request.ts@@ -41,13 +41,16 @@ export const validateAndPinUrl = async (throw new BadRequestError({ message: "URLs with user credentials (e.g., user:pass@) are not allowed" });}- // IPv6 literal hostnames come back from `new URL()` wrapped in brackets- // (e.g. "[::1]"). isIP and dns.lookup both reject the bracketed form, so- // strip them before passing the host on.- const rawHost =- validUrl.hostname.startsWith("[") && validUrl.hostname.endsWith("]")- ? validUrl.hostname.slice(1, -1)- : validUrl.hostname;+ // `new URL()` preserves both IPv6 brackets (e.g. "[::1]") and trailing+ // FQDN dots (e.g. "localhost."). Strip both so isIP / dns.lookup / the+ // literal-hostname check all see a clean form.+ let rawHost = validUrl.hostname;+ if (rawHost.startsWith("[") && rawHost.endsWith("]")) {+ rawHost = rawHost.slice(1, -1);+ }+ if (rawHost.endsWith(".")) {+ rawHost = rawHost.slice(0, -1);+ }let entries: LookupAddress[];if (isIP(rawHost)) {