Repository navigation
Conversation
/api/preview accepted any URL scheme (ftp:, file:, javascript:, data:) which failed deep inside fetch or produced nonsense reports, and cached 400/502 responses for five minutes. A shared http(s)-only schema now rejects bad schemes with a 400, error responses send no-store, and /api/ai/autofill uses the same schema. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
/api/previewvalidatesurlwithz.string().url(), which Zod accepts for any scheme — softp:,file:,mailto:,javascript:anddata:URLs reachfetchMetaTags()and surface as a 502 (or, fordata:, a nonsense 200 report) instead of the caller's 400. Separately, every response — errors included — goes out withCache-Control: public, max-age=300, so a site that times out keeps serving the same cached 502 for five minutes (/api/oghad the same issue, fixed in #109).This adds a shared
httpUrlSchemainsrc/lib/api-validation.tsand uses it for bothpreviewQuerySchemaand the autofillurl. Missing, empty, or unparseable values reporturl: A valid URL is required; a parsable non-http(s) URL gets a 400 saying only http and https URLs are supported; uppercase schemes likeHTTPS://keep working. The 400 and 502 responses now sendCache-Control: no-store; 200 keepspublic, max-age=300.Closes #414
How I Tested This
npx vitest run tests/api/preview.test.ts— 34 tests: the routeGETis called with@/lib/meta-fetchermocked (liketests/api/og.test.ts), covering missing/empty/unparseableurl, all five bad schemes (ftp:,file:,data:,javascript:,mailto:— assertingfetchMetaTagsis never called),http/https/uppercase-scheme success, 502 on fetch failure, theno-storevsmax-age=300headers, and the same scheme rejections throughPOST /api/ai/autofill.npm run check(0 errors), fullnpm run test(2151 tests), andnpm run buildall pass.AI Assistance
Devin CLI (SWE-2 High): implemented the shared schema, the route header change, the autofill schema swap, and the test file under human direction; diff reviewed and verified by the operator.
Type of Change
Screenshots
N/A — API behavior change only, no UI.
Checklist
devnpm run checkpassesnpm run testpassesnpm run dev(route tests exercise the handler directly;curlspot-checks in tests)Created with SWE-2 High in Devin CLI.