@knime/utils 1.9.1 → 1.9.2

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
@@ -1,5 +1,11 @@
1
1
  # @knime/utils
2
2
 
3
+ ## 1.9.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 6d57731: Add option to allow hyperlinks to the sanitization util.
8
+
3
9
  ## 1.9.1
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knime/utils",
3
- "version": "1.9.1",
3
+ "version": "1.9.2",
4
4
  "description": "Internal utility functions and constants shared across @knime packages.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,16 +35,28 @@ const ALLOWED_TAGS = [
35
35
  /**
36
36
  * Sanitizes Raw HTML and only allow specific tags to be used, as per OWASP standards.
37
37
  * @param rawHTML
38
+ * @param options.allowStyleAttribute - Allow the style attribute on elements
39
+ * @param options.allowHyperlinks - Allow anchor tags with href attribute
38
40
  * @returns sanitized html
39
41
  */
40
42
  const sanitizeHTML = (
41
43
  rawHTML: string,
42
- options: { allowStyleAttribute: boolean } = { allowStyleAttribute: false },
44
+ options: { allowStyleAttribute?: boolean; allowHyperlinks?: boolean } = {
45
+ allowStyleAttribute: false,
46
+ allowHyperlinks: false,
47
+ },
43
48
  ) => {
44
- const { allowStyleAttribute } = options;
45
- const ALLOWED_ATTR = allowStyleAttribute ? ["style"] : [];
49
+ const { allowStyleAttribute, allowHyperlinks } = options;
50
+ const ALLOWED_ATTR = [
51
+ ...(allowStyleAttribute ? ["style"] : []),
52
+ ...(allowHyperlinks ? ["href"] : []),
53
+ ];
54
+ const allowedTags = allowHyperlinks ? [...ALLOWED_TAGS, "a"] : ALLOWED_TAGS;
46
55
 
47
- return DomPurify.sanitize(rawHTML, { ALLOWED_TAGS, ALLOWED_ATTR });
56
+ return DomPurify.sanitize(rawHTML, {
57
+ ALLOWED_TAGS: allowedTags,
58
+ ALLOWED_ATTR,
59
+ });
48
60
  };
49
61
 
50
62
  /**