Skip to content

Commit a300882

Browse files
author
jaapbakker88
authored
Merge branch 'master' into fix/CRS-288-fallback-initials-preview
2 parents e7221ff + 2383096 commit a300882

File tree

5 files changed

+41
-7
lines changed

5 files changed

+41
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"pretty-bytes": "^5.4.1",
3535
"prop-types": "^15.7.2",
3636
"react-fast-compare": "^3.2.0",
37-
"react-file-utils": "0.3.16",
37+
"react-file-utils": "0.3.17",
3838
"react-images": "^1.1.7",
3939
"react-is": "^16.13.1",
4040
"react-markdown": "^4.3.1",

src/components/Gallery/Image.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React from 'react';
33
import PropTypes from 'prop-types';
44

55
import ModalWrapper from './ModalWrapper';
6+
import { sanitizeUrl } from '@braintree/sanitize-url';
67

78
/**
89
* Image - Small wrapper around an image tag, supports thumbnails
@@ -32,13 +33,14 @@ class Image extends React.PureComponent {
3233

3334
render() {
3435
const { image_url, thumb_url, fallback } = this.props;
35-
const formattedArray = [{ src: image_url || thumb_url }];
36+
const imageSrc = sanitizeUrl(image_url || thumb_url);
37+
const formattedArray = [{ src: imageSrc }];
3638
return (
3739
<React.Fragment>
3840
<img
3941
className="str-chat__message-attachment--img"
4042
onClick={this.toggleModal}
41-
src={thumb_url || image_url}
43+
src={imageSrc}
4244
alt={fallback}
4345
data-testid="image-test"
4446
/>

src/components/Gallery/__tests__/Image.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,37 @@ describe('Image', () => {
1717
expect(tree).toMatchSnapshot();
1818
});
1919

20+
describe('it should prevent unsafe image uri protocols in the rendered image src', () => {
21+
it('should prevent javascript protocol in image src', () => {
22+
// eslint-disable-next-line no-script-url
23+
const xssJavascriptUri = 'javascript:alert("p0wn3d")';
24+
const { getByTestId } = render(<Image image_url={xssJavascriptUri} />);
25+
expect(getByTestId('image-test')).not.toHaveAttribute(
26+
'src',
27+
xssJavascriptUri,
28+
);
29+
});
30+
it('should prevent javascript protocol in thumbnail src', () => {
31+
// eslint-disable-next-line no-script-url
32+
const xssJavascriptUri = 'javascript:alert("p0wn3d")';
33+
const { getByTestId } = render(<Image thumb_url={xssJavascriptUri} />);
34+
expect(getByTestId('image-test')).not.toHaveAttribute(
35+
'src',
36+
xssJavascriptUri,
37+
);
38+
});
39+
it('should prevent dataUris in image src', () => {
40+
const xssDataUri = 'data:image/svg+xml;base64,DANGEROUSENCODEDSVG';
41+
const { getByTestId } = render(<Image image_url={xssDataUri} />);
42+
expect(getByTestId('image-test')).not.toHaveAttribute('src', xssDataUri);
43+
});
44+
it('should prevent dataUris in thumb src', () => {
45+
const xssDataUri = 'data:image/svg+xml;base64,DANGEROUSENCODEDSVG';
46+
const { getByTestId } = render(<Image thumb_url={xssDataUri} />);
47+
expect(getByTestId('image-test')).not.toHaveAttribute('src', xssDataUri);
48+
});
49+
});
50+
2051
it('should open modal on image click', async () => {
2152
jest.spyOn(console, 'warn').mockImplementation(() => null);
2253
const { getByTestId, getByTitle } = render(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ exports[`Image should render component with default props 1`] = `
55
className="str-chat__message-attachment--img"
66
data-testid="image-test"
77
onClick={[Function]}
8+
src="about:blank"
89
/>
910
`;

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9555,10 +9555,10 @@ react-file-icon@^0.2.0:
95559555
react-dom "^16.2.0"
95569556
tinycolor2 "^1.4.1"
95579557

9558-
9559-
version "0.3.16"
9560-
resolved "https://registry.yarnpkg.com/react-file-utils/-/react-file-utils-0.3.16.tgz#de646e64ad65b5b75833440f6d8f9119ddf5d60d"
9561-
integrity sha512-21z3AWxvgtW06ZOvVe4olPdz1dRnfPm0s/a/Era7vzGrMZrSarlGiO9rIfChtotyJwrlPF8UQMFiOp8P42gNtA==
9558+
9559+
version "0.3.17"
9560+
resolved "https://registry.yarnpkg.com/react-file-utils/-/react-file-utils-0.3.17.tgz#99e9a0583d7e0c362565068ffa09a7ea112754ba"
9561+
integrity sha512-8EFgRZJkIC8w48SLOtsJY3RHkUFtBebl9iyOM6B5qcz74cn7rvWxavXDUc22P7Ibs4xuNgYEfBt0OMdOLjKP7A==
95629562
dependencies:
95639563
"@fortawesome/fontawesome-svg-core" "^1.2.13"
95649564
"@fortawesome/free-regular-svg-icons" "^5.7.0"

0 commit comments

Comments
 (0)