@manifest-configuration-language/browser 0.1.5 → 0.1.6

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/mcl.wasm CHANGED
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/dist/mcl.wasm
3
- size: 96219377 bytes
4
- sha256: 285f6bf9e6c1720d4db98f9aeedcf0d751e8ef33a5f7a3b2d2d2c501c9f12a9d
3
+ size: 96170429 bytes
4
+ sha256: d08ad3914d8a2862e52db7dbc3ec43c38c1143dea99dda6c87383c7d59212c7d
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manifest-configuration-language/browser",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Run MCL projects in a browser Web Worker using the Go WebAssembly runtime.",
5
5
  "repository": {
6
6
  "type": "git",
package/src/index.d.ts CHANGED
@@ -24,6 +24,9 @@ export declare const maxSourceBytes: number;
24
24
  export declare const maxProjectFiles: number;
25
25
  export declare const maxProjectFileBytes: number;
26
26
  export declare const maxProjectBytes: number;
27
+ export declare const maxProjectPathLength: number;
28
+ export declare const maxProjectPathDepth: number;
29
+ export declare function isValidProjectPath(path: unknown): path is string;
27
30
 
28
31
  /** Root-relative project files passed to MCL's per-request filesystem. Uint8Array values are copied before transfer so callers can reuse them. */
29
32
  export type ProjectFile = string | Uint8Array;
package/src/index.js CHANGED
@@ -1,6 +1,27 @@
1
- import { maxProjectBytes, maxProjectFileBytes, maxProjectFiles, maxSourceBytes } from "./limits.js";
1
+ import {
2
+ maxProjectBytes,
3
+ maxProjectFileBytes,
4
+ maxProjectFiles,
5
+ maxProjectPathDepth,
6
+ maxProjectPathLength,
7
+ maxSourceBytes,
8
+ } from "./limits.js";
2
9
 
3
- export { maxProjectBytes, maxProjectFileBytes, maxProjectFiles, maxSourceBytes };
10
+ export { maxProjectBytes, maxProjectFileBytes, maxProjectFiles, maxProjectPathDepth, maxProjectPathLength, maxSourceBytes };
11
+
12
+ export function isValidProjectPath(value) {
13
+ if (typeof value !== "string" || value.length === 0 || value.startsWith("/") ||
14
+ /^[a-z]:/i.test(value) || value.includes("\\") || value.includes("\0")) {
15
+ return false;
16
+ }
17
+ let pathLength = 0;
18
+ let pathDepth = 1;
19
+ for (const character of value) {
20
+ if (++pathLength > maxProjectPathLength) return false;
21
+ if (character === "/" && ++pathDepth > maxProjectPathDepth) return false;
22
+ }
23
+ return value.split("/").every((part) => part !== "" && part !== "." && part !== "..");
24
+ }
4
25
 
5
26
  const defaultInitializationTimeoutMs = 30_000;
6
27
  const defaultOperationTimeoutMs = 10_000;
@@ -113,7 +134,8 @@ export function createMclRuntime(options = {}) {
113
134
  try {
114
135
  if (timeoutMs <= 0) throw timeoutError;
115
136
  timer = setTimeout(() => {
116
- (stopCurrent ?? stopInitialization)?.(timeoutError);
137
+ if (stopCurrent) stopCurrent(timeoutError);
138
+ else stopInitialization?.(timeoutError);
117
139
  }, timeoutMs);
118
140
  await waitUntilReady(requestOptions.signal);
119
141
  if (requestOptions.signal?.aborted) throw new DOMException("The operation was aborted", "AbortError");
@@ -258,7 +280,7 @@ export function createMclRuntime(options = {}) {
258
280
  }
259
281
 
260
282
  function isSafeRelativePath(filePath) {
261
- return typeof filePath === "string" && filePath.length > 0 && !/^[a-z]:/i.test(filePath) && !filePath.startsWith("/") && !filePath.includes("\\") && filePath.split("/").every((part) => part && part !== "." && part !== "..");
283
+ return isValidProjectPath(filePath);
262
284
  }
263
285
 
264
286
  function prepareFilesForTransfer(source, files, entrypoint) {
package/src/limits.js CHANGED
@@ -5,3 +5,5 @@ export const maxProjectFileBytes = 16777216;
5
5
  export const maxProjectBytes = 67108864;
6
6
  export const maxOutputBytes = 1048576;
7
7
  export const evaluationTimeoutMillis = 4000;
8
+ export const maxProjectPathLength = 512;
9
+ export const maxProjectPathDepth = 64;
package/src/protocol.d.ts CHANGED
@@ -6,10 +6,7 @@ export type Request = {
6
6
  revision?: number;
7
7
  operation: "parse" | "lint" | "format" | "check" | "evaluate" | "render" | "completion" | "definition" | "hover";
8
8
  position?: CompletionPosition;
9
- /**
10
- * Project-relative MCL source path. Defaults to main.mcl.
11
- */
12
- entrypoint?: string;
9
+ entrypoint?: ProjectPath;
13
10
  /**
14
11
  * UTF-8 entrypoint source, limited by the runtime.
15
12
  */
@@ -21,6 +18,10 @@ export type Request = {
21
18
  [k: string]: FileInput;
22
19
  };
23
20
  };
21
+ /**
22
+ * Project-relative MCL source path. Defaults to main.mcl.
23
+ */
24
+ export type ProjectPath = string;
24
25
  /**
25
26
  * Binary files omit content and are supplied in the optional second run argument under the same path.
26
27
  */