@brightspace-ui/core 3.334.1 → 3.335.0

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/helpers/README.md CHANGED
@@ -275,6 +275,20 @@ requestIdleCallback((deadline) => {
275
275
  }, { timeout: 1000 });
276
276
  ```
277
277
 
278
+ ## Trusted Types
279
+
280
+ The Trusted Types module provides a polyfill for the browser's TrustedTypes API along with Trusted Type policies. These policies provide a `createHTML` method for creating TrustedHTML objects that can be passed to injection sinks like `innerHTML`.
281
+
282
+ ```js
283
+ import { markdownHtmlPolicy, safeHtmlPolicy } from '@brightspace-ui/core/helpers/trusted-types.js';
284
+
285
+ // filters HTML string and returns TrustedHTML
286
+ const result = safeHtmlPolicy.createHTML(html);
287
+
288
+ // filters HTML string for Markdown supported elements and returns TrustedHTML
289
+ const result = markdownHtmlPolicy.createHTML(html);
290
+ ```
291
+
278
292
  ## UniqueId
279
293
 
280
294
  A simple helper that returns a unique id.
@@ -0,0 +1,21 @@
1
+ import DOMPurify from 'dompurify';
2
+
3
+ if (typeof globalThis.trustedTypes === 'undefined') {
4
+ globalThis.trustedTypes = { createPolicy: (name, rules) => rules };
5
+ }
6
+
7
+ export const safeHtmlPolicy = globalThis.trustedTypes.createPolicy('safe-html', {
8
+ createHTML: (input) => DOMPurify.sanitize(input, {
9
+ TRUSTED_TYPES_POLICY: null
10
+ })
11
+ });
12
+
13
+ export const markdownHtmlPolicy = globalThis.trustedTypes.createPolicy('markdown-html', {
14
+ createHTML: (input) => DOMPurify.sanitize(input, {
15
+ ALLOWED_TAGS: ['a', 'blockquote', 'br', 'code', 'em', 'li', 'ol', 'p', 'pre', 'strong', 'ul'],
16
+ ALLOWED_ATTR: ['class', 'href', 'start', 'title'],
17
+ ALLOW_ARIA_ATTR: false,
18
+ ALLOW_DATA_ATTR: false,
19
+ TRUSTED_TYPES_POLICY: null
20
+ })
21
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "3.334.1",
3
+ "version": "3.335.0",
4
4
  "description": "A collection of accessible, free, open-source web components for building Brightspace applications",
5
5
  "type": "module",
6
6
  "repository": "https://github.com/BrightspaceUI/core.git",
@@ -76,6 +76,7 @@
76
76
  "@brightspace-ui/intl": "^3",
77
77
  "@brightspace-ui/lms-context-provider": "^1",
78
78
  "@open-wc/dedupe-mixin": "^2",
79
+ "dompurify": "^3.4.17",
79
80
  "ifrau": "^0.42",
80
81
  "lit": "^3",
81
82
  "prismjs": "^1"