@crowi/plugin-api 1.0.0-alpha.3 → 1.0.0-alpha.5

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/dist/index.js CHANGED
@@ -22,11 +22,34 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  ACTION_FIELD_MARKER: () => ACTION_FIELD_MARKER,
24
24
  SENSITIVE_FIELD_MARKER: () => SENSITIVE_FIELD_MARKER,
25
+ escapeHtml: () => escapeHtml,
26
+ extractSvgDimensions: () => extractSvgDimensions,
25
27
  getActionAnnotation: () => getActionAnnotation,
26
- isSensitiveField: () => isSensitiveField
28
+ isSensitiveField: () => isSensitiveField,
29
+ sanitizeSvg: () => sanitizeSvg
27
30
  });
28
31
  module.exports = __toCommonJS(index_exports);
29
32
 
33
+ // src/html.ts
34
+ function escapeHtml(s) {
35
+ return s.replace(/[&<>"']/g, (c) => {
36
+ switch (c) {
37
+ case "&":
38
+ return "&amp;";
39
+ case "<":
40
+ return "&lt;";
41
+ case ">":
42
+ return "&gt;";
43
+ case '"':
44
+ return "&quot;";
45
+ case "'":
46
+ return "&#39;";
47
+ default:
48
+ return c;
49
+ }
50
+ });
51
+ }
52
+
30
53
  // src/schema-markers.ts
31
54
  var SENSITIVE_FIELD_MARKER = "@sensitive";
32
55
  var ACTION_FIELD_MARKER = "@action";
@@ -45,11 +68,215 @@ function getActionAnnotation(field) {
45
68
  const [, label, method, path] = match;
46
69
  return { label, method, path };
47
70
  }
71
+
72
+ // ../svg-sanitize/dist/index.mjs
73
+ var import_xmldom = require("@xmldom/xmldom");
74
+ var MAX_DIMENSION_PX = 1e6;
75
+ function extractSvgDimensions(svg) {
76
+ const match = /\bviewBox\s*=\s*["']\s*([-\d.]+)[\s,]+([-\d.]+)[\s,]+([-\d.]+)[\s,]+([-\d.]+)\s*["']/.exec(svg);
77
+ if (!match) return null;
78
+ const width = Math.round(Number(match[3]));
79
+ const height = Math.round(Number(match[4]));
80
+ if (!Number.isFinite(width) || !Number.isFinite(height)) return null;
81
+ if (width <= 0 || height <= 0 || width > MAX_DIMENSION_PX || height > MAX_DIMENSION_PX) return null;
82
+ return { width, height };
83
+ }
84
+ function sanitizeSvg(input, policy) {
85
+ const doc = parseXml(input);
86
+ if (!doc) return { ok: false, reason: "malformed_xml" };
87
+ if (doc.doctype) {
88
+ return { ok: false, reason: "doctype_not_allowed" };
89
+ }
90
+ const root = doc.documentElement;
91
+ if (!isUnprefixedSvgElement(root)) {
92
+ return { ok: false, reason: "root_is_not_svg" };
93
+ }
94
+ sanitizeElementTree(root, policy, true);
95
+ const serializer = new import_xmldom.XMLSerializer();
96
+ const serialized = serializer.serializeToString(root);
97
+ const verifyDoc = parseXml(serialized);
98
+ if (!verifyDoc || !isUnprefixedSvgElement(verifyDoc.documentElement)) {
99
+ return { ok: false, reason: "sanitized_output_not_single_root_svg" };
100
+ }
101
+ return { ok: true, svg: serialized };
102
+ }
103
+ var SVG_NAMESPACE_URI = "http://www.w3.org/2000/svg";
104
+ var XML_NAMESPACE_URI = "http://www.w3.org/XML/1998/namespace";
105
+ var XLINK_NAMESPACE_URI = "http://www.w3.org/1999/xlink";
106
+ function isSvgNamespaceElement(el) {
107
+ return el.namespaceURI === SVG_NAMESPACE_URI && el.prefix == null;
108
+ }
109
+ function isUnprefixedSvgElement(el) {
110
+ return el != null && el.localName === "svg" && isSvgNamespaceElement(el);
111
+ }
112
+ function parseXml(source) {
113
+ try {
114
+ return new import_xmldom.DOMParser({ onError: () => void 0 }).parseFromString(source, "image/svg+xml");
115
+ } catch {
116
+ return null;
117
+ }
118
+ }
119
+ var ALLOWED_ELEMENTS = /* @__PURE__ */ new Set([
120
+ "svg",
121
+ "g",
122
+ "defs",
123
+ "symbol",
124
+ "use",
125
+ "title",
126
+ "desc",
127
+ "metadata",
128
+ "path",
129
+ "rect",
130
+ "circle",
131
+ "ellipse",
132
+ "line",
133
+ "polyline",
134
+ "polygon",
135
+ "text",
136
+ "tspan",
137
+ "textPath",
138
+ "tref",
139
+ "marker",
140
+ "clipPath",
141
+ "mask",
142
+ "pattern",
143
+ "linearGradient",
144
+ "radialGradient",
145
+ "stop",
146
+ "image",
147
+ "style",
148
+ "a",
149
+ "switch",
150
+ "filter",
151
+ "feGaussianBlur",
152
+ "feOffset",
153
+ "feMerge",
154
+ "feMergeNode",
155
+ "feColorMatrix",
156
+ "feComposite",
157
+ "feFlood",
158
+ "feBlend",
159
+ "feDropShadow",
160
+ "feMorphology",
161
+ "feTurbulence",
162
+ "feDisplacementMap"
163
+ ]);
164
+ var PROCESSING_INSTRUCTION_NODE = 7;
165
+ var ELEMENT_NODE = 1;
166
+ function sanitizeElementTree(el, policy, isRoot) {
167
+ sanitizeAttributes(el, policy, isRoot);
168
+ if (el.localName === "style") {
169
+ el.textContent = sanitizeStyleText(el.textContent ?? "");
170
+ return;
171
+ }
172
+ for (const child of Array.from(el.childNodes)) {
173
+ if (child.nodeType === PROCESSING_INSTRUCTION_NODE) {
174
+ el.removeChild(child);
175
+ continue;
176
+ }
177
+ if (child.nodeType !== ELEMENT_NODE) continue;
178
+ const childEl = child;
179
+ if (!isSvgNamespaceElement(childEl) || !ALLOWED_ELEMENTS.has(childEl.localName ?? childEl.nodeName)) {
180
+ el.removeChild(childEl);
181
+ continue;
182
+ }
183
+ sanitizeElementTree(childEl, policy, false);
184
+ }
185
+ }
186
+ function sanitizeAttributes(el, policy, isRoot) {
187
+ for (const attr of Array.from(el.attributes)) {
188
+ const localName = attr.localName ?? attr.name;
189
+ if (/^on/i.test(localName)) {
190
+ el.removeAttributeNode(attr);
191
+ continue;
192
+ }
193
+ if (localName === "style") {
194
+ el.removeAttributeNode(attr);
195
+ continue;
196
+ }
197
+ if (localName === "base" && attr.namespaceURI === XML_NAMESPACE_URI) {
198
+ el.removeAttributeNode(attr);
199
+ continue;
200
+ }
201
+ if (localName === "href") {
202
+ const sanitizedValue = sanitizeHrefValue(attr.value, policy);
203
+ if (sanitizedValue === null) {
204
+ el.removeAttributeNode(attr);
205
+ } else {
206
+ attr.value = sanitizedValue;
207
+ }
208
+ continue;
209
+ }
210
+ if (URL_VALUED_PRESENTATION_ATTRS.has(localName)) {
211
+ if (!isUrlFuncIriSafe(attr.value)) {
212
+ el.removeAttributeNode(attr);
213
+ }
214
+ continue;
215
+ }
216
+ if (attr.name === "xmlns" || attr.name.startsWith("xmlns:")) {
217
+ if (!isRoot || !isEssentialRootNamespaceDeclaration(attr)) {
218
+ el.removeAttributeNode(attr);
219
+ }
220
+ }
221
+ }
222
+ }
223
+ function isEssentialRootNamespaceDeclaration(attr) {
224
+ if (attr.name === "xmlns") return true;
225
+ return attr.name === "xmlns:xlink" && attr.value === XLINK_NAMESPACE_URI;
226
+ }
227
+ var URL_VALUED_PRESENTATION_ATTRS = /* @__PURE__ */ new Set([
228
+ "fill",
229
+ "stroke",
230
+ "filter",
231
+ "clip-path",
232
+ "mask",
233
+ "cursor",
234
+ "marker",
235
+ "marker-start",
236
+ "marker-mid",
237
+ "marker-end"
238
+ ]);
239
+ var URL_FUNC_PATTERN = /url\(\s*(['"]?)([^'")]*)\1\s*\)/gi;
240
+ function isUrlFuncIriSafe(rawValue) {
241
+ const matches = Array.from(cssUnescape(rawValue).matchAll(URL_FUNC_PATTERN));
242
+ if (matches.length === 0) return true;
243
+ return matches.every(([, , target]) => target.trim().startsWith("#"));
244
+ }
245
+ function sanitizeHrefValue(rawValue, policy) {
246
+ const value = rawValue.trim();
247
+ if (value.startsWith("#")) return value;
248
+ if (/^javascript:/i.test(value)) return null;
249
+ if (/^data:/i.test(value)) return null;
250
+ if (value.startsWith("//")) return null;
251
+ if (policy.allowSafeHref && /^https:\/\//i.test(value)) return value;
252
+ return null;
253
+ }
254
+ function sanitizeStyleText(css) {
255
+ const withoutComments = css.replace(/\/\*[\s\S]*?\*\//g, " ");
256
+ let out = cssUnescape(withoutComments);
257
+ out = out.replace(/@import\b[^;]*;?/gi, "");
258
+ out = out.replace(URL_FUNC_PATTERN, (match, _quote, target) => target.trim().startsWith("#") ? match : "none");
259
+ return out;
260
+ }
261
+ function cssUnescape(css) {
262
+ return css.replace(/\\([0-9a-fA-F]{1,6})[ \t\n\f\r]?|\\([^\r\n\f])|\\$/g, (_match, hex, literal) => {
263
+ if (hex !== void 0) {
264
+ const codePoint = Number.parseInt(hex, 16);
265
+ if (codePoint === 0 || codePoint > 1114111 || codePoint >= 55296 && codePoint <= 57343) return "\uFFFD";
266
+ return String.fromCodePoint(codePoint);
267
+ }
268
+ if (literal !== void 0) return literal;
269
+ return "\uFFFD";
270
+ });
271
+ }
48
272
  // Annotate the CommonJS export names for ESM import in node:
49
273
  0 && (module.exports = {
50
274
  ACTION_FIELD_MARKER,
51
275
  SENSITIVE_FIELD_MARKER,
276
+ escapeHtml,
277
+ extractSvgDimensions,
52
278
  getActionAnnotation,
53
- isSensitiveField
279
+ isSensitiveField,
280
+ sanitizeSvg
54
281
  });
55
282
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/schema-markers.ts"],"sourcesContent":["/**\n * @crowi/plugin-api — type-only contract for Crowi 2.0 plugins.\n *\n * Plugins author against this package. The runtime (@crowi/server) loads\n * plugins listed in `crowi.config.json`, calls each plugin's\n * `register*` callbacks, and routes all the side effects (storage,\n * search, auth, notifications) through the typed registries declared\n * here.\n *\n * For the design rationale see `docs/rfcs/0001-plugin-architecture.md`\n * in the Crowi monorepo.\n */\n\nexport type { CrowiPlugin } from './plugin';\n\nexport type { PluginContext, AppInfo, PageMetadataAccessor, PluginLogger, StateCell } from './context';\n\nexport type { StorageDriver, StorageRegistry, StoragePutMeta, StoragePutResult } from './registries/storage';\n\nexport type {\n SearchDriver,\n SearchRegistry,\n SearchableDoc,\n SearchQuery,\n SearchQueryViewer,\n SearchQueryGrants,\n SearchPageType,\n SearchHits,\n SearchHit,\n} from './registries/search';\n\nexport type { AuthDriver, AuthRegistry, AuthProfile, AuthVerifyResult } from './registries/auth';\n\nexport type { NotifierDriver, NotifierRegistry, NotificationPayload } from './registries/notifier';\n\nexport type { MailSender, MailSenderRegistry, EmailMessage } from './registries/mail';\n\nexport type {\n RendererRegistry,\n NodeRenderer,\n CodeBlockRenderer,\n CodeBlockInfo,\n EmbedRenderer,\n EmbedInput,\n EmbedFragment,\n UrlInlineExpansionRule,\n InlineExpansion,\n RenderContext,\n RenderPhase,\n RenderResult,\n RenderError,\n Reservation,\n CacheStorage,\n ScopedCacheStorage,\n CacheKey,\n CacheEntry,\n AuthContext,\n} from './renderer';\n\nexport type { EventBus, PluginEvents } from './events';\n\nexport type { PluginRouterScope, PluginRouteHandler, PluginRouteMethod, PluginRouteOptions } from './routes';\n\nexport { SENSITIVE_FIELD_MARKER, ACTION_FIELD_MARKER, isSensitiveField, getActionAnnotation } from './schema-markers';\n","import type { z } from 'zod/v3';\n\nimport type { PluginRouteMethod } from './routes';\n\n/**\n * `configSchema` description-string markers.\n *\n * The admin UI walks the schema and looks at each field's\n * `description` (set via `z.string().describe('@sensitive ...')`). A\n * description starting with one of these marker tokens unlocks special\n * UI behaviour without forcing every field to declare a custom Zod\n * type.\n */\n\n/**\n * Marker that flags a config field as sensitive (encrypted at rest).\n * Usage:\n *\n * z.string().describe('@sensitive AWS secret access key')\n *\n * The runtime auto-encrypts on write and decrypts on read, using the\n * same KeyProvider as core sensitive Config. The admin UI renders the\n * field via `<SecretField>` (saved badge / clear pending / undo).\n */\nexport const SENSITIVE_FIELD_MARKER = '@sensitive';\n\n/**\n * Marker that adds an action button next to a config field. Usage:\n *\n * z.string().describe('@action \"Test connection\" POST /test')\n *\n * The admin form renders a button with the given label that calls the\n * plugin's contributed endpoint at the given verb / path (relative to\n * `/api/v2/plugins/<name>/`). Useful for \"Test connection\",\n * \"Authorise with Google\", etc. without forcing every plugin to ship\n * its own React component.\n */\nexport const ACTION_FIELD_MARKER = '@action';\n\n/**\n * True if the schema field is marked `@sensitive`.\n *\n * `field` is `z.ZodTypeAny` (intentionally loose); call sites pass the\n * value type from `configSchema.shape[key]`.\n */\nexport function isSensitiveField(field: z.ZodTypeAny): boolean {\n const description = field.description;\n return typeof description === 'string' && description.trimStart().startsWith(SENSITIVE_FIELD_MARKER);\n}\n\n/**\n * Parsed `@action` annotation extracted from a field's `description`.\n */\nexport interface ActionAnnotation {\n /** Visible button label, e.g. \"Test connection\". */\n label: string;\n /** HTTP verb of the plugin endpoint to call. */\n method: PluginRouteMethod;\n /** Path relative to `/api/v2/plugins/<name>/`, with leading slash. */\n path: string;\n}\n\n/**\n * Parse an `@action` annotation off a field, or return null if absent.\n *\n * Format: `@action \"<label>\" <METHOD> <path>`\n * e.g. `@action \"Test connection\" POST /test`\n *\n * The label may include spaces when wrapped in double quotes; the method\n * must be one of `PluginRouteMethod` (`GET` / `POST` — the only verbs a\n * plugin route can actually be mounted on, see `routes.ts`); the path\n * begins with `/`. A description that starts with the `@action` marker\n * but declares an unsupported verb (e.g. `PUT` / `DELETE`) fails to match\n * and returns `null` here — callers that walk a plugin's `configSchema`\n * (e.g. `PluginManager.activate()`) are expected to warn on that case at\n * boot, since it would otherwise be a silent dead button.\n */\nexport function getActionAnnotation(field: z.ZodTypeAny): ActionAnnotation | null {\n const description = field.description;\n if (typeof description !== 'string') return null;\n const trimmed = description.trimStart();\n if (!trimmed.startsWith(ACTION_FIELD_MARKER)) return null;\n\n const rest = trimmed.slice(ACTION_FIELD_MARKER.length).trimStart();\n // `\"<label>\" <METHOD> <path>`\n const match = rest.match(/^\"([^\"]+)\"\\s+(GET|POST)\\s+(\\/\\S*)/);\n if (!match) return null;\n\n const [, label, method, path] = match;\n return { label, method: method as ActionAnnotation['method'], path };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACwBO,IAAM,yBAAyB;AAa/B,IAAM,sBAAsB;AAQ5B,SAAS,iBAAiB,OAA8B;AAC7D,QAAM,cAAc,MAAM;AAC1B,SAAO,OAAO,gBAAgB,YAAY,YAAY,UAAU,EAAE,WAAW,sBAAsB;AACrG;AA6BO,SAAS,oBAAoB,OAA8C;AAChF,QAAM,cAAc,MAAM;AAC1B,MAAI,OAAO,gBAAgB,SAAU,QAAO;AAC5C,QAAM,UAAU,YAAY,UAAU;AACtC,MAAI,CAAC,QAAQ,WAAW,mBAAmB,EAAG,QAAO;AAErD,QAAM,OAAO,QAAQ,MAAM,oBAAoB,MAAM,EAAE,UAAU;AAEjE,QAAM,QAAQ,KAAK,MAAM,mCAAmC;AAC5D,MAAI,CAAC,MAAO,QAAO;AAEnB,QAAM,CAAC,EAAE,OAAO,QAAQ,IAAI,IAAI;AAChC,SAAO,EAAE,OAAO,QAA8C,KAAK;AACrE;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/html.ts","../src/schema-markers.ts","../../svg-sanitize/src/dimensions.ts","../../svg-sanitize/src/sanitize.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaO,SAAS,WAAW,GAAmB;AAC5C,SAAO,EAAE,QAAQ,YAAY,CAAC,MAAM;AAClC,YAAQ,GAAG;AAAA,MACT,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO;AAAA,MACT;AACE,eAAO;AAAA,IACX;AAAA,EACF,CAAC;AACH;;;ACNO,IAAM,yBAAyB;AAa/B,IAAM,sBAAsB;AAQ5B,SAAS,iBAAiB,OAA8B;AAC7D,QAAM,cAAc,MAAM;AAC1B,SAAO,OAAO,gBAAgB,YAAY,YAAY,UAAU,EAAE,WAAW,sBAAsB;AACrG;AA6BO,SAAS,oBAAoB,OAA8C;AAChF,QAAM,cAAc,MAAM;AAC1B,MAAI,OAAO,gBAAgB,SAAU,QAAO;AAC5C,QAAM,UAAU,YAAY,UAAU;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;AACjC,SAAO,QAAQ,MAAM,CAAC,CAAC,EAAE,EAAE,MAAM,MAAM,OAAO,KAAK,EAAE,WAAW,GAAG,CAAC;AACtE;AAGA,SAAS,kBAAkB,UAAkB,QAA0C;AACrF,QAAM,QAAQ,SAAS,KAAK;AAC5B,MAAI,MAAM,WAAW,GAAG,EAAG,QAAO;AAClC,MAAI,gBAAgB,KAAK,KAAK,EAAG,QAAO;AACxC,MAAI,UAAU,KAAK,KAAK,EAAG,QAAO;AAClC,MAAI,MAAM,WAAW,IAAI,EAAG,QAAO;AACnC,MAAI,OAAO,iBAAiB,eAAe,KAAK,KAAK,EAAG,QAAO;AAC/D,SAAO;AACT;AA6CA,SAAS,kBAAkB,KAAqB;AAM9C,QAAM,kBAAkB,IAAI,QAAQ,qBAAqB,GAAG;AAC5D,MAAI,MAAM,YAAY,eAAe;AACrC,QAAM,IAAI,QAAQ,sBAAsB,EAAE;AAC1C,QAAM,IAAI,QAAQ,kBAAkB,CAAC,OAAO,QAAQ,WAAY,OAAO,KAAK,EAAE,WAAW,GAAG,IAAI,QAAQ,MAAO;AAC/G,SAAO;AACT;AAaA,SAAS,YAAY,KAAqB;AACxC,SAAO,IAAI,QAAQ,uDAAuD,CAAC,QAAQ,KAAyB,YAAgC;AAC1I,QAAI,QAAQ,QAAW;AACrB,YAAM,YAAY,OAAO,SAAS,KAAK,EAAE;AACzC,UAAI,cAAc,KAAK,YAAY,WAAa,aAAa,SAAU,aAAa,MAAS,QAAO;AACpG,aAAO,OAAO,cAAc,SAAS;IACvC;AACA,QAAI,YAAY,OAAW,QAAO;AAClC,WAAO;EACT,CAAC;AACH;","names":[]}
package/dist/index.mjs CHANGED
@@ -1,3 +1,23 @@
1
+ // src/html.ts
2
+ function escapeHtml(s) {
3
+ return s.replace(/[&<>"']/g, (c) => {
4
+ switch (c) {
5
+ case "&":
6
+ return "&amp;";
7
+ case "<":
8
+ return "&lt;";
9
+ case ">":
10
+ return "&gt;";
11
+ case '"':
12
+ return "&quot;";
13
+ case "'":
14
+ return "&#39;";
15
+ default:
16
+ return c;
17
+ }
18
+ });
19
+ }
20
+
1
21
  // src/schema-markers.ts
2
22
  var SENSITIVE_FIELD_MARKER = "@sensitive";
3
23
  var ACTION_FIELD_MARKER = "@action";
@@ -16,10 +36,214 @@ function getActionAnnotation(field) {
16
36
  const [, label, method, path] = match;
17
37
  return { label, method, path };
18
38
  }
39
+
40
+ // ../svg-sanitize/dist/index.mjs
41
+ import { DOMParser, XMLSerializer } from "@xmldom/xmldom";
42
+ var MAX_DIMENSION_PX = 1e6;
43
+ function extractSvgDimensions(svg) {
44
+ const match = /\bviewBox\s*=\s*["']\s*([-\d.]+)[\s,]+([-\d.]+)[\s,]+([-\d.]+)[\s,]+([-\d.]+)\s*["']/.exec(svg);
45
+ if (!match) return null;
46
+ const width = Math.round(Number(match[3]));
47
+ const height = Math.round(Number(match[4]));
48
+ if (!Number.isFinite(width) || !Number.isFinite(height)) return null;
49
+ if (width <= 0 || height <= 0 || width > MAX_DIMENSION_PX || height > MAX_DIMENSION_PX) return null;
50
+ return { width, height };
51
+ }
52
+ function sanitizeSvg(input, policy) {
53
+ const doc = parseXml(input);
54
+ if (!doc) return { ok: false, reason: "malformed_xml" };
55
+ if (doc.doctype) {
56
+ return { ok: false, reason: "doctype_not_allowed" };
57
+ }
58
+ const root = doc.documentElement;
59
+ if (!isUnprefixedSvgElement(root)) {
60
+ return { ok: false, reason: "root_is_not_svg" };
61
+ }
62
+ sanitizeElementTree(root, policy, true);
63
+ const serializer = new XMLSerializer();
64
+ const serialized = serializer.serializeToString(root);
65
+ const verifyDoc = parseXml(serialized);
66
+ if (!verifyDoc || !isUnprefixedSvgElement(verifyDoc.documentElement)) {
67
+ return { ok: false, reason: "sanitized_output_not_single_root_svg" };
68
+ }
69
+ return { ok: true, svg: serialized };
70
+ }
71
+ var SVG_NAMESPACE_URI = "http://www.w3.org/2000/svg";
72
+ var XML_NAMESPACE_URI = "http://www.w3.org/XML/1998/namespace";
73
+ var XLINK_NAMESPACE_URI = "http://www.w3.org/1999/xlink";
74
+ function isSvgNamespaceElement(el) {
75
+ return el.namespaceURI === SVG_NAMESPACE_URI && el.prefix == null;
76
+ }
77
+ function isUnprefixedSvgElement(el) {
78
+ return el != null && el.localName === "svg" && isSvgNamespaceElement(el);
79
+ }
80
+ function parseXml(source) {
81
+ try {
82
+ return new DOMParser({ onError: () => void 0 }).parseFromString(source, "image/svg+xml");
83
+ } catch {
84
+ return null;
85
+ }
86
+ }
87
+ var ALLOWED_ELEMENTS = /* @__PURE__ */ new Set([
88
+ "svg",
89
+ "g",
90
+ "defs",
91
+ "symbol",
92
+ "use",
93
+ "title",
94
+ "desc",
95
+ "metadata",
96
+ "path",
97
+ "rect",
98
+ "circle",
99
+ "ellipse",
100
+ "line",
101
+ "polyline",
102
+ "polygon",
103
+ "text",
104
+ "tspan",
105
+ "textPath",
106
+ "tref",
107
+ "marker",
108
+ "clipPath",
109
+ "mask",
110
+ "pattern",
111
+ "linearGradient",
112
+ "radialGradient",
113
+ "stop",
114
+ "image",
115
+ "style",
116
+ "a",
117
+ "switch",
118
+ "filter",
119
+ "feGaussianBlur",
120
+ "feOffset",
121
+ "feMerge",
122
+ "feMergeNode",
123
+ "feColorMatrix",
124
+ "feComposite",
125
+ "feFlood",
126
+ "feBlend",
127
+ "feDropShadow",
128
+ "feMorphology",
129
+ "feTurbulence",
130
+ "feDisplacementMap"
131
+ ]);
132
+ var PROCESSING_INSTRUCTION_NODE = 7;
133
+ var ELEMENT_NODE = 1;
134
+ function sanitizeElementTree(el, policy, isRoot) {
135
+ sanitizeAttributes(el, policy, isRoot);
136
+ if (el.localName === "style") {
137
+ el.textContent = sanitizeStyleText(el.textContent ?? "");
138
+ return;
139
+ }
140
+ for (const child of Array.from(el.childNodes)) {
141
+ if (child.nodeType === PROCESSING_INSTRUCTION_NODE) {
142
+ el.removeChild(child);
143
+ continue;
144
+ }
145
+ if (child.nodeType !== ELEMENT_NODE) continue;
146
+ const childEl = child;
147
+ if (!isSvgNamespaceElement(childEl) || !ALLOWED_ELEMENTS.has(childEl.localName ?? childEl.nodeName)) {
148
+ el.removeChild(childEl);
149
+ continue;
150
+ }
151
+ sanitizeElementTree(childEl, policy, false);
152
+ }
153
+ }
154
+ function sanitizeAttributes(el, policy, isRoot) {
155
+ for (const attr of Array.from(el.attributes)) {
156
+ const localName = attr.localName ?? attr.name;
157
+ if (/^on/i.test(localName)) {
158
+ el.removeAttributeNode(attr);
159
+ continue;
160
+ }
161
+ if (localName === "style") {
162
+ el.removeAttributeNode(attr);
163
+ continue;
164
+ }
165
+ if (localName === "base" && attr.namespaceURI === XML_NAMESPACE_URI) {
166
+ el.removeAttributeNode(attr);
167
+ continue;
168
+ }
169
+ if (localName === "href") {
170
+ const sanitizedValue = sanitizeHrefValue(attr.value, policy);
171
+ if (sanitizedValue === null) {
172
+ el.removeAttributeNode(attr);
173
+ } else {
174
+ attr.value = sanitizedValue;
175
+ }
176
+ continue;
177
+ }
178
+ if (URL_VALUED_PRESENTATION_ATTRS.has(localName)) {
179
+ if (!isUrlFuncIriSafe(attr.value)) {
180
+ el.removeAttributeNode(attr);
181
+ }
182
+ continue;
183
+ }
184
+ if (attr.name === "xmlns" || attr.name.startsWith("xmlns:")) {
185
+ if (!isRoot || !isEssentialRootNamespaceDeclaration(attr)) {
186
+ el.removeAttributeNode(attr);
187
+ }
188
+ }
189
+ }
190
+ }
191
+ function isEssentialRootNamespaceDeclaration(attr) {
192
+ if (attr.name === "xmlns") return true;
193
+ return attr.name === "xmlns:xlink" && attr.value === XLINK_NAMESPACE_URI;
194
+ }
195
+ var URL_VALUED_PRESENTATION_ATTRS = /* @__PURE__ */ new Set([
196
+ "fill",
197
+ "stroke",
198
+ "filter",
199
+ "clip-path",
200
+ "mask",
201
+ "cursor",
202
+ "marker",
203
+ "marker-start",
204
+ "marker-mid",
205
+ "marker-end"
206
+ ]);
207
+ var URL_FUNC_PATTERN = /url\(\s*(['"]?)([^'")]*)\1\s*\)/gi;
208
+ function isUrlFuncIriSafe(rawValue) {
209
+ const matches = Array.from(cssUnescape(rawValue).matchAll(URL_FUNC_PATTERN));
210
+ if (matches.length === 0) return true;
211
+ return matches.every(([, , target]) => target.trim().startsWith("#"));
212
+ }
213
+ function sanitizeHrefValue(rawValue, policy) {
214
+ const value = rawValue.trim();
215
+ if (value.startsWith("#")) return value;
216
+ if (/^javascript:/i.test(value)) return null;
217
+ if (/^data:/i.test(value)) return null;
218
+ if (value.startsWith("//")) return null;
219
+ if (policy.allowSafeHref && /^https:\/\//i.test(value)) return value;
220
+ return null;
221
+ }
222
+ function sanitizeStyleText(css) {
223
+ const withoutComments = css.replace(/\/\*[\s\S]*?\*\//g, " ");
224
+ let out = cssUnescape(withoutComments);
225
+ out = out.replace(/@import\b[^;]*;?/gi, "");
226
+ out = out.replace(URL_FUNC_PATTERN, (match, _quote, target) => target.trim().startsWith("#") ? match : "none");
227
+ return out;
228
+ }
229
+ function cssUnescape(css) {
230
+ return css.replace(/\\([0-9a-fA-F]{1,6})[ \t\n\f\r]?|\\([^\r\n\f])|\\$/g, (_match, hex, literal) => {
231
+ if (hex !== void 0) {
232
+ const codePoint = Number.parseInt(hex, 16);
233
+ if (codePoint === 0 || codePoint > 1114111 || codePoint >= 55296 && codePoint <= 57343) return "\uFFFD";
234
+ return String.fromCodePoint(codePoint);
235
+ }
236
+ if (literal !== void 0) return literal;
237
+ return "\uFFFD";
238
+ });
239
+ }
19
240
  export {
20
241
  ACTION_FIELD_MARKER,
21
242
  SENSITIVE_FIELD_MARKER,
243
+ escapeHtml,
244
+ extractSvgDimensions,
22
245
  getActionAnnotation,
23
- isSensitiveField
246
+ isSensitiveField,
247
+ sanitizeSvg
24
248
  };
25
249
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/schema-markers.ts"],"sourcesContent":["import type { z } from 'zod/v3';\n\nimport type { PluginRouteMethod } from './routes';\n\n/**\n * `configSchema` description-string markers.\n *\n * The admin UI walks the schema and looks at each field's\n * `description` (set via `z.string().describe('@sensitive ...')`). A\n * description starting with one of these marker tokens unlocks special\n * UI behaviour without forcing every field to declare a custom Zod\n * type.\n */\n\n/**\n * Marker that flags a config field as sensitive (encrypted at rest).\n * Usage:\n *\n * z.string().describe('@sensitive AWS secret access key')\n *\n * The runtime auto-encrypts on write and decrypts on read, using the\n * same KeyProvider as core sensitive Config. The admin UI renders the\n * field via `<SecretField>` (saved badge / clear pending / undo).\n */\nexport const SENSITIVE_FIELD_MARKER = '@sensitive';\n\n/**\n * Marker that adds an action button next to a config field. Usage:\n *\n * z.string().describe('@action \"Test connection\" POST /test')\n *\n * The admin form renders a button with the given label that calls the\n * plugin's contributed endpoint at the given verb / path (relative to\n * `/api/v2/plugins/<name>/`). Useful for \"Test connection\",\n * \"Authorise with Google\", etc. without forcing every plugin to ship\n * its own React component.\n */\nexport const ACTION_FIELD_MARKER = '@action';\n\n/**\n * True if the schema field is marked `@sensitive`.\n *\n * `field` is `z.ZodTypeAny` (intentionally loose); call sites pass the\n * value type from `configSchema.shape[key]`.\n */\nexport function isSensitiveField(field: z.ZodTypeAny): boolean {\n const description = field.description;\n return typeof description === 'string' && description.trimStart().startsWith(SENSITIVE_FIELD_MARKER);\n}\n\n/**\n * Parsed `@action` annotation extracted from a field's `description`.\n */\nexport interface ActionAnnotation {\n /** Visible button label, e.g. \"Test connection\". */\n label: string;\n /** HTTP verb of the plugin endpoint to call. */\n method: PluginRouteMethod;\n /** Path relative to `/api/v2/plugins/<name>/`, with leading slash. */\n path: string;\n}\n\n/**\n * Parse an `@action` annotation off a field, or return null if absent.\n *\n * Format: `@action \"<label>\" <METHOD> <path>`\n * e.g. `@action \"Test connection\" POST /test`\n *\n * The label may include spaces when wrapped in double quotes; the method\n * must be one of `PluginRouteMethod` (`GET` / `POST` — the only verbs a\n * plugin route can actually be mounted on, see `routes.ts`); the path\n * begins with `/`. A description that starts with the `@action` marker\n * but declares an unsupported verb (e.g. `PUT` / `DELETE`) fails to match\n * and returns `null` here — callers that walk a plugin's `configSchema`\n * (e.g. `PluginManager.activate()`) are expected to warn on that case at\n * boot, since it would otherwise be a silent dead button.\n */\nexport function getActionAnnotation(field: z.ZodTypeAny): ActionAnnotation | null {\n const description = field.description;\n if (typeof description !== 'string') return null;\n const trimmed = description.trimStart();\n if (!trimmed.startsWith(ACTION_FIELD_MARKER)) return null;\n\n const rest = trimmed.slice(ACTION_FIELD_MARKER.length).trimStart();\n // `\"<label>\" <METHOD> <path>`\n const match = rest.match(/^\"([^\"]+)\"\\s+(GET|POST)\\s+(\\/\\S*)/);\n if (!match) return null;\n\n const [, label, method, path] = match;\n return { label, method: method as ActionAnnotation['method'], path };\n}\n"],"mappings":";AAwBO,IAAM,yBAAyB;AAa/B,IAAM,sBAAsB;AAQ5B,SAAS,iBAAiB,OAA8B;AAC7D,QAAM,cAAc,MAAM;AAC1B,SAAO,OAAO,gBAAgB,YAAY,YAAY,UAAU,EAAE,WAAW,sBAAsB;AACrG;AA6BO,SAAS,oBAAoB,OAA8C;AAChF,QAAM,cAAc,MAAM;AAC1B,MAAI,OAAO,gBAAgB,SAAU,QAAO;AAC5C,QAAM,UAAU,YAAY,UAAU;AACtC,MAAI,CAAC,QAAQ,WAAW,mBAAmB,EAAG,QAAO;AAErD,QAAM,OAAO,QAAQ,MAAM,oBAAoB,MAAM,EAAE,UAAU;AAEjE,QAAM,QAAQ,KAAK,MAAM,mCAAmC;AAC5D,MAAI,CAAC,MAAO,QAAO;AAEnB,QAAM,CAAC,EAAE,OAAO,QAAQ,IAAI,IAAI;AAChC,SAAO,EAAE,OAAO,QAA8C,KAAK;AACrE;","names":[]}
1
+ {"version":3,"sources":["../src/html.ts","../src/schema-markers.ts","../../svg-sanitize/src/dimensions.ts","../../svg-sanitize/src/sanitize.ts"],"mappings":";AAaO,SAAS,WAAW,GAAmB;AAC5C,SAAO,EAAE,QAAQ,YAAY,CAAC,MAAM;AAClC,YAAQ,GAAG;AAAA,MACT,KAAK;AACH,eAAO;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AQ,KAAyB,YAAgC;AAC1I,QAAI,QAAQ,QAAW;AACrB,YAAM,YAAY,OAAO,SAAS,KAAK,EAAE;AACzC,UAAI,cAAc,KAAK,YAAY,WAAa,aAAa,SAAU,aAAa,MAAS,QAAO;AACpG,aAAO,OAAO,cAAc,SAAS;IACvC;AACA,QAAI,YAAY,OAAW,QAAO;AAClC,WAAO;EACT,CAAC;AACH;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowi/plugin-api",
3
- "version": "1.0.0-alpha.3",
3
+ "version": "1.0.0-alpha.5",
4
4
  "description": "Type-only contract for Crowi 2.0 plugins. See docs/rfcs/0001-plugin-architecture.md.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,14 +31,18 @@
31
31
  "devDependencies": {
32
32
  "@types/jest": "^29.5.14",
33
33
  "@types/node": "^24",
34
- "hono": "^4.12.25",
34
+ "hono": "^4.12.31",
35
35
  "jest": "^29.7.0",
36
36
  "ts-jest": "^29.3.4",
37
37
  "tsup": "^8.3.5",
38
38
  "typescript": "^5.8.3",
39
39
  "zod": "^4.4.3",
40
+ "@crowi/svg-sanitize": "0.1.0-alpha.1",
40
41
  "@crowi/tsconfig": "0.1.0-alpha.0"
41
42
  },
43
+ "dependencies": {
44
+ "@xmldom/xmldom": "^0.9.10"
45
+ },
42
46
  "scripts": {
43
47
  "build": "tsup",
44
48
  "dev": "tsup --watch --no-clean",