@nocobase/utils 2.3.0-beta.2 → 2.3.0-beta.20

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/lib/client.d.ts CHANGED
@@ -29,6 +29,7 @@ export * from './ses';
29
29
  export * from './i18n';
30
30
  export * from './isPortalInBody';
31
31
  export * from './parseHTML';
32
+ export * from './sanitize-rich-text-html';
32
33
  export * from './uid';
33
34
  export * from './url';
34
35
  export * from './transformMultiColumnToSingleColumn';
package/lib/client.js CHANGED
@@ -67,6 +67,7 @@ __reExport(client_exports, require("./ses"), module.exports);
67
67
  __reExport(client_exports, require("./i18n"), module.exports);
68
68
  __reExport(client_exports, require("./isPortalInBody"), module.exports);
69
69
  __reExport(client_exports, require("./parseHTML"), module.exports);
70
+ __reExport(client_exports, require("./sanitize-rich-text-html"), module.exports);
70
71
  __reExport(client_exports, require("./uid"), module.exports);
71
72
  __reExport(client_exports, require("./url"), module.exports);
72
73
  __reExport(client_exports, require("./transformMultiColumnToSingleColumn"), module.exports);
@@ -100,6 +101,7 @@ __reExport(client_exports, require("./liquidjs"), module.exports);
100
101
  ...require("./i18n"),
101
102
  ...require("./isPortalInBody"),
102
103
  ...require("./parseHTML"),
104
+ ...require("./sanitize-rich-text-html"),
103
105
  ...require("./uid"),
104
106
  ...require("./url"),
105
107
  ...require("./transformMultiColumnToSingleColumn"),
package/lib/index.d.ts CHANGED
@@ -46,6 +46,7 @@ export * from './url';
46
46
  export * from './variable-usage';
47
47
  export * from './wrap-middleware';
48
48
  export * from './run-sql';
49
+ export * from './sanitize-rich-text-html';
49
50
  export * from './liquidjs';
50
51
  export * from './server-request';
51
52
  export * from './storage-path';
package/lib/index.js CHANGED
@@ -82,6 +82,7 @@ __reExport(src_exports, require("./url"), module.exports);
82
82
  __reExport(src_exports, require("./variable-usage"), module.exports);
83
83
  __reExport(src_exports, require("./wrap-middleware"), module.exports);
84
84
  __reExport(src_exports, require("./run-sql"), module.exports);
85
+ __reExport(src_exports, require("./sanitize-rich-text-html"), module.exports);
85
86
  __reExport(src_exports, require("./liquidjs"), module.exports);
86
87
  __reExport(src_exports, require("./server-request"), module.exports);
87
88
  __reExport(src_exports, require("./storage-path"), module.exports);
@@ -127,6 +128,7 @@ __reExport(src_exports, require("./storage-path"), module.exports);
127
128
  ...require("./variable-usage"),
128
129
  ...require("./wrap-middleware"),
129
130
  ...require("./run-sql"),
131
+ ...require("./sanitize-rich-text-html"),
130
132
  ...require("./liquidjs"),
131
133
  ...require("./server-request"),
132
134
  ...require("./storage-path")
@@ -0,0 +1,9 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ export declare function sanitizeRichTextHtml(value: string): any;
@@ -0,0 +1,145 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
+ var __export = (target, all) => {
18
+ for (var name in all)
19
+ __defProp(target, name, { get: all[name], enumerable: true });
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
+ // If the importer is in node compatibility mode or this is not an ESM
31
+ // file that has been converted to a CommonJS file using a Babel-
32
+ // compatible transform (i.e. "__esModule" has not been set), then set
33
+ // "default" to the CommonJS "module.exports" for node compatibility.
34
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
+ mod
36
+ ));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+ var sanitize_rich_text_html_exports = {};
39
+ __export(sanitize_rich_text_html_exports, {
40
+ sanitizeRichTextHtml: () => sanitizeRichTextHtml
41
+ });
42
+ module.exports = __toCommonJS(sanitize_rich_text_html_exports);
43
+ var import_sanitize_html = __toESM(require("sanitize-html"));
44
+ const imageDataUrlPattern = /^data:image\/(?:gif|jpe?g|png|webp);base64,[a-z\d+/=\s]+$/i;
45
+ const dimensionPattern = /^(?:\d{1,4}(?:\.\d+)?(?:px)?|(?:100|[1-9]?\d)(?:\.\d+)?%)$/;
46
+ const imageStyleDimensionPattern = /^(?:\d{1,4}(?:\.\d+)?px|(?:100|[1-9]?\d)(?:\.\d+)?%)$/;
47
+ function sanitizeLinkAttributes(attribs) {
48
+ const nextAttributes = { ...attribs };
49
+ if (nextAttributes.target && !["_blank", "_self"].includes(nextAttributes.target)) {
50
+ delete nextAttributes.target;
51
+ }
52
+ if (nextAttributes.target === "_blank") {
53
+ nextAttributes.rel = "noopener noreferrer";
54
+ } else {
55
+ delete nextAttributes.rel;
56
+ }
57
+ return nextAttributes;
58
+ }
59
+ __name(sanitizeLinkAttributes, "sanitizeLinkAttributes");
60
+ function sanitizeImageAttributes(attribs) {
61
+ var _a;
62
+ const nextAttributes = { ...attribs };
63
+ if (((_a = nextAttributes.src) == null ? void 0 : _a.trim().toLowerCase().startsWith("data:")) && !imageDataUrlPattern.test(nextAttributes.src)) {
64
+ delete nextAttributes.src;
65
+ }
66
+ for (const dimension of ["width", "height"]) {
67
+ if (nextAttributes[dimension] && !dimensionPattern.test(nextAttributes[dimension])) {
68
+ delete nextAttributes[dimension];
69
+ }
70
+ }
71
+ return nextAttributes;
72
+ }
73
+ __name(sanitizeImageAttributes, "sanitizeImageAttributes");
74
+ const richTextSanitizeOptions = {
75
+ allowedTags: [
76
+ "a",
77
+ "b",
78
+ "blockquote",
79
+ "br",
80
+ "em",
81
+ "h1",
82
+ "h2",
83
+ "h3",
84
+ "h4",
85
+ "h5",
86
+ "h6",
87
+ "i",
88
+ "img",
89
+ "li",
90
+ "ol",
91
+ "p",
92
+ "s",
93
+ "span",
94
+ "strike",
95
+ "strong",
96
+ "u",
97
+ "ul"
98
+ ],
99
+ allowedAttributes: {
100
+ a: ["href", "target", "rel"],
101
+ img: ["src", "alt", "title", "width", "height", "style"],
102
+ span: ["style"]
103
+ },
104
+ allowedClasses: {
105
+ blockquote: [/^ql-indent-[1-9]$/],
106
+ h1: [/^ql-indent-[1-9]$/],
107
+ h2: [/^ql-indent-[1-9]$/],
108
+ h3: [/^ql-indent-[1-9]$/],
109
+ h4: [/^ql-indent-[1-9]$/],
110
+ h5: [/^ql-indent-[1-9]$/],
111
+ h6: [/^ql-indent-[1-9]$/],
112
+ li: [/^ql-indent-[1-9]$/],
113
+ p: [/^ql-indent-[1-9]$/]
114
+ },
115
+ allowedStyles: {
116
+ img: {
117
+ height: [imageStyleDimensionPattern],
118
+ width: [imageStyleDimensionPattern]
119
+ },
120
+ span: {
121
+ "font-size": [/^(?:12|14|16|18|20|24|32|48)px$/]
122
+ }
123
+ },
124
+ allowedSchemes: ["http", "https", "mailto", "tel"],
125
+ allowedSchemesByTag: {
126
+ img: ["http", "https", "data"]
127
+ },
128
+ allowProtocolRelative: false,
129
+ transformTags: {
130
+ a(tagName, attribs) {
131
+ return { tagName, attribs: sanitizeLinkAttributes(attribs) };
132
+ },
133
+ img(tagName, attribs) {
134
+ return { tagName, attribs: sanitizeImageAttributes(attribs) };
135
+ }
136
+ }
137
+ };
138
+ function sanitizeRichTextHtml(value) {
139
+ return (0, import_sanitize_html.default)(value, richTextSanitizeOptions);
140
+ }
141
+ __name(sanitizeRichTextHtml, "sanitizeRichTextHtml");
142
+ // Annotate the CommonJS export names for ESM import in node:
143
+ 0 && (module.exports = {
144
+ sanitizeRichTextHtml
145
+ });
@@ -18,6 +18,7 @@ export declare function matchesDomainPattern(hostname: string, pattern: string):
18
18
  *
19
19
  * Throws an error if:
20
20
  * - The URL scheme is not http or https.
21
+ * - SERVER_REQUEST_DISALLOW_IP is true and the host is a literal IP address.
21
22
  * - SERVER_REQUEST_WHITELIST is set and the host does not match any entry.
22
23
  *
23
24
  * Silently returns for relative URLs (no scheme) so that internal API calls
@@ -189,13 +189,19 @@ function checkUrlAgainstWhitelist(url) {
189
189
  );
190
190
  }
191
191
  const host = getNormalizedHost(parsed);
192
+ if (process.env.SERVER_REQUEST_DISALLOW_IP === "true" && import_ipaddr.default.isValid(host)) {
193
+ throw new Error(`Outbound request to "${host}" is blocked because SERVER_REQUEST_DISALLOW_IP is enabled.`);
194
+ }
192
195
  const whitelist = process.env.SERVER_REQUEST_WHITELIST;
193
196
  if (!whitelist || !whitelist.trim()) {
194
197
  warnIfSsrfRiskTarget(host);
195
198
  return;
196
199
  }
197
200
  const entries = whitelist.split(",").map((e) => e.trim()).filter(Boolean);
198
- if (entries.length === 0) return;
201
+ if (entries.length === 0) {
202
+ warnIfSsrfRiskTarget(host);
203
+ return;
204
+ }
199
205
  for (const entry of entries) {
200
206
  if (matchesEntry(host, entry)) return;
201
207
  }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@nocobase/utils",
3
- "version": "2.3.0-beta.2",
3
+ "version": "2.3.0-beta.20",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "Apache-2.0",
7
7
  "dependencies": {
8
- "@budibase/handlebars-helpers": "0.14.0",
8
+ "@budibase/handlebars-helpers": "0.14.3",
9
9
  "@hapi/topo": "^6.0.0",
10
10
  "@rc-component/mini-decimal": "^1.1.0",
11
11
  "axios": "^1.7.0",
@@ -19,7 +19,8 @@
19
19
  "liquidjs": "^10.23.0",
20
20
  "multer": "^2.1.1",
21
21
  "object-path": "^0.11.8",
22
+ "sanitize-html": "2.17.7",
22
23
  "ses": "^1.14.0"
23
24
  },
24
- "gitHead": "2e5b43a39d3f3e7cff58cb5e5a36a8c8e599dfb5"
25
+ "gitHead": "31adfe1b6bd3136bec29ff936fe1a0a7b5273d67"
25
26
  }