crossnote 0.9.40 → 0.9.41

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/out/cli/index.cjs CHANGED
@@ -34949,12 +34949,108 @@ function buildMathJaxConfigScript(mathJaxConfig) {
34949
34949
 
34950
34950
  // src/renderers/wavedrom-source.ts
34951
34951
  var import_json52 = __toESM(require("json5"));
34952
+
34953
+ // src/lib/dangerous-urls.ts
34954
+ var DANGEROUS_URL_PATTERN = /^\s*(javascript|vbscript)\s*:|^\s*data\s*:\s*text\/html/i;
34955
+ var URL_ATTRIBUTES = [
34956
+ "href",
34957
+ "src",
34958
+ "action",
34959
+ "formaction",
34960
+ "xlink:href"
34961
+ ];
34962
+ function isDangerousUrl(value) {
34963
+ return DANGEROUS_URL_PATTERN.test(value);
34964
+ }
34965
+
34966
+ // src/renderers/wavedrom-source.ts
34967
+ var DANGEROUS_SVG_TAGS = /* @__PURE__ */ new Set([
34968
+ "script",
34969
+ "handler",
34970
+ // SVG Tiny 1.2 event scripting
34971
+ "listener",
34972
+ // SVG Tiny 1.2 event wiring
34973
+ "foreignobject",
34974
+ // switches to the HTML namespace inside SVG
34975
+ "iframe",
34976
+ "embed",
34977
+ "object",
34978
+ "applet",
34979
+ // SMIL animation elements: <animate attributeName="href" to="javascript:...">
34980
+ "animate",
34981
+ "animatemotion",
34982
+ "animatetransform",
34983
+ "set"
34984
+ ]);
34985
+ var TAG_NAME_PATTERN = /^[a-zA-Z][a-zA-Z0-9:._-]*$/;
34986
+ function isPlainObject(value) {
34987
+ return typeof value === "object" && value !== null && !Array.isArray(value);
34988
+ }
34989
+ function escapeXml(s) {
34990
+ return /[&<>"]/.test(s) ? s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;") : s;
34991
+ }
34992
+ function escapeAttrBag(attrs) {
34993
+ const out = {};
34994
+ for (const [key, val] of Object.entries(attrs)) {
34995
+ const escapedKey = /[&<>"]/.test(key) ? escapeXml(key) : key;
34996
+ out[escapedKey] = Array.isArray(val) ? val.map((v) => typeof v === "string" ? escapeXml(v) : v) : typeof val === "string" ? escapeXml(val) : val;
34997
+ }
34998
+ return out;
34999
+ }
35000
+ function sanitizeWavedromData(value, parentKey) {
35001
+ if (Array.isArray(value)) {
35002
+ const rawTag = value[0];
35003
+ const tag = typeof rawTag === "string" ? rawTag.toLowerCase() : null;
35004
+ if (tag !== null && DANGEROUS_SVG_TAGS.has(tag)) {
35005
+ if (isPlainObject(value[1]) || tag === "script" || tag === "handler") {
35006
+ return "";
35007
+ }
35008
+ }
35009
+ const bag = value[1];
35010
+ const isElement = tag !== null && (isPlainObject(bag) || TAG_NAME_PATTERN.test(tag));
35011
+ if (!isElement || parentKey === "data") {
35012
+ return value.map(
35013
+ (v) => Array.isArray(v) || isPlainObject(v) ? sanitizeWavedromData(v) : v
35014
+ );
35015
+ }
35016
+ const out = [rawTag];
35017
+ let i = 1;
35018
+ if (isPlainObject(bag)) {
35019
+ sanitizeWavedromData(bag);
35020
+ out.push(escapeAttrBag(bag));
35021
+ i = 2;
35022
+ }
35023
+ for (; i < value.length; i++) {
35024
+ const child = value[i];
35025
+ out.push(
35026
+ typeof child === "string" ? escapeXml(child) : sanitizeWavedromData(child)
35027
+ );
35028
+ }
35029
+ return out;
35030
+ }
35031
+ if (isPlainObject(value)) {
35032
+ for (const key of Object.keys(value)) {
35033
+ if (/^on/i.test(key)) {
35034
+ delete value[key];
35035
+ continue;
35036
+ }
35037
+ const attrValue = value[key];
35038
+ if (URL_ATTRIBUTES.includes(key.toLowerCase()) && typeof attrValue === "string" && isDangerousUrl(attrValue)) {
35039
+ delete value[key];
35040
+ continue;
35041
+ }
35042
+ value[key] = sanitizeWavedromData(attrValue, key);
35043
+ }
35044
+ }
35045
+ return value;
35046
+ }
34952
35047
  function normalizeWavedromSource(raw) {
34953
35048
  try {
34954
35049
  const data = import_json52.default.parse(raw);
34955
35050
  if (typeof data !== "object" || data === null || Array.isArray(data)) {
34956
35051
  return null;
34957
35052
  }
35053
+ sanitizeWavedromData(data);
34958
35054
  const json = JSON.stringify(data, (_key, value) => {
34959
35055
  if (typeof value === "number" && !Number.isFinite(value)) {
34960
35056
  throw new SyntaxError("WaveDrom data contains a non-finite number");
@@ -34968,10 +35064,8 @@ function normalizeWavedromSource(raw) {
34968
35064
  }
34969
35065
 
34970
35066
  // src/markdown-engine/sanitize.ts
34971
- var DANGEROUS_URL_PATTERN = /^\s*(javascript|vbscript)\s*:|^\s*data\s*:\s*text\/html/i;
34972
35067
  var DANGEROUS_TAGS = ["object", "embed", "applet"];
34973
35068
  var SAFE_SCRIPT_TYPES = /* @__PURE__ */ new Set(["wavedrom", "text/tikz"]);
34974
- var URL_ATTRIBUTES = ["href", "src", "action", "formaction", "xlink:href"];
34975
35069
  function sanitizeRenderedHTML($) {
34976
35070
  $(DANGEROUS_TAGS.join(", ")).remove();
34977
35071
  $("script").each((_, el) => {
@@ -35002,7 +35096,7 @@ function sanitizeRenderedHTML($) {
35002
35096
  delete attribs[attr];
35003
35097
  continue;
35004
35098
  }
35005
- if (URL_ATTRIBUTES.includes(attr.toLowerCase()) && DANGEROUS_URL_PATTERN.test(attribs[attr])) {
35099
+ if (URL_ATTRIBUTES.includes(attr.toLowerCase()) && isDangerousUrl(attribs[attr])) {
35006
35100
  delete attribs[attr];
35007
35101
  }
35008
35102
  }