fix(upload): key R2 upload folder by immutable companyId instead of mutable companyName

Đang mở Phù hợp với người mới
#60 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

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

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
82/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ệ
cloud, typescript
Lĩnh vực
backend, cloud

Hướng nghiên cứu

Đọc apps/api/src/upload/upload.service.ts, đặc biệt là uploadFile quanh dòng 128-135, và theo dõi cách tạo tiền tố khóa R2. Thay tiền tố dựa trên tên công ty bằng phương án dự phòng dùng ID công ty hoặc ID người dùng được mô tả trong issue, đồng thời xóa companyName khỏi quá trình tạo khóa. Hoàn tất khi các lượt tải lên mới dùng tiền tố bất biến và các URL đã lưu hiện có không bị ảnh hưởng.

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

Mô tả

backend good first issue
Problem Description

In apps/api/src/upload/upload.service.ts (uploadFile, lines 128-135), the R2 object path prefix companySegment is derived from sanitizeSegment(userCompany.name) or from the client-supplied companyName when userCompany is null.

This creates three issues at 1k-10k+ multi-tenant scale:

  1. Prefix collisions: Two different companies whose names sanitize to the same slug (e.g., "Acme Co" and "Acme! Co") write into the same R2 folder prefix.
  2. Client-supplied folder spoofing: A user with userCompany === null can pass another company's name in companyName and write files into that tenant's R2 folder.
  3. Mutable path: Renaming a company changes its future upload folder prefix.

Expected Behavior
  1. New uploads must always be scoped under an immutable, collision-free folder prefix (userCompany.id, or user-${userId} when the user has no company).
  2. Client-supplied companyName must be ignored for R2 key generation.
  3. Existing uploaded file URLs already stored in the database continue to resolve normally.

Where to Look
  • apps/api/src/upload/upload.service.ts (uploadFile, lines 128-135)

Solution / Implementation Guide
  1. In apps/api/src/upload/upload.service.ts, replace the companySegment derivation in uploadFile with:
    const companySegment = userCompany?.id
      ? sanitizeSegment(userCompany.id)
      : `user-${sanitizeSegment(userId)}`;
    
  2. Remove usage of the client-supplied companyName parameter for constructing the R2 storage key.
Ngôn ngữ chính
TypeScript
Star
2
Fork
1
Merge trung bình
6 phút
Pull request đã merge (30 ngày)
27

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

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 sumamakhan761/tryinstance

Tất cả issue của sumamakhan761/tryinstance

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.