Harden GoogleDriveProvider downloads and folder listing

Open
#4,921 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
56/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
api, backend

Research direction

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.

Written by the indexing model from the issue text.

Description

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.

Dominant language
TypeScript
Stars
30
Forks
10
Avg merge
2d 12h
Merged PRs (30d)
276

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Urigo/accounter-fullstack

All issues in Urigo/accounter-fullstack

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.