Email for professionals and teams
fix(security): add public-url helper used by webhook validation (#224)
Hieu Nguyen (Jack)79517c00fe89
diff --git a/src/lib/security/public-url.ts b/src/lib/security/public-url.tsnew file mode 100644index 0000000..a9de3bf--- /dev/null+++ b/src/lib/security/public-url.ts@@ -0,0 +1,16 @@+import { isForbiddenHostname, isIpLiteral } from "@/lib/remote-images/fetch";++/**+ * Text-level check that a URL we are asked to call points at a public HTTPS host. It cannot see+ * what the name resolves to, so redirects stay disabled at the call site.+ */+export function isPublicHttpsUrl(value: string): boolean {+ try {+ const url = new URL(value);+ return url.protocol === "https:" && !url.username && !url.password && !!url.hostname && !isIpLiteral(url.hostname) && !isForbiddenHostname(url.hostname);+ } catch {+ return false;+ }+}++export const PUBLIC_HTTPS_URL_MESSAGE = "Webhook URLs must use https:// and point at a public host";