Skip to content

Commit a205dbe

Browse files
committed
Merge branch 'new_demo_app' of github.com:browserstack/test-selection-demo-app-browserstack into new_demo_app
2 parents 5dd6e62 + 676aab8 commit a205dbe

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/lib/avatar.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getAssetPath } from './assetUtils';
33
const DEFAULT_AVATAR = getAssetPath('/static/avatars/demo1.svg');
44

55
const HTTP_URL_REGEX = /^(https?:\/\/)[^\s]+$/i;
6-
const DATA_URI_REGEX = /^data:image\/(png|jpeg|jpg|gif|webp|svg\+xml);base64,[A-Za-z0-9+/=]+$/i;
6+
const DATA_URI_REGEX = /^data:image\/(png|jpeg|jpg|gif|webp);base64,[A-Za-z0-9+/=]+$/i;
77

88
export const sanitizeAvatarUrl = (avatar?: string | null): string => {
99
if (!avatar || typeof avatar !== 'string') {
@@ -12,10 +12,23 @@ export const sanitizeAvatarUrl = (avatar?: string | null): string => {
1212
const trimmed = avatar.trim();
1313

1414
if (trimmed.startsWith('/')) {
15+
// Prevent SVGs by extension (avoid even local .svg paths if user-controllable)
16+
if (trimmed.endsWith('.svg')) {
17+
return DEFAULT_AVATAR;
18+
}
1519
return trimmed;
1620
}
1721

18-
if (HTTP_URL_REGEX.test(trimmed) || DATA_URI_REGEX.test(trimmed)) {
22+
// Only allow HTTP(s) URLs if they do NOT end in .svg
23+
if (HTTP_URL_REGEX.test(trimmed)) {
24+
if (/\.(svg|svgz)(\?|#|$)/i.test(trimmed)) {
25+
return DEFAULT_AVATAR;
26+
}
27+
return trimmed;
28+
}
29+
30+
// Allow data URIs for accepted raster formats only (.svg is blocked in DATA_URI_REGEX)
31+
if (DATA_URI_REGEX.test(trimmed)) {
1932
return trimmed;
2033
}
2134

0 commit comments

Comments
 (0)