@hyperframes/core 0.9.31 → 0.9.33

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.
@@ -41,6 +41,8 @@
41
41
  * differ from the preview, which is the more dangerous of the two directions.
42
42
  */
43
43
  export declare function sanitizeCssValue(value: string): string;
44
+ /** The src `values` bind to `el` through its `data-var-src`, or null when nothing safe is bound. */
45
+ export declare function boundMediaSrc(el: Element, values: Record<string, unknown>, warn?: boolean): string | null;
44
46
  /** The src an element loads, preview proxy aside: its bound variable's value, else its attribute. */
45
47
  export declare function unproxiedMediaSrc(el: Element): string | null;
46
48
  /** Applies the bindings in `doc`, or only those inside `within` and `within` itself. */
@@ -129,7 +129,8 @@ function applyCssCustomProperties(roots, cache) {
129
129
  }
130
130
  }
131
131
  }
132
- function variableSrcFor(el, cache, warn = true) {
132
+ /** The src `values` bind to `el` through its `data-var-src`, or null when nothing safe is bound. */
133
+ export function boundMediaSrc(el, values, warn = true) {
133
134
  const id = el.getAttribute("data-var-src")?.trim();
134
135
  if (!id)
135
136
  return null;
@@ -140,7 +141,7 @@ function variableSrcFor(el, cache, warn = true) {
140
141
  console.warn(`[hyperframes] Ignoring data-var-src on <${el.tagName.toLowerCase()}>: variable-bound src is only allowed on ${Array.from(VAR_SRC_TAGS).join("/")}.`);
141
142
  return null;
142
143
  }
143
- const url = resolveUrl(valuesForElement(el, cache)[id]);
144
+ const url = resolveUrl(values[id]);
144
145
  if (url === null)
145
146
  return null;
146
147
  if (!isSafeMediaUrl(url)) {
@@ -150,6 +151,9 @@ function variableSrcFor(el, cache, warn = true) {
150
151
  }
151
152
  return url;
152
153
  }
154
+ function variableSrcFor(el, cache, warn = true) {
155
+ return boundMediaSrc(el, valuesForElement(el, cache), warn);
156
+ }
153
157
  /** The src an element loads, preview proxy aside: its bound variable's value, else its attribute. */
154
158
  export function unproxiedMediaSrc(el) {
155
159
  return variableSrcFor(el, new Map(), false) ?? unproxiedSrc(el);
package/dist/safePath.js CHANGED
@@ -1,4 +1,4 @@
1
- import { resolve, sep, join, dirname, basename, relative, isAbsolute } from "node:path";
1
+ import { resolve, sep, join, dirname, basename, relative, isAbsolute, parse } from "node:path";
2
2
  import { lstatSync, mkdirSync, realpathSync, statSync } from "node:fs";
3
3
  export function realpath(path) {
4
4
  try {
@@ -25,6 +25,11 @@ function isMissingPath(path) {
25
25
  (error.code === "ENOENT" || error.code === "ENOTDIR"));
26
26
  }
27
27
  }
28
+ // On Windows even a realpath or lstat of a UNC or device path (\\host\share, \\?\, \\.\) connects to that host.
29
+ function namesAnotherNetworkRoot(base, target) {
30
+ const root = parse(target).root;
31
+ return /^[\\/]{2}/.test(root) && root.toLowerCase() !== parse(base).root.toLowerCase();
32
+ }
28
33
  /**
29
34
  * Reject paths that escape the `base` directory — including via symlinks.
30
35
  *
@@ -48,6 +53,9 @@ function isMissingPath(path) {
48
53
  * from there without a backwards edge.
49
54
  */
50
55
  export function isSafePath(base, resolved) {
56
+ const target = resolve(resolved);
57
+ if (namesAnotherNetworkRoot(resolve(base), target))
58
+ return false;
51
59
  let baseReal;
52
60
  try {
53
61
  baseReal = realpath(resolve(base));
@@ -56,7 +64,6 @@ export function isSafePath(base, resolved) {
56
64
  // Base must exist and be resolvable; fail closed if not.
57
65
  return false;
58
66
  }
59
- const target = resolve(resolved);
60
67
  const trailing = [];
61
68
  let probe = target;
62
69
  for (;;) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/core",
3
- "version": "0.9.31",
3
+ "version": "0.9.33",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -437,9 +437,9 @@
437
437
  "linkedom": "^0.18.12",
438
438
  "postcss": "^8.5.8",
439
439
  "wawoff2": "^2.0.1",
440
- "@hyperframes/lint": "0.9.31",
441
- "@hyperframes/parsers": "0.9.31",
442
- "@hyperframes/studio-server": "0.9.31"
440
+ "@hyperframes/lint": "0.9.33",
441
+ "@hyperframes/studio-server": "0.9.33",
442
+ "@hyperframes/parsers": "0.9.33"
443
443
  },
444
444
  "devDependencies": {
445
445
  "@fontsource/archivo-black": "^5.2.8",