From 0f2313d574bae153725309e2ffbd234517f485fe Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 10 Jan 2026 20:15:38 +0000 Subject: [PATCH 1/2] Fix XSS vulnerability in URL handling Add URL sanitization utilities to prevent XSS attacks via javascript: protocol URLs. Apply sanitization to all database-sourced URLs before use in href attributes and window.open() calls. - Add sanitizeUrl() and safeOpenUrl() utilities in lib/utils.ts - Fix IntegrationDetailModal.tsx URL handling - Fix IntegrationsMarketplace.tsx URL handling - Fix PDFViewer.tsx URL handling --- src/components/PDFViewer.tsx | 15 +++-- .../admin/IntegrationDetailModal.tsx | 37 +++++------- src/lib/utils.ts | 57 +++++++++++++++++++ src/pages/admin/IntegrationsMarketplace.tsx | 5 +- 4 files changed, 84 insertions(+), 30 deletions(-) diff --git a/src/components/PDFViewer.tsx b/src/components/PDFViewer.tsx index 250bc080..afafdc96 100644 --- a/src/components/PDFViewer.tsx +++ b/src/components/PDFViewer.tsx @@ -14,7 +14,7 @@ import { ChevronLeft, ChevronRight } from 'lucide-react'; -import { cn } from '@/lib/utils'; +import { cn, sanitizeUrl, safeOpenUrl } from '@/lib/utils'; // Configure PDF.js worker from CDN pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`; @@ -65,17 +65,22 @@ export function PDFViewer({ url, title, compact = false }: PDFViewerProps) { }; const handleDownload = () => { + const safeUrl = sanitizeUrl(url); + if (!safeUrl) return; const link = document.createElement('a'); - link.href = url; + link.href = safeUrl; link.download = title || 'drawing.pdf'; link.click(); }; const handleOpenExternal = () => { - window.open(url, '_blank'); + safeOpenUrl(url); }; - if (!url) { + // Validate URL to prevent XSS + const safeFileUrl = sanitizeUrl(url); + + if (!url || !safeFileUrl) { return (
@@ -218,7 +223,7 @@ export function PDFViewer({ url, title, compact = false }: PDFViewerProps) { {!error && (
by {integration.provider_name} - {integration.provider_url && ( + {sanitizeUrl(integration.provider_url) && ( {integration.pricing_description}

- {integration.pricing_url && ( + {sanitizeUrl(integration.pricing_url) && (
- {integration.documentation_url && ( + {sanitizeUrl(integration.documentation_url) && ( )} - {integration.github_repo_url && ( + {sanitizeUrl(integration.github_repo_url) && ( )} - {integration.demo_video_url && ( + {sanitizeUrl(integration.demo_video_url) && (
- {integration.github_repo_url && ( + {sanitizeUrl(integration.github_repo_url) && (