File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { getAssetPath } from './assetUtils';
33const DEFAULT_AVATAR = getAssetPath ( '/static/avatars/demo1.svg' ) ;
44
55const HTTP_URL_REGEX = / ^ ( h t t p s ? : \/ \/ ) [ ^ \s ] + $ / i;
6- const DATA_URI_REGEX = / ^ d a t a : i m a g e \/ ( p n g | j p e g | j p g | g i f | w e b p | s v g \+ x m l ) ; b a s e 6 4 , [ A - Z a - z 0 - 9 + / = ] + $ / i;
6+ const DATA_URI_REGEX = / ^ d a t a : i m a g e \/ ( p n g | j p e g | j p g | g i f | w e b p ) ; b a s e 6 4 , [ A - Z a - z 0 - 9 + / = ] + $ / i;
77
88export 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 ( / \. ( s v g | s v g z ) ( \? | # | $ ) / 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
You can’t perform that action at this time.
0 commit comments