@triflare/fx 2.3.0 → 2.3.1-alpha.2
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/package.json +1 -1
- package/product.yml +1 -1
- package/src/build.js +19 -4
- package/src/cli/commands/decompile.js +2 -0
- package/src/cli/run.js +9 -0
- package/src/config.js +49 -4
- package/src/dev.js +75 -1
- package/src/extensions.js +19 -6
- package/src/features.js +3 -0
- package/src/marketplace.js +44 -1
- package/src/package.js +32 -8
- package/src/project-path.js +111 -0
- package/src/vendor.js +91 -14
- package/vendor/pm-packager-dist/.fx-build.json +1 -1
- package/vendor/pm-vm-dist/.fx-build.json +2 -2
- package/vendor/pm-vm-dist/NOTICE +1 -1
- package/vendor/pm-vm-dist/dist/scratch-vm.js +1 -1
package/src/vendor.js
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
readExtensionDataUri,
|
|
24
24
|
resolveSource,
|
|
25
25
|
} from "./extensions.js";
|
|
26
|
+
import { externalFileAllowed, resolveProjectFile } from "./project-path.js";
|
|
26
27
|
import { sanitizeTerminalText } from "./terminal.js";
|
|
27
28
|
|
|
28
29
|
export const LOCK_FILENAME = "fx.lock";
|
|
@@ -245,9 +246,12 @@ function readLocalSource(entry, configDir) {
|
|
|
245
246
|
if (source == null) throw new VendorError("unsupported data URI");
|
|
246
247
|
return { buffer: Buffer.from(source, "utf8"), file: null };
|
|
247
248
|
}
|
|
248
|
-
const file =
|
|
249
|
-
|
|
250
|
-
|
|
249
|
+
const file = resolveProjectFile(
|
|
250
|
+
entry.source,
|
|
251
|
+
configDir,
|
|
252
|
+
`local extension ${JSON.stringify(entry.source)}`,
|
|
253
|
+
{ rootDir: configDir, allowOutside: externalFileAllowed() },
|
|
254
|
+
);
|
|
251
255
|
try {
|
|
252
256
|
return { buffer: fs.readFileSync(file), file };
|
|
253
257
|
} catch (error) {
|
|
@@ -281,24 +285,78 @@ function fetchOptions(etag, lastModified) {
|
|
|
281
285
|
}
|
|
282
286
|
|
|
283
287
|
/**
|
|
284
|
-
* Fetch an extension over HTTP.
|
|
288
|
+
* Fetch an extension over HTTP. When `allowedOrigins` is supplied, redirects
|
|
289
|
+
* are followed manually and every hop is checked, so a trusted URL cannot
|
|
290
|
+
* redirect a download to an arbitrary internal host.
|
|
291
|
+
*
|
|
285
292
|
* @returns {Promise<{buffer: Buffer, etag: string|null, lastModified: string|null, notModified: boolean}>}
|
|
286
293
|
*/
|
|
287
294
|
export async function fetchVendorSource(
|
|
288
295
|
source,
|
|
289
|
-
{ fetchImpl, etag, lastModified } = {},
|
|
296
|
+
{ fetchImpl, etag, lastModified, allowedOrigins, maxRedirects = 5 } = {},
|
|
290
297
|
) {
|
|
291
298
|
const fetchFn = fetchImpl || globalThis.fetch;
|
|
292
299
|
if (typeof fetchFn !== "function")
|
|
293
300
|
throw new VendorError("global fetch is unavailable");
|
|
301
|
+
const guarded = allowedOrigins && allowedOrigins.size > 0;
|
|
302
|
+
const assertAllowed = (url) => {
|
|
303
|
+
let parsed;
|
|
304
|
+
try {
|
|
305
|
+
parsed = new URL(url);
|
|
306
|
+
} catch (error) {
|
|
307
|
+
throw new VendorError(`Could not download ${source}: invalid URL`, {
|
|
308
|
+
cause: error,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
if (parsed.protocol !== "https:" || !allowedOrigins.has(parsed.origin))
|
|
312
|
+
throw new VendorError(
|
|
313
|
+
`Refusing to download ${source}: ${parsed.origin} is not an allowed marketplace origin`,
|
|
314
|
+
);
|
|
315
|
+
};
|
|
316
|
+
let target = source;
|
|
294
317
|
let response;
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
318
|
+
for (let hop = 0; hop <= maxRedirects; hop += 1) {
|
|
319
|
+
if (guarded) assertAllowed(target);
|
|
320
|
+
const init = guarded
|
|
321
|
+
? {
|
|
322
|
+
...(hop === 0 ? fetchOptions(etag, lastModified) : {}),
|
|
323
|
+
redirect: "manual",
|
|
324
|
+
}
|
|
325
|
+
: hop === 0
|
|
326
|
+
? fetchOptions(etag, lastModified)
|
|
327
|
+
: undefined;
|
|
328
|
+
try {
|
|
329
|
+
response = await fetchFn(target, init);
|
|
330
|
+
} catch (error) {
|
|
331
|
+
throw new VendorError(`Could not download ${source}: ${error.message}`, {
|
|
332
|
+
cause: error,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
if (
|
|
336
|
+
guarded &&
|
|
337
|
+
response.status >= 300 &&
|
|
338
|
+
response.status < 400 &&
|
|
339
|
+
response.headers?.get
|
|
340
|
+
) {
|
|
341
|
+
const location = response.headers.get("location");
|
|
342
|
+
if (!location)
|
|
343
|
+
throw new VendorError(
|
|
344
|
+
`Could not download ${source}: redirect has no location`,
|
|
345
|
+
);
|
|
346
|
+
try {
|
|
347
|
+
target = new URL(location, target).href;
|
|
348
|
+
} catch (error) {
|
|
349
|
+
throw new VendorError(
|
|
350
|
+
`Could not download ${source}: invalid redirect location`,
|
|
351
|
+
{ cause: error },
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
break;
|
|
301
357
|
}
|
|
358
|
+
if (guarded && response.status >= 300 && response.status < 400)
|
|
359
|
+
throw new VendorError(`Could not download ${source}: too many redirects`);
|
|
302
360
|
if (response.status === 304)
|
|
303
361
|
return {
|
|
304
362
|
buffer: null,
|
|
@@ -927,9 +985,26 @@ export function verifyVendor({ configDir, config } = {}) {
|
|
|
927
985
|
);
|
|
928
986
|
}
|
|
929
987
|
if (!entry.data) {
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
988
|
+
let sourceFile;
|
|
989
|
+
try {
|
|
990
|
+
sourceFile = resolveProjectFile(
|
|
991
|
+
entry.source,
|
|
992
|
+
configDir,
|
|
993
|
+
`local extension ${JSON.stringify(entry.source)}`,
|
|
994
|
+
{ rootDir: configDir, allowOutside: externalFileAllowed() },
|
|
995
|
+
);
|
|
996
|
+
} catch (error) {
|
|
997
|
+
problems.push(
|
|
998
|
+
`extension "${entry.name}": local source ${entry.source} was refused: ${error.message}`,
|
|
999
|
+
);
|
|
1000
|
+
results.push({
|
|
1001
|
+
name: entry.name,
|
|
1002
|
+
file,
|
|
1003
|
+
status: "unsafe-source",
|
|
1004
|
+
hash,
|
|
1005
|
+
});
|
|
1006
|
+
continue;
|
|
1007
|
+
}
|
|
933
1008
|
if (!fs.existsSync(sourceFile))
|
|
934
1009
|
problems.push(
|
|
935
1010
|
`extension "${entry.name}": local source ${entry.source} is missing`,
|
|
@@ -1243,6 +1318,8 @@ export async function loadVendorExtensions({
|
|
|
1243
1318
|
fetchImpl,
|
|
1244
1319
|
expectUnsandboxed,
|
|
1245
1320
|
reportUnmatchedUnsandboxed: false,
|
|
1321
|
+
// Vendor targets were checked against the vendor root above.
|
|
1322
|
+
allowOutside: true,
|
|
1246
1323
|
},
|
|
1247
1324
|
);
|
|
1248
1325
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scratch-vm",
|
|
3
3
|
"version": "0.2.0",
|
|
4
|
-
"commit": "
|
|
4
|
+
"commit": "752072fa6f460e9d24f1d512b8c5d162e7366fae",
|
|
5
5
|
"inputHash": "bb8f99fcce9f4ecdc563f11df5a0510dcc94c25d256c6931c7f1f113e0a1998b",
|
|
6
|
-
"builtAt": "2026-11-
|
|
6
|
+
"builtAt": "2026-11-30T18:40:26.860Z"
|
|
7
7
|
}
|
package/vendor/pm-vm-dist/NOTICE
CHANGED