@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 +6 -0
- package/package.json +1 -1
- package/src/sanitization.ts +16 -4
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/sanitization.ts
CHANGED
|
@@ -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
|
|
44
|
+
options: { allowStyleAttribute?: boolean; allowHyperlinks?: boolean } = {
|
|
45
|
+
allowStyleAttribute: false,
|
|
46
|
+
allowHyperlinks: false,
|
|
47
|
+
},
|
|
43
48
|
) => {
|
|
44
|
-
const { allowStyleAttribute } = options;
|
|
45
|
-
const ALLOWED_ATTR =
|
|
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, {
|
|
56
|
+
return DomPurify.sanitize(rawHTML, {
|
|
57
|
+
ALLOWED_TAGS: allowedTags,
|
|
58
|
+
ALLOWED_ATTR,
|
|
59
|
+
});
|
|
48
60
|
};
|
|
49
61
|
|
|
50
62
|
/**
|