Skip to content

Commit 1c5e640

Browse files
fix(Attachment): sanitization of image sources (#1953)
1 parent 330b622 commit 1c5e640

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/components/Attachment/Attachment.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useMemo } from 'react';
2-
import { sanitizeUrl } from '@braintree/sanitize-url';
32
import type { ReactPlayerProps } from 'react-player';
43
import type { Attachment as StreamAttachment } from 'stream-chat';
54

@@ -103,13 +102,9 @@ const renderGroupedAttachments = <
103102
attachments,
104103
...rest
105104
}: AttachmentProps<StreamChatGenerics>): GroupedRenderedAttachment => {
106-
const uploadedImages: StreamAttachment<StreamChatGenerics>[] = attachments
107-
.filter((attachment) => isUploadedImage(attachment))
108-
.map((attachment) => ({
109-
...attachment,
110-
image_url: sanitizeUrl(attachment.image_url),
111-
thumb_url: sanitizeUrl(attachment.thumb_url),
112-
}));
105+
const uploadedImages: StreamAttachment<StreamChatGenerics>[] = attachments.filter((attachment) =>
106+
isUploadedImage(attachment),
107+
);
113108

114109
const containers = attachments
115110
.filter((attachment) => !isUploadedImage(attachment))

src/components/Gallery/Gallery.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { CSSProperties, MutableRefObject, useState } from 'react';
2+
import { sanitizeUrl } from '@braintree/sanitize-url';
23
import clsx from 'clsx';
34

45
import { Modal } from '../Modal';
@@ -81,7 +82,7 @@ const UnMemoizedGallery = <
8182
>
8283
<img
8384
alt='User uploaded content'
84-
src={image.previewUrl || image.image_url || image.thumb_url}
85+
src={sanitizeUrl(image.previewUrl || image.image_url || image.thumb_url)}
8586
style={image.style}
8687
{...(innerRefs?.current && { ref: (r) => (innerRefs.current[i] = r) })}
8788
/>

src/components/Gallery/__tests__/__snapshots__/Gallery.test.js.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ exports[`Gallery should render component with 3 images 1`] = `
1111
>
1212
<img
1313
alt="User uploaded content"
14+
src="about:blank"
1415
/>
1516
</button>
1617
<button
@@ -20,6 +21,7 @@ exports[`Gallery should render component with 3 images 1`] = `
2021
>
2122
<img
2223
alt="User uploaded content"
24+
src="about:blank"
2325
/>
2426
</button>
2527
<button
@@ -29,6 +31,7 @@ exports[`Gallery should render component with 3 images 1`] = `
2931
>
3032
<img
3133
alt="User uploaded content"
34+
src="about:blank"
3235
/>
3336
</button>
3437
</div>
@@ -45,6 +48,7 @@ exports[`Gallery should render component with 4 images 1`] = `
4548
>
4649
<img
4750
alt="User uploaded content"
51+
src="about:blank"
4852
/>
4953
</button>
5054
<button
@@ -54,6 +58,7 @@ exports[`Gallery should render component with 4 images 1`] = `
5458
>
5559
<img
5660
alt="User uploaded content"
61+
src="about:blank"
5762
/>
5863
</button>
5964
<button
@@ -63,6 +68,7 @@ exports[`Gallery should render component with 4 images 1`] = `
6368
>
6469
<img
6570
alt="User uploaded content"
71+
src="about:blank"
6672
/>
6773
</button>
6874
<button
@@ -72,6 +78,7 @@ exports[`Gallery should render component with 4 images 1`] = `
7278
>
7379
<img
7480
alt="User uploaded content"
81+
src="about:blank"
7582
/>
7683
</button>
7784
</div>
@@ -88,6 +95,7 @@ exports[`Gallery should render component with 5 images 1`] = `
8895
>
8996
<img
9097
alt="User uploaded content"
98+
src="about:blank"
9199
/>
92100
</button>
93101
<button
@@ -97,6 +105,7 @@ exports[`Gallery should render component with 5 images 1`] = `
97105
>
98106
<img
99107
alt="User uploaded content"
108+
src="about:blank"
100109
/>
101110
</button>
102111
<button
@@ -106,6 +115,7 @@ exports[`Gallery should render component with 5 images 1`] = `
106115
>
107116
<img
108117
alt="User uploaded content"
118+
src="about:blank"
109119
/>
110120
</button>
111121
<button
@@ -136,6 +146,7 @@ exports[`Gallery should render component with default props 1`] = `
136146
>
137147
<img
138148
alt="User uploaded content"
149+
src="about:blank"
139150
/>
140151
</button>
141152
<button
@@ -145,6 +156,7 @@ exports[`Gallery should render component with default props 1`] = `
145156
>
146157
<img
147158
alt="User uploaded content"
159+
src="about:blank"
148160
/>
149161
</button>
150162
</div>

0 commit comments

Comments
 (0)