cozy-sharing 4.1.2 → 4.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [4.1.3](https://github.com/cozy/cozy-libs/compare/cozy-sharing@4.1.2...cozy-sharing@4.1.3) (2022-02-21)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **sharing:** Escape public name in public cozy2cozy view ([b5af978](https://github.com/cozy/cozy-libs/commit/b5af978e6f349819b8f76e097f328a87a6c18912))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [4.1.2](https://github.com/cozy/cozy-libs/compare/cozy-sharing@4.1.1...cozy-sharing@4.1.2) (2022-02-18)
7
18
 
8
19
 
@@ -29,19 +29,21 @@ var PublicBannerCozyToCozyContent = function PublicBannerCozyToCozyContent(_ref)
29
29
  var knowMore = /*#__PURE__*/React.createElement("a", {
30
30
  href: "https://cozy.io",
31
31
  target: "_blank",
32
- className: 'u-link',
32
+ className: "u-link",
33
33
  rel: "noopener noreferrer"
34
34
  }, t('Share.banner.know_more'));
35
35
  var withAvatar = snarkdown(t('Share.banner.shared_from', {
36
36
  name: name,
37
37
  image: avatarURL
38
38
  }));
39
+ var beginning = withAvatar.split('<img src');
40
+ var translated = beginning[1].split('alt="avatar">');
39
41
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
40
- className: styles['bannermarkdown'],
41
- dangerouslySetInnerHTML: {
42
- __html: withAvatar
43
- }
44
- }), /*#__PURE__*/React.createElement("span", null, ' ', text, " ", knowMore));
42
+ className: styles['bannermarkdown']
43
+ }, beginning[0], /*#__PURE__*/React.createElement("img", {
44
+ src: avatarURL,
45
+ alt: "avatar"
46
+ }), translated[1]), /*#__PURE__*/React.createElement("span", null, ' ', text, " ", knowMore));
45
47
  };
46
48
 
47
49
  PublicBannerCozyToCozyContent.propTypes = {
@@ -0,0 +1,47 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import { SharingBannerCozyToCozy } from './PublicBanner';
4
+ import { useI18n } from 'cozy-ui/transpiled/react/I18n';
5
+ import { useClient } from 'cozy-client';
6
+ jest.mock('cozy-ui/transpiled/react/I18n');
7
+ jest.mock('cozy-client');
8
+ describe('PublicBanner', function () {
9
+ beforeEach(function () {
10
+ useClient.mockReturnValue({
11
+ options: {
12
+ uri: 'http://cozy.localhost:8080'
13
+ }
14
+ });
15
+ });
16
+ it('should not add dangerous html', function () {
17
+ // Given
18
+ useI18n.mockReturnValue({
19
+ t: function t(localeToTranslate, options) {
20
+ if (localeToTranslate === 'Share.banner.shared_from') {
21
+ return "Shared from ![avatar](".concat(options.image, ") ").concat(options.name, "'s cozy.");
22
+ }
23
+
24
+ return localeToTranslate;
25
+ }
26
+ });
27
+ var publicName = '[Click me!](https://evil.com)';
28
+ var sharing = {
29
+ attributes: {
30
+ members: [{
31
+ public_name: publicName
32
+ }]
33
+ }
34
+ }; // When
35
+
36
+ var _render = render( /*#__PURE__*/React.createElement(SharingBannerCozyToCozy, {
37
+ sharing: sharing,
38
+ isSharingShortcutCreated: true,
39
+ discoveryLink: 'discoveryLink',
40
+ onClose: function onClose() {}
41
+ })),
42
+ container = _render.container; // Then
43
+
44
+
45
+ expect(container.querySelector('.bannermarkdown').innerHTML).toEqual("Shared from <img src=\"http://cozy.localhost:8080/public/avatar?fallback=initials\" alt=\"avatar\"> &lt;a href=\"https://evil.com\"&gt;Click me!&lt;/a&gt;'s cozy.");
46
+ });
47
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-sharing",
3
- "version": "4.1.2",
3
+ "version": "4.1.3",
4
4
  "description": "Provides sharing login for React applications.",
5
5
  "main": "dist/index.js",
6
6
  "author": "Cozy",
@@ -61,5 +61,5 @@
61
61
  "sideEffects": [
62
62
  "*.css"
63
63
  ],
64
- "gitHead": "3bfcea11a7a0d354b5feabc3d4a2655345eee2ee"
64
+ "gitHead": "d248d58ef7828f260799b3dfce1451ebb40ae994"
65
65
  }
@@ -30,24 +30,28 @@ const PublicBannerCozyToCozyContent = ({
30
30
  <a
31
31
  href="https://cozy.io"
32
32
  target="_blank"
33
- className={'u-link'}
33
+ className="u-link"
34
34
  rel="noopener noreferrer"
35
35
  >
36
36
  {t('Share.banner.know_more')}
37
37
  </a>
38
38
  )
39
+
39
40
  const withAvatar = snarkdown(
40
41
  t('Share.banner.shared_from', {
41
42
  name: name,
42
43
  image: avatarURL
43
44
  })
44
45
  )
46
+ const beginning = withAvatar.split('<img src')
47
+ const translated = beginning[1].split('alt="avatar">')
45
48
  return (
46
49
  <>
47
- <span
48
- className={styles['bannermarkdown']}
49
- dangerouslySetInnerHTML={{ __html: withAvatar }}
50
- />
50
+ <span className={styles['bannermarkdown']}>
51
+ {beginning[0]}
52
+ <img src={avatarURL} alt="avatar" />
53
+ {translated[1]}
54
+ </span>
51
55
  <span>
52
56
  {' '}
53
57
  {text} {knowMore}
@@ -0,0 +1,45 @@
1
+ import React from 'react'
2
+ import { render } from '@testing-library/react'
3
+ import { SharingBannerCozyToCozy } from './PublicBanner'
4
+ import { useI18n } from 'cozy-ui/transpiled/react/I18n'
5
+ import { useClient } from 'cozy-client'
6
+
7
+ jest.mock('cozy-ui/transpiled/react/I18n')
8
+ jest.mock('cozy-client')
9
+
10
+ describe('PublicBanner', () => {
11
+ beforeEach(() => {
12
+ useClient.mockReturnValue({
13
+ options: { uri: 'http://cozy.localhost:8080' }
14
+ })
15
+ })
16
+
17
+ it('should not add dangerous html', () => {
18
+ // Given
19
+ useI18n.mockReturnValue({
20
+ t: (localeToTranslate, options) => {
21
+ if (localeToTranslate === 'Share.banner.shared_from') {
22
+ return `Shared from ![avatar](${options.image}) ${options.name}'s cozy.`
23
+ }
24
+ return localeToTranslate
25
+ }
26
+ })
27
+ const publicName = '[Click me!](https://evil.com)'
28
+ const sharing = { attributes: { members: [{ public_name: publicName }] } }
29
+
30
+ // When
31
+ const { container } = render(
32
+ <SharingBannerCozyToCozy
33
+ sharing={sharing}
34
+ isSharingShortcutCreated={true}
35
+ discoveryLink={'discoveryLink'}
36
+ onClose={() => {}}
37
+ />
38
+ )
39
+
40
+ // Then
41
+ expect(container.querySelector('.bannermarkdown').innerHTML).toEqual(
42
+ `Shared from <img src="http://cozy.localhost:8080/public/avatar?fallback=initials" alt="avatar"> &lt;a href="https://evil.com"&gt;Click me!&lt;/a&gt;'s cozy.`
43
+ )
44
+ })
45
+ })