Skip to content

fix(security): sanitize project URL fields to prevent XSS via javascript: URIs#423

Merged
mohanadft merged 2 commits intomainfrom
fix/security-xss-url-sanitization
Apr 13, 2026
Merged

fix(security): sanitize project URL fields to prevent XSS via javascript: URIs#423
mohanadft merged 2 commits intomainfrom
fix/security-xss-url-sanitization

Conversation

@mohanadft
Copy link
Copy Markdown
Collaborator

@mohanadft mohanadft commented Apr 13, 2026

Summary

  • API route (/api/projects): strips any URL field whose protocol is not http: or https: before returning data to the client — defense-in-depth at the server layer
  • ProjectsNew component: adds a sanitizeUrl() helper that validates protocol before use; all href attributes derived from project data (websiteUrl, githubUrl, twitterUrl, linkedinUrl, instagramUrl, facebookUrl, youtubeUrl, telegramUrl, mastodonUrl, blueskyUrl, tiktokUrl, signalUrl, upscrolledUrl) now go through this check — unsafe URLs are suppressed entirely

Motivation

Project metadata is sourced from the external ProjectHub API. If an admin account on the hub were compromised, an attacker could inject javascript: or data: URIs into URL fields, which would be rendered as href attributes on this site. React + MUI + CSP mitigate the risk in practice, but explicit protocol validation closes the gap with no reliance on downstream defences.

Test plan

  • Browse /projects — all project cards and "Visit Site" links render as before for legitimate URLs
  • Open a project detail dialog — social media buttons render correctly
  • Verify build passes (pnpm build)

…ipt: URIs

Add URL protocol validation on both server and client to guard against
XSS injection through project metadata sourced from the ProjectHub API.

- API route: strip any URL field whose protocol is not http/https before
  returning data to the client (defense-in-depth)
- ProjectsNew component: sanitizeUrl() helper gates every href derived
  from project data; unsafe URLs are suppressed entirely
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Apr 13, 2026

Deploying website with  Cloudflare Pages  Cloudflare Pages

Latest commit: c75f1d1
Status: ✅  Deploy successful!
Preview URL: https://1cd80fd3.website-aun.pages.dev
Branch Preview URL: https://fix-security-xss-url-sanitiz.website-aun.pages.dev

View logs

@mohanadft mohanadft merged commit 15f768b into main Apr 13, 2026
5 checks passed
@mohanadft mohanadft deleted the fix/security-xss-url-sanitization branch April 13, 2026 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant