fix(bio-links): restrict bio link URLs to http/https schemes and prevent arbitrary iframe embeds

Đang mở
#28 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ó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
55/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, react, typescript
Lĩnh vực
backend, frontend, security

Hướng nghiên cứu

Start with the listed DTO and public bio components, then inspect sibling bio link DTOs and how parseMediaEmbed selects providers. Trace URL fields through validation and rendering, and check the existing tests for these paths. Done means bio link URLs accept only HTTP(S), and public media embeds render only for the approved providers.

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

Mô tả

backend bug ui web
Problem Description
  1. Stored XSS via javascript: URIs:
    In apps/api/src/bio-links/dto/upsert-bio-links.dto.ts, BioLinkInputDto only validates url and redirectUrl with @IsString(), without restricting the URL scheme to http: or https:.
    As a result, dangerous payloads such as javascript:... or data:... can be saved to the database and rendered directly into href attributes or window.open(...) calls on public bio pages (PublicLinkCard.tsx, PublicProductCard.tsx, PublicSocialButton.tsx), executing arbitrary JavaScript in visitors' browsers when clicked.

  2. Arbitrary <iframe> injection on public bio pages:
    In apps/web/components/bio-links/PublicMediaEmbed.tsx, parseMediaEmbed falls back to returning { type: ..., embedUrl: cleanUrl } for any URL that does not match YouTube, Spotify, or Instagram, and renders <iframe src={embedUrl}> directly. This allows arbitrary external URLs or javascript:/data: URIs to be embedded in public /l/[slug] pages.


Expected Behavior
  1. All URL fields on Bio-Links DTOs (url, redirectUrl, and any related social/product/media URLs) must validate that only http: and https: schemes are accepted.
  2. Public bio components (PublicLinkCard.tsx, PublicProductCard.tsx, PublicSocialButton.tsx) must sanitize/verify URLs before rendering href or calling window.open(...), rejecting non-HTTP(S) schemes.
  3. PublicMediaEmbed.tsx must only render <iframe> elements for approved embed providers/domains (YouTube, Spotify, Instagram) instead of falling back to arbitrary URLs.

Where to Look
  • apps/api/src/bio-links/dto/upsert-bio-links.dto.ts (BioLinkInputDto)
  • apps/web/components/bio-links/PublicLinkCard.tsx
  • apps/web/components/bio-links/PublicProductCard.tsx
  • apps/web/components/bio-links/PublicSocialButton.tsx
  • apps/web/components/bio-links/PublicMediaEmbed.tsx (parseMediaEmbed)

Solution / Implementation Guide
  1. Backend (apps/api/src/bio-links/dto/):

    • Replace bare @IsString() on url and redirectUrl in BioLinkInputDto (and any sibling bio-links DTOs for products, social buttons, or media embeds) with @IsUrl({ protocols: ['http', 'https'], require_protocol: true }).
  2. Frontend (apps/web/components/bio-links/):

    • Add a shared getSafeHttpUrl(url?: string | null): string | null helper that parses with new URL(...) and only returns the URL if protocol === 'http:' || protocol === 'https:'.
    • Use getSafeHttpUrl before passing URLs to href or window.open(...) in PublicLinkCard.tsx, PublicProductCard.tsx, and PublicSocialButton.tsx.
    • In PublicMediaEmbed.tsx, remove the arbitrary embedUrl: cleanUrl fallback for <iframe src={embedUrl}> so only whitelisted provider embeds (YouTube, Spotify, Instagram) render an <iframe>.
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.