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

Aperta
#28 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
nextjs, react, typescript

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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>.
Lingua principale
TypeScript
Stelle
2
Fork
1
Merge medio
6m
PR unite (30g)
27

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di sumamakhan761/tryinstance

Tutte le issue di sumamakhan761/tryinstance

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.