@getforma/core 1.0.9 → 1.0.10

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.
@@ -1116,7 +1116,35 @@ var FormaRuntime = (() => {
1116
1116
  };
1117
1117
  }
1118
1118
 
1119
+ // src/security/url-safety.ts
1120
+ var URL_IGNORED_CHARS_RE = /[\u0000-\u0020\u007F-\u009F]/g;
1121
+ var DANGEROUS_SCHEME_RE = /^(?:javascript|vbscript|data:text\/html)/i;
1122
+ var URL_ATTRS = /* @__PURE__ */ new Set([
1123
+ "href",
1124
+ "src",
1125
+ "action",
1126
+ "formaction",
1127
+ "xlink:href",
1128
+ "poster",
1129
+ "background"
1130
+ ]);
1131
+ function isUrlAttr(name) {
1132
+ return URL_ATTRS.has(name.toLowerCase());
1133
+ }
1134
+ function isDangerousUrl(value2) {
1135
+ const normalized = value2.replace(URL_IGNORED_CHARS_RE, "");
1136
+ return DANGEROUS_SCHEME_RE.test(normalized);
1137
+ }
1138
+ function isEventHandlerAttr(name) {
1139
+ return /^on/i.test(name);
1140
+ }
1141
+
1119
1142
  // src/runtime.ts
1143
+ function isUnsafeAttrBinding(name, value2) {
1144
+ if (isEventHandlerAttr(name)) return true;
1145
+ if (isUrlAttr(name) && isDangerousUrl(value2)) return true;
1146
+ return false;
1147
+ }
1120
1148
  var _refetchRegistry = /* @__PURE__ */ new Map();
1121
1149
  function $refetch(id) {
1122
1150
  const fn = _refetchRegistry.get(id);
@@ -2120,7 +2148,12 @@ var FormaRuntime = (() => {
2120
2148
  if (attr.value.includes("{item")) {
2121
2149
  const compiled = compileTemplate(attr.value);
2122
2150
  entries.push({ attr: attr.name, compiled });
2123
- node.setAttribute(attr.name, evaluateCompiledTemplate(compiled, item));
2151
+ const value2 = evaluateCompiledTemplate(compiled, item);
2152
+ if (isUnsafeAttrBinding(attr.name, value2)) {
2153
+ node.removeAttribute(attr.name);
2154
+ } else {
2155
+ node.setAttribute(attr.name, value2);
2156
+ }
2124
2157
  }
2125
2158
  }
2126
2159
  if (entries.length > 0) {
@@ -2962,7 +2995,12 @@ var FormaRuntime = (() => {
2962
2995
  if (val == null || val === false) {
2963
2996
  el.removeAttribute(attrName);
2964
2997
  } else {
2965
- el.setAttribute(attrName, String(val));
2998
+ const str = String(val);
2999
+ if (isUnsafeAttrBinding(attrName, str)) {
3000
+ el.removeAttribute(attrName);
3001
+ } else {
3002
+ el.setAttribute(attrName, str);
3003
+ }
2966
3004
  }
2967
3005
  });
2968
3006
  disposers.push(dispose);