fix(google-sites,pinecone-assistant,decopilot-app): validate URLs taken from request input
What is this Contribution About?
Follow-up to #1702. That PR fixed the website loaders; three integration apps still fetched a URL taken from request input without validation. All of them can be invoked through /live/invoke on any site that installs the app:
google-sites/loaders/extractAllLinks.ts:siteUrlwent tofetch()withredirect: "follow", and everyhttp(s)link in the response came back.google-sites/loaders/searchContent.ts:siteUrlwas fetched and crawled (up to 50 same-host pages), and text snippets matchingquerycame back.pinecone-assistant/actions/upload.ts:fileUrlwas fetched and its body uploaded to the assistant, where it can be read back.decopilot-app/utils/handleAttachments.ts: attachmentfileUrls (CSV, JSON, images) were fetched and inlined into the LLM prompt.
So each one could reach loopback, private and cloud metadata addresses, directly or through a redirect, and return what it read. None had a body size limit.
Changes
- All four now fetch through
fetchPublicUrlfromwebsite/utils/publicUrl.ts: only publichttp(s)URLs, the host's A/AAAA records checked, and every redirect hop validated. - Bodies are read with a cap: 5 MB for HTML/CSV/JSON, 10 MB for decopilot images, 100 MB for Pinecone files (Pinecone's own limit).
- New
readBytesWithLimitinpublicUrl.ts.readTextWithLimitnow decodes its result. - Error handling:
extractAllLinksreturns aninfomessage for a refused URL.searchContentreports a refused URL as an invalid site.- Pinecone returns
success: falsewith the reason, and also on a non-2xx response, which it used to upload as the file. - decopilot throws as it already did for a failed fetch.
Valid public URLs keep working. Same limitation as #1702: DNS rebinding is not covered.
Verification
website/utils/publicUrl_integrations_test.ts(5 tests) checks that each app refusesfile://, metadata, loopback, private,.svcand IPv6 loopback URLs without callingfetch, plus the byte cap. Againstmain, the 4 app tests fail. With this change, all pass.- With Deno 2.4.5 (the CI version):
deno fmt --checkanddeno lintpass.deno checkpasses forwebsite,google-sites,pinecone-assistant,decopilot-appand the new test.deno test website/utils/passes 27/27. - Live
extractAllLinks:https://sites.google.comfollows its redirect and returns links.http://127.0.0.1.nip.io/andhttp://169.254.169.254/return "URL não permitida".
Issue Link
- Issue: none (reported privately)
Loom Video
N/A (no UI change)
Demonstration Link
N/A
🤖 Generated with Claude Code
Summary by cubic
Fixes SSRF in three integration apps: google-sites (extractAllLinks, searchContent), pinecone-assistant (upload), and decopilot-app (attachments) fetched URLs straight from request input without validation, so any site installing the app could reach loopback, private, and cloud metadata addresses and return what was read.
All four now fetch through fetchPublicUrl, which only allows public http(s) URLs, checks the host's DNS A/AAAA records, and validates every redirect hop. Valid public URLs keep working; DNS rebinding is not covered.
Response size limits
- HTML/CSV/JSON bodies are capped at 5 MB, decopilot images at 10 MB, Pinecone files at 100 MB.
- Added
readBytesWithLimittopublicUrl.ts;readTextWithLimitnow decodes its result.
Error handling
- Refused URLs:
extractAllLinksreturns aninfomessage;searchContenttreats them as invalid sites; Pinecone returnssuccess: false, now also for non-2xx responses it used to upload; decopilot throws as before. - Added
publicUrl_integrations_test.tscovering refused URLs and byte caps without network calls.
Summary by CodeRabbit
-
Bug Fixes
- URL-based downloads, site searches, link extraction, and uploads now reject local or internal URLs and limit how much response data is read.
- Oversized responses and unsuccessful requests are handled with clearer failure results, helping prevent unexpected downloads or uploads.
-
Tests
- Added coverage for response-size limits and URL rejection across supported integrations.