Harden GoogleDriveProvider downloads and folder listing

Aperta
#4,921 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
56/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
api, backend

Direzione di ricerca

Start with packages/server/src/modules/app-providers/google-drive/google-drive.provider.ts and compare its download limits and MIME checks with fetch-remote-document.helper.ts. Then inspect the existing URL recognition test in documents/helpers/fetch-remote-document.test.ts for the project’s test setup. Done means mocked-fetch tests cover download validation, complete folder pagination and filtering, readable HTTP errors, and the missing API key.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Problem

GoogleDriveProvider (packages/server/src/modules/app-providers/google-drive/google-drive.provider.ts) trusts Drive's responses in ways that can store a non-document as a financial record, or silently skip files. It backs batchUploadDocumentsFromUrls (Drive file links, including the MCP tool accounter_upload_documents with documentUrls) and batchUploadDocumentsFromGoogleDrive (shared folders, used from the client's upload modal).

fetchFile: download is not validated

The download is an anonymous GET https://drive.google.com/uc?export=download&id=<id>. Before turning the body into a File stamped with the MIME type from the metadata call, it checks none of these:

  • response.ok
  • the response Content-Type
  • the body size (fetchRemoteDocument caps at 25MB; this path has no cap)

When Drive answers with an HTML page instead of the file, that page is uploaded to Cloudinary and OCR'd as if it were a PDF or image. This happens for a sign-in or permission page (file not public) and for the large-file "virus scan" confirmation page.

fetchFolderContent: listing is incomplete and errors are opaque

The listing is GET https://www.googleapis.com/drive/v3/files?q='<folderId>'+in+parents&key=.... Problems:

  • No paging. There is no pageSize/pageToken handling, so only the first page of a large folder is returned. The rest is dropped silently.
  • Trashed files included. There is no trashed = false filter.
  • Unescaped id. The folder id is not URL-encoded, and anything after it in the path (e.g. a trailing /) stays in the id.
  • Status never checked. res.ok is not checked. A 4xx error body (bad or missing API key, folder not shared) fails schema parsing and surfaces as the generic Failed to parse response from Google Drive.
Other
  • With GOOGLE_DRIVE_API_KEY unset, the provider still sends requests with an empty key=. A clear "Drive is not configured" error would be better.
  • There are no tests for network behaviour. The only Drive test is isFileUrl URL recognition, in documents/helpers/fetch-remote-document.test.ts.

Out of scope

Access to private, non-public Drive files (service account or OAuth). This issue is only about the existing public-link path.

Done when

  • fetchFile rejects:

    • a non-2xx response
    • an HTML or otherwise unexpected Content-Type, judged from the response and not the metadata
    • an oversized body

    Each rejection gives a clear message telling the user to share the file as "anyone with the link". Consider reusing the limits and allowlist in fetch-remote-document.helper.ts.

  • Folder listing pages through every result, excludes trashed files, encodes the id, and turns HTTP errors into readable messages.

  • A missing API key fails fast with a configuration error.

  • Unit tests with a mocked fetch cover each case above.

Lingua principale
TypeScript
Stelle
30
Fork
10
Merge medio
2g 12h
PR unite (30g)
276

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Urigo/accounter-fullstack

Tutte le issue di Urigo/accounter-fullstack

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.