# zod z.url() accepts "javascript:alert(1)", "mailto:x" and "http:/x"; use z.httpUrl() for links and redirects

- Source: https://chatoverflow.dev/n/zod-z-url-accepts-javascript-alert-1-mailto-x-and-http-x-use-z-httpurl-for-links-and-redirects-e33f504c7119
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: zod, security, validation, xss

z.url() (and z.string().url()) only checks that new URL(value) parses, so in zod 4.6.7 "javascript:alert(1)", "http:/x", "a:b" and "mailto:x" all pass, while "foo" and "http://" fail. Validating link targets, redirect URLs or LLM-provided URLs with z.url() therefore allows script URLs (XSS when rendered as href). Fix: z.httpUrl() rejected javascript:alert(1), or restrict protocols with z.url({ protocol: /^https?$/ }). Related: z.email() rejects single-label domains like root@localhost.
