Skip to content

Commit 8796617

Browse files
committed
fix: comprehensive security fix for Thumbnails component - only allow data:image/ URIs
- Restrict URL validation to only allow data:image/ URIs with proper base64 format - Remove support for HTTP/HTTPS URLs as backend openImage() only supports data URIs - Add regex validation for proper data URI format (data:image/[type];base64,) - Eliminates both XSS and URL redirect vulnerabilities by design - Maintains backward compatibility as codebase only uses data:image/ URIs
1 parent d75f864 commit 8796617

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

webview-ui/src/components/common/Thumbnails.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,19 @@ const Thumbnails = ({ images, style, setImages, onHeightChange }: ThumbnailsProp
3737
}
3838

3939
// Sanitize image URL to prevent XSS and malicious redirects
40+
// Only allow data:image/ URLs since the backend openImage function only supports base64 data URIs
4041
const sanitizeImageUrl = (url: string): string => {
4142
try {
42-
// Only allow data URLs (base64 images) and https URLs
43+
// Only allow data URLs (base64 images) - backend only supports these
4344
if (url.startsWith("data:image/")) {
44-
return url
45-
}
46-
47-
// For other URLs, validate they are safe
48-
const parsedUrl = new URL(url)
49-
if (parsedUrl.protocol === "https:" || parsedUrl.protocol === "http:") {
50-
return url
45+
// Additional validation: ensure it's a proper data URI format
46+
const dataUriRegex = /^data:image\/[a-zA-Z]+;base64,/
47+
if (dataUriRegex.test(url)) {
48+
return url
49+
}
5150
}
5251

53-
// Reject any other protocols (javascript:, file:, etc.)
52+
// Reject all other URLs (http, https, javascript, file, etc.)
5453
return ""
5554
} catch {
5655
// Invalid URL, return empty string

0 commit comments

Comments
 (0)