Harden client-warm cache writes against forged card and poster images

Đang mở
#3 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
nextjs, typescript
Lĩnh vực
api, backend, security

Hướng nghiên cứu

Start at app/api/cache-image/route.ts, then read components/WarmOnView.tsx to see how warm writes are triggered and lib/og/pngCache.ts for the cache key and expected card/poster dimensions. Check scripts/warm.mjs because it currently treats locally warmed handles as final, which affects how poisoned entries survive. Done means the route rejects unsigned/expired writes, invalid PNG bytes and wrong dimensions, enforces a documented write limit, and has tests covering unsigned, signed, bad bytes, wrong dimensions and the limit.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug help wanted security

Summary

POST /api/cache-image stores client-supplied bytes in R2 under a cache key built from the query string. It does not authenticate the caller, verify that the bytes are a PNG, or rate-limit writes. A third party can seed a valid-looking handle or pair with arbitrary image bytes; the card and poster routes will serve those bytes until the entry is replaced or expires.

This is a cache-poisoning and storage-abuse path, not a cosmetic issue.

Evidence

  • app/api/cache-image/route.ts:10-37 accepts kind, login, a and b; it checks only the login shape and a 200 KB to 4 MB size before writing to GITONE_PNGS.
  • components/WarmOnView.tsx:51-55 makes the same route reachable from any public profile page.
  • lib/og/pngCache.ts:80-86 serves the stored object directly as image/png.
  • scripts/warm.mjs:139-142 treats a handle as warmed once it is in local state, so a poisoned object can survive later warmer runs.

Expected behavior

  • A warm write must prove it came from the app. Use a short-lived HMAC over kind, the exact key, and an expiry, generated by the page or server and checked by the route.
  • Reject bytes that are not a valid PNG. Reject dimensions that do not match the card or poster contract.
  • Add a per-IP or global write budget and a structured log line for rejected writes.
  • Keep reads public; only writes need the token.

Scope

  • app/api/cache-image/route.ts
  • components/WarmOnView.tsx
  • lib/og/pngCache.ts for the expected dimensions / key helpers
  • tests for the route

Acceptance

  • Unsigned or expired warm requests return 401/403.
  • A correctly signed request still stores and serves the image.
  • A file with a bad PNG header or wrong dimensions returns 400 and writes nothing.
  • Repeated writes are bounded by a documented limit.
  • Tests cover unsigned, signed, bad bytes, wrong dimensions and the limit.
Ngôn ngữ chính
TypeScript
Star
7
Fork
0
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của LangerSword/gitone

Tất cả issue của LangerSword/gitone

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.