From 6ebc1fdf91e7b9eda4d6888852ec1d961270557c Mon Sep 17 00:00:00 2001 From: hannesrudolph Date: Mon, 16 Jun 2025 12:35:42 -0600 Subject: [PATCH] fix: address security review comments for message editing feature - Enhanced URL sanitization in Thumbnails component to prevent XSS and redirect attacks - Added comprehensive validation for data: URLs including dangerous patterns - Added length limit (5MB) for data URIs to prevent DoS - Fixed handleImageClick to use sanitized URL instead of original - Added explicit rejection of javascript:, vbscript:, and other dangerous protocols --- .../src/components/common/Thumbnails.tsx | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/webview-ui/src/components/common/Thumbnails.tsx b/webview-ui/src/components/common/Thumbnails.tsx index 9fdf99c57d..ca737be5c6 100644 --- a/webview-ui/src/components/common/Thumbnails.tsx +++ b/webview-ui/src/components/common/Thumbnails.tsx @@ -40,12 +40,36 @@ const Thumbnails = ({ images, style, setImages, onHeightChange }: ThumbnailsProp // Only allow data:image/ URLs since the backend openImage function only supports base64 data URIs const sanitizeImageUrl = (url: string): string => { try { + // Trim whitespace and convert to string to prevent injection + const trimmedUrl = String(url).trim() + + // Reject URLs with potentially dangerous protocols or patterns + const dangerousPatterns = [ + /^javascript:/i, + /^vbscript:/i, + /^data:text\/html/i, + /^data:application\/javascript/i, + /^data:.*script/i, + /