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

Open
#28 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active

Research direction

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.

Written by the indexing model from the issue text.

Description

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>.
Dominant language
TypeScript
Stars
2
Forks
1
Avg merge
6m
Merged PRs (30d)
27

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sumamakhan761/tryinstance

All issues in sumamakhan761/tryinstance

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.