Repository navigation
Description
/api/preview validates url with z.string().url('A valid URL is required') (src/lib/api-validation.ts lines 106 to 108). Zod accepts any scheme there, so ftp:, file:, mailto:, javascript: and data: URLs get through to fetchMetaTags() and fail (or succeed) inside fetch. Calling the route's GET under Node, where npm run test runs it, with the values URL-encoded:
/api/preview → 400 {"error":"url: Invalid input: expected string, received undefined"}
/api/preview?url= → 400 {"error":"url: A valid URL is required"}
/api/preview?url=ftp://example.com → 502 {"error":"fetch failed"}
/api/preview?url=file:///etc/passwd → 502 {"error":"fetch failed"}
/api/preview?url=data:text/html,<title>hi</title> → 200, a full report (grade F) for the data: URL
The first message is Zod's internal wording, not the one the schema sets. The scheme cases are the caller's mistake, so they should be a 400 that says so, not a 502 that reads as if the target site is down.
Second, every response, errors included, uses one headers object with Cache-Control: public, max-age=300 (src/pages/api/preview.ts lines 10 to 14, reused by the 400 at line 22 and the 502 at lines 43 to 46). The preview page fetches with the default cache mode (src/components/preview/usePreviewState.ts line 89), so after a site times out or answers with a 5xx, pressing Check again within five minutes can get the same error straight from the browser cache without trying the site. /api/og had the same problem and fixed it in #109.
Smart Autofill validates its url with the same z.string().url() (src/pages/api/ai/autofill.ts line 19).
What to do
- Add one http(s) URL schema to
src/lib/api-validation.tsand use it forpreviewQuerySchemaand for the autofillurl. Zod 4 hasz.url({ protocol: /^https?$/ }). Uppercase schemes likeHTTPS://must keep working ([Bug] Preview checker rejects valid URLs with uppercase HTTP/HTTPS schemes #329, [Bug] AI autofill mishandles URLs with uppercase HTTP/HTTPS schemes #377). - A missing, empty or unparseable
urlgivesurl: A valid URL is required. Any other scheme gives a 400 whose message says only http and https URLs are supported. - Send
Cache-Control: no-storeon the 400 and 502 responses. A 200 keepspublic, max-age=300.
Acceptance criteria
- No
url,url=andurl=example.comreturn 400 withurl: A valid URL is required -
ftp:,file:,data:,javascript:andmailto:URLs return 400, andfetchMetaTagsisn't called -
http://,https://and uppercase-scheme URLs work as before - 400 and 502 responses send
no-store, 200 responses keeppublic, max-age=300 -
/api/ai/autofillrejects the same schemes with a 400 - Route tests that call
GETwith@/lib/meta-fetchermocked. Todaytests/api/preview.test.tsonly checks the schema;tests/api/og.test.tsshows how to mock a module and call a handler. -
npm run check,npm run testandnpm run buildpass
How to test
Besides the tests, run npm run dev and try the URLs above with curl -i, checking the status and the cache-control header.
Want to work on this? Comment below and I'll assign it to you. Please take one issue at a time, branch off dev, and open your PR against dev with Closes #414 in the description.
Activity
joshuaallgaier2-cmd commentedon Nov 15, 2026
I'll take this issue.
joshuaallgaier2-cmd commentedon Nov 15, 2026
I'd like to take this. Added httpUrlSchema (http/https only) used by preview and autofill, no-store on 400/502, 200 keeps public max-age=300.
joshuaallgaier2-cmd commentedon Nov 15, 2026
I'd like to take this. Added httpUrlSchema (http/https only) used by preview and autofill, no-store on 400/502, 200 keeps public max-age=300. Preview/og route tests pass.
Seyamalam commentedon Nov 20, 2026
Note
🤖 SWE-2 High (Devin) responding on behalf of Seyamalam
I'd like to work on this next (my #425 and #429 were merged). Plan: add a shared http(s)-only URL schema in
src/lib/api-validation.ts(missing/empty/unparseable →url: A valid URL is required, other schemes → a 400 saying only http and https are supported, uppercase schemes still pass), use it forpreviewQuerySchemaand the autofillurl, sendCache-Control: no-storeon the 400/502 while 200 keepspublic, max-age=300, and extendtests/api/preview.test.tsinto route tests callingGETwith@/lib/meta-fetchermocked. Could you assign it to me?anurag629 commentedon Nov 21, 2026
Hey @Seyamalam, it's yours! That plan covers everything in the issue, so go ahead.