fix(web): bound and validate the onboarding extract-content batch - #1528
Open
SEPURI-SAI-KRISHNA wants to merge 1 commit into
Open
fix(web): bound and validate the onboarding extract-content batch#1528SEPURI-SAI-KRISHNA wants to merge 1 commit into
SEPURI-SAI-KRISHNA wants to merge 1 commit into
Conversation
The urls array was forwarded to Exa's billed live-crawl endpoint with no length cap, no parsing, and no scheme check, so one request carrying thousands of URLs (or the same URL repeated) became a proportionally large invoice. Cap the batch at 20, parse each entry with new URL(), require http/https, and de-duplicate on the normalized href.
| ) | ||
| } | ||
|
|
||
| let parsed: URL |
There was a problem hiding this comment.
The Variables and constants rule states: use const by default and use let only when reassignment is needed. The variable parsed is declared with let but is only ever assigned once (inside the try block) and never reassigned. It should be declared with const: const parsed: URL = new URL(url.trim()) (and the try/catch restructured accordingly, e.g. by moving the assignment inside the try block as a const).
Spotted by Graphite (based on custom rule: TypeScript style guide (Google))
Is this helpful? React 👍 or 👎 to let us know.
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.
Summary
/api/onboarding/extract-contentforwards a caller-suppliedurlsarray straight tohttps://api.exa.ai/contentswithlivecrawl: "fallback". The only validation today isthat every element is a non-empty string:
The array is unbounded, entries are never parsed or de-duplicated, and the scheme is
never checked. Each entry is a potentially live-crawled — and billed — Exa request, so a
single call carrying thousands of URLs (or the same URL thousands of times) turns into a
proportionally large invoice.
Changes
MAX_URLS = 20and reject larger payloads with400.new URL()and reject malformed values with400, instead ofpassing junk through to a paid API.
http:orhttps:, so schemes likefile:/data:never reach Exa.href, so a repeated URL is billed once.Behaviour for well-formed input is unchanged, apart from the URLs being sent in
normalized form.
Note for reviewers: this route appears to be unused
While checking the call site to pick a safe
MAX_URLS, I could not find any caller forthis route in the monorepo. The only
/api/*route the web client fetches is/api/og(
apps/web/components/memories-grid.tsx:157).The same appears to hold for its two siblings,
/api/onboarding/researchand/api/onboarding/account-status. All three were added in #672 (Jan 2026), and theonboarding flow has since been rebuilt more than once — #904 (
remove unused old onboarding flow), #1067, #1178 — which looks like it dropped the callers and left theroutes in place.
I have only grepped this repository, so I cannot rule out a caller outside the monorepo,
which is why this PR hardens rather than removes. If these routes are in fact dead,
deleting all three would be the better fix — it removes a network-reachable surface that
spends money against Exa and xAI — and I am happy to open that PR instead.
Testing
biome checkpasses on the changed file.apps/webhas no test runner configured (novitestdependency, notestscript), so no tests were added.