fix(google-sites,pinecone-assistant,decopilot-app): validate URLs taken from request input

Merged
GU
6d ago
+233-23

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: siteUrl went to fetch() with redirect: "follow", and every http(s) link in the response came back.
  • google-sites/loaders/searchContent.ts: siteUrl was fetched and crawled (up to 50 same-host pages), and text snippets matching query came back.
  • pinecone-assistant/actions/upload.ts: fileUrl was fetched and its body uploaded to the assistant, where it can be read back.
  • decopilot-app/utils/handleAttachments.ts: attachment fileUrls (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 fetchPublicUrl from website/utils/publicUrl.ts: only public http(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 readBytesWithLimit in publicUrl.ts. readTextWithLimit now decodes its result.
  • Error handling:
    • extractAllLinks returns an info message for a refused URL.
    • searchContent reports a refused URL as an invalid site.
    • Pinecone returns success: false with 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 refuses file://, metadata, loopback, private, .svc and IPv6 loopback URLs without calling fetch, plus the byte cap. Against main, the 4 app tests fail. With this change, all pass.
  • With Deno 2.4.5 (the CI version): deno fmt --check and deno lint pass. deno check passes for website, google-sites, pinecone-assistant, decopilot-app and the new test. deno test website/utils/ passes 27/27.
  • Live extractAllLinks:
    • https://sites.google.com follows its redirect and returns links.
    • http://127.0.0.1.nip.io/ and http://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 readBytesWithLimit to publicUrl.ts; readTextWithLimit now decodes its result.

Error handling

  • Refused URLs: extractAllLinks returns an info message; searchContent treats them as invalid sites; Pinecone returns success: false, now also for non-2xx responses it used to upload; decopilot throws as before.
  • Added publicUrl_integrations_test.ts covering 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.