@instructure/ui-avatar 11.7.4-snapshot-136 → 11.7.4-snapshot-144

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,7 +3,12 @@
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
- ## [11.7.4-snapshot-136](https://github.com/instructure/instructure-ui/compare/v11.7.3...v11.7.4-snapshot-136) (2026-07-24)
6
+ ## [11.7.4-snapshot-144](https://github.com/instructure/instructure-ui/compare/v11.7.3...v11.7.4-snapshot-144) (2026-07-24)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **many:** do not allow javascript: and data: hrefs ([4a0ac03](https://github.com/instructure/instructure-ui/commit/4a0ac038c6a4102646e04d27c1c3251f97367822))
7
12
 
8
13
 
9
14
  ### Features
@@ -22,6 +22,9 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
+ import { safeHref } from '@instructure/ui-utils';
26
+ // Escape characters that could break out of a CSS single-quoted url() string.
27
+ const escapeCssUrl = value => value.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/[\r\n]/g, '');
25
28
  /**
26
29
  * ---
27
30
  * private: true
@@ -41,6 +44,8 @@ const generateStyle = (componentTheme, params) => {
41
44
  src,
42
45
  showBorder
43
46
  } = params;
47
+ const safeSrc = safeHref(src, 'img', 'src');
48
+ const backgroundImageValue = safeSrc ? `url('${escapeCssUrl(safeSrc)}')` : undefined;
44
49
 
45
50
  // TODO: this is a temporary solution and should be revised on component update
46
51
  // NOTE: this is needed due to design changes. The size of the component is calculated from "em" which means it is
@@ -187,7 +192,7 @@ const generateStyle = (componentTheme, params) => {
187
192
  ...sizeStyles[size],
188
193
  ...shapeStyles[shape],
189
194
  ...(loaded ? {
190
- backgroundImage: `url('${src}')`,
195
+ backgroundImage: backgroundImageValue,
191
196
  ...(showBorder !== 'always' && {
192
197
  border: 0
193
198
  }),
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ var _safeHref = require("@instructure/ui-utils/lib/safeHref.js");
7
8
  /*
8
9
  * The MIT License (MIT)
9
10
  *
@@ -28,6 +29,8 @@ exports.default = void 0;
28
29
  * SOFTWARE.
29
30
  */
30
31
 
32
+ // Escape characters that could break out of a CSS single-quoted url() string.
33
+ const escapeCssUrl = value => value.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/[\r\n]/g, '');
31
34
  /**
32
35
  * ---
33
36
  * private: true
@@ -47,6 +50,8 @@ const generateStyle = (componentTheme, params) => {
47
50
  src,
48
51
  showBorder
49
52
  } = params;
53
+ const safeSrc = (0, _safeHref.safeHref)(src, 'img', 'src');
54
+ const backgroundImageValue = safeSrc ? `url('${escapeCssUrl(safeSrc)}')` : undefined;
50
55
 
51
56
  // TODO: this is a temporary solution and should be revised on component update
52
57
  // NOTE: this is needed due to design changes. The size of the component is calculated from "em" which means it is
@@ -193,7 +198,7 @@ const generateStyle = (componentTheme, params) => {
193
198
  ...sizeStyles[size],
194
199
  ...shapeStyles[shape],
195
200
  ...(loaded ? {
196
- backgroundImage: `url('${src}')`,
201
+ backgroundImage: backgroundImageValue,
197
202
  ...(showBorder !== 'always' && {
198
203
  border: 0
199
204
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-avatar",
3
- "version": "11.7.4-snapshot-136",
3
+ "version": "11.7.4-snapshot-144",
4
4
  "description": "An image or letters that represents a user.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -15,20 +15,21 @@
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
17
  "@babel/runtime": "^7.29.7",
18
- "@instructure/emotion": "11.7.4-snapshot-136",
19
- "@instructure/shared-types": "11.7.4-snapshot-136",
20
- "@instructure/ui-react-utils": "11.7.4-snapshot-136",
21
- "@instructure/ui-icons": "11.7.4-snapshot-136",
22
- "@instructure/ui-themes": "11.7.4-snapshot-136",
23
- "@instructure/ui-view": "11.7.4-snapshot-136"
18
+ "@instructure/emotion": "11.7.4-snapshot-144",
19
+ "@instructure/shared-types": "11.7.4-snapshot-144",
20
+ "@instructure/ui-react-utils": "11.7.4-snapshot-144",
21
+ "@instructure/ui-themes": "11.7.4-snapshot-144",
22
+ "@instructure/ui-icons": "11.7.4-snapshot-144",
23
+ "@instructure/ui-utils": "11.7.4-snapshot-144",
24
+ "@instructure/ui-view": "11.7.4-snapshot-144"
24
25
  },
25
26
  "devDependencies": {
26
27
  "@testing-library/jest-dom": "^6.9.1",
27
28
  "@testing-library/react": "16.3.2",
28
29
  "vitest": "^4.1.9",
29
- "@instructure/ui-babel-preset": "11.7.4-snapshot-136",
30
- "@instructure/ui-axe-check": "11.7.4-snapshot-136",
31
- "@instructure/ui-color-utils": "11.7.4-snapshot-136"
30
+ "@instructure/ui-babel-preset": "11.7.4-snapshot-144",
31
+ "@instructure/ui-color-utils": "11.7.4-snapshot-144",
32
+ "@instructure/ui-axe-check": "11.7.4-snapshot-144"
32
33
  },
33
34
  "peerDependencies": {
34
35
  "react": ">=18 <=19"
@@ -23,8 +23,16 @@
23
23
  */
24
24
 
25
25
  import type { AvatarTheme } from '@instructure/shared-types'
26
+ import { safeHref } from '@instructure/ui-utils'
26
27
  import { AvatarProps, AvatarStyle } from './props.js'
27
28
 
29
+ // Escape characters that could break out of a CSS single-quoted url() string.
30
+ const escapeCssUrl = (value: string) =>
31
+ value
32
+ .replace(/\\/g, '\\\\')
33
+ .replace(/'/g, "\\'")
34
+ .replace(/[\r\n]/g, '')
35
+
28
36
  type StyleParams = {
29
37
  loaded: boolean
30
38
  size: AvatarProps['size']
@@ -51,6 +59,11 @@ const generateStyle = (
51
59
  const { loaded, size, color, hasInverseColor, shape, src, showBorder } =
52
60
  params
53
61
 
62
+ const safeSrc = safeHref(src, 'img', 'src')
63
+ const backgroundImageValue = safeSrc
64
+ ? `url('${escapeCssUrl(safeSrc)}')`
65
+ : undefined
66
+
54
67
  // TODO: this is a temporary solution and should be revised on component update
55
68
  // NOTE: this is needed due to design changes. The size of the component is calculated from "em" which means it is
56
69
  // tied to the fontSize. The font sizes changed for the icons, which meant that the container (component) size would've
@@ -209,7 +222,7 @@ const generateStyle = (
209
222
  ...shapeStyles[shape!],
210
223
  ...(loaded
211
224
  ? {
212
- backgroundImage: `url('${src}')`,
225
+ backgroundImage: backgroundImageValue,
213
226
  ...(showBorder !== 'always' && {
214
227
  border: 0
215
228
  }),
@@ -33,6 +33,7 @@
33
33
  },
34
34
  {
35
35
  "path": "../ui-icons/tsconfig.build.json"
36
- }
36
+ },
37
+ { "path": "../ui-utils/tsconfig.build.json" }
37
38
  ]
38
39
  }