Rate-limit lh4.googleusercontent.com full-tier image fetches - #25
Merged
Conversation
Shared by PDF export, bulk download, and the local OCR/phash pilot - previously unguarded (GOOGLE_DRIVE_RATE_LIMITER only covers the real Drive API, a different Google domain this path never touches).
6 tasks
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
Investigating throughput for the local OCR/phash pilot (docs/features/printing-tags.md Stage 8) surfaced a real gap: the image CDN Worker's
fulltier is a pure passthrough tohttps://lh4.googleusercontent.com/d/{id}...(Google's image-serving CDN, not the Drive API) with no rate limiting anywhere in the codebase. This path is shared by three callers:frontend/src/features/pdf/pdfImage.ts(PDF export)frontend/src/features/download/downloadImages.ts(bulk image download)The existing
GOOGLE_DRIVE_RATE_LIMITERbinding doesn't cover this - it only guardsGoogleDriveService.executeCall, the real Drive API (a different Google domain entirely). A sustained high-volume caller hammering the unguardedlh4.googleusercontent.comendpoint risks degrading it for live PDF export/download traffic too, not just whatever's generating the load.Changes
IMAGE_FULL_TIER_RATE_LIMITERCloudflare rate-limiting binding (wrangler.toml, 3 req/s sustained - conservative since there's no published Google quota for this specific endpoint to size against; comfortably serves normal PDF/bulk-download bursts).src/utils.ts:fetchWithRateLimithelper - mirrorsGoogleDriveService.executeCall's existing check-then-backoff-then-retry pattern (checked-in-limit, delay-and-retry on denial, defensive retry on an upstream 429), but as a standalone primitive since this call site is a plain unauthenticated GET to a different Google domain thanexecuteCallis built around (POST, OAuth, Drive API).src/handler/image.ts: thefulltier now routes throughfetchWithRateLimitinstead of a barefetch().worker-configuration.d.ts: added the new binding's type.Test plan
npx vitest run- 53/53 passed (including 3 new tests for the retry/backoff/exhaustion behavior intests/utils.test.ts, and 1 new handler-level test confirming thefulltier actually routes through the limiter)full-tier requests) pass unchanged - no regression to normal burst usagenpx tsc --noEmit- no new errors (pre-existingcloudflare:test/globaltype-resolution gaps in the vitest-pool-workers test environment, unrelated to this change)Lands independently of the pilot's own branch - deploy ahead of any full-catalog pilot run so live traffic is protected regardless of pilot timing.
🤖 Generated with Claude Code
https://claude.ai/code/session_016i9S7LQsCL3FGaih3ZTRBJ