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) && (