sandboxedjs 0.2.6 → 0.2.7
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/browser-host.cjs +137 -0
- package/dist/browser-host.d.cts +12 -0
- package/dist/browser-host.d.ts +12 -0
- package/dist/browser-host.js +137 -0
- package/dist/egress.cjs +12 -1
- package/dist/egress.d.cts +33 -1
- package/dist/egress.d.ts +33 -1
- package/dist/egress.js +11 -2
- package/dist/index.cjs +169 -128
- package/dist/index.js +169 -128
- package/dist/worker-entry.js +58 -17
- package/package.json +1 -1
package/dist/worker-entry.js
CHANGED
|
@@ -7183,14 +7183,14 @@ var require_buffer = __commonJS({
|
|
|
7183
7183
|
} else {
|
|
7184
7184
|
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
|
|
7185
7185
|
for (i = byteOffset; i >= 0; i--) {
|
|
7186
|
-
let
|
|
7186
|
+
let found2 = true;
|
|
7187
7187
|
for (let j = 0; j < valLength; j++) {
|
|
7188
7188
|
if (read(arr, i + j) !== read(val, j)) {
|
|
7189
|
-
|
|
7189
|
+
found2 = false;
|
|
7190
7190
|
break;
|
|
7191
7191
|
}
|
|
7192
7192
|
}
|
|
7193
|
-
if (
|
|
7193
|
+
if (found2) return i;
|
|
7194
7194
|
}
|
|
7195
7195
|
}
|
|
7196
7196
|
return -1;
|
|
@@ -22060,23 +22060,23 @@ var CommonJsEngine = class {
|
|
|
22060
22060
|
const builtin = this.builtin(specifier);
|
|
22061
22061
|
if (builtin.found) return specifier;
|
|
22062
22062
|
if (specifier.startsWith("#")) {
|
|
22063
|
-
const
|
|
22064
|
-
if (
|
|
22063
|
+
const found2 = this.resolveImports(specifier, importer, kind);
|
|
22064
|
+
if (found2) return found2;
|
|
22065
22065
|
throw this.moduleNotFound(specifier, importer);
|
|
22066
22066
|
}
|
|
22067
22067
|
const baseDir = dirname(importer);
|
|
22068
22068
|
if (specifier.startsWith("/") || specifier.startsWith("./") || specifier.startsWith("../")) {
|
|
22069
22069
|
const resolved = specifier.startsWith("/") ? clean(specifier) : resolve(baseDir, specifier);
|
|
22070
|
-
const
|
|
22071
|
-
if (
|
|
22070
|
+
const found2 = this.resolvePath(resolved, kind);
|
|
22071
|
+
if (found2) return found2;
|
|
22072
22072
|
} else {
|
|
22073
22073
|
const aliased = this.aliasFor(specifier);
|
|
22074
22074
|
if (aliased) {
|
|
22075
22075
|
const substituted = this.resolvePackage(aliased, baseDir, kind);
|
|
22076
22076
|
if (substituted) return substituted;
|
|
22077
22077
|
}
|
|
22078
|
-
const
|
|
22079
|
-
if (
|
|
22078
|
+
const found2 = this.resolvePackage(specifier, baseDir, kind);
|
|
22079
|
+
if (found2) return found2;
|
|
22080
22080
|
}
|
|
22081
22081
|
throw this.moduleNotFound(specifier, importer);
|
|
22082
22082
|
}
|
|
@@ -22242,8 +22242,8 @@ ${code}
|
|
|
22242
22242
|
continue;
|
|
22243
22243
|
}
|
|
22244
22244
|
for (const target of targets ?? []) {
|
|
22245
|
-
const
|
|
22246
|
-
if (
|
|
22245
|
+
const found2 = this.resolvePath(resolve(root, target), kind);
|
|
22246
|
+
if (found2) return found2;
|
|
22247
22247
|
}
|
|
22248
22248
|
}
|
|
22249
22249
|
return null;
|
|
@@ -22252,8 +22252,8 @@ ${code}
|
|
|
22252
22252
|
for (const field of ENTRY_FIELDS[kind]) {
|
|
22253
22253
|
const value = manifest?.[field];
|
|
22254
22254
|
if (typeof value === "string") {
|
|
22255
|
-
const
|
|
22256
|
-
if (
|
|
22255
|
+
const found2 = this.resolvePath(resolve(root, value), kind);
|
|
22256
|
+
if (found2) return found2;
|
|
22257
22257
|
}
|
|
22258
22258
|
}
|
|
22259
22259
|
return this.resolveIndex(root);
|
|
@@ -22276,8 +22276,8 @@ ${code}
|
|
|
22276
22276
|
continue;
|
|
22277
22277
|
}
|
|
22278
22278
|
for (const target of targets ?? []) {
|
|
22279
|
-
const
|
|
22280
|
-
if (
|
|
22279
|
+
const found2 = target.startsWith(".") ? this.resolvePath(resolve(root, target), kind) : this.resolvePackage(target, root, kind);
|
|
22280
|
+
if (found2) return found2;
|
|
22281
22281
|
}
|
|
22282
22282
|
}
|
|
22283
22283
|
return null;
|
|
@@ -28281,10 +28281,50 @@ function isBrowser() {
|
|
|
28281
28281
|
}
|
|
28282
28282
|
function browserBlocked(hostname, message) {
|
|
28283
28283
|
return new Error(
|
|
28284
|
-
`${message} \u2014 the request to ${hostname} was blocked by the browser. A page can only read a response from a host that sends CORS headers, and most APIs send none.
|
|
28284
|
+
`${message} \u2014 the request to ${hostname} was blocked by the browser. A page can only read a response from a host that sends CORS headers, and most APIs send none. The container looks for a proxy to make the request for it and found none: mount \`handleEgressRequest\` from "sandboxedjs/egress" at /__sandboxedjs__/egress on this origin, or run \`npx sandboxedjs-egress\`, and it is used without further configuration (network: { proxy } names one somewhere else) \u2014 or run the container on a server.`
|
|
28285
28285
|
);
|
|
28286
28286
|
}
|
|
28287
28287
|
|
|
28288
|
+
// src/net/discover-egress.ts
|
|
28289
|
+
var EGRESS_PATH = "/__sandboxedjs__/egress";
|
|
28290
|
+
var EGRESS_MARKER = { sandboxedjs: "egress", protocol: 1 };
|
|
28291
|
+
var CLI_PORT = 4181;
|
|
28292
|
+
var found = null;
|
|
28293
|
+
var PROBE_TIMEOUT_MS = 1500;
|
|
28294
|
+
async function isEgress(url, fetchImpl) {
|
|
28295
|
+
const control = new AbortController();
|
|
28296
|
+
const timer = setTimeout(() => control.abort(), PROBE_TIMEOUT_MS);
|
|
28297
|
+
try {
|
|
28298
|
+
const answer2 = await fetchImpl(url, { method: "GET", signal: control.signal });
|
|
28299
|
+
if (!answer2.ok) return false;
|
|
28300
|
+
const payload = await answer2.json();
|
|
28301
|
+
return payload?.sandboxedjs === EGRESS_MARKER.sandboxedjs;
|
|
28302
|
+
} catch {
|
|
28303
|
+
return false;
|
|
28304
|
+
} finally {
|
|
28305
|
+
clearTimeout(timer);
|
|
28306
|
+
}
|
|
28307
|
+
}
|
|
28308
|
+
function candidates() {
|
|
28309
|
+
const origin = globalThis.location?.origin;
|
|
28310
|
+
const list = [];
|
|
28311
|
+
if (origin && /^https?:/.test(origin)) list.push(`${origin}${EGRESS_PATH}`);
|
|
28312
|
+
list.push(`http://127.0.0.1:${CLI_PORT}/`);
|
|
28313
|
+
return list;
|
|
28314
|
+
}
|
|
28315
|
+
async function discoverEgress(fetchImpl = fetch) {
|
|
28316
|
+
if (!isBrowser()) return null;
|
|
28317
|
+
if (!found) {
|
|
28318
|
+
found = (async () => {
|
|
28319
|
+
for (const candidate of candidates()) {
|
|
28320
|
+
if (await isEgress(candidate, fetchImpl)) return candidate;
|
|
28321
|
+
}
|
|
28322
|
+
return null;
|
|
28323
|
+
})();
|
|
28324
|
+
}
|
|
28325
|
+
return await found;
|
|
28326
|
+
}
|
|
28327
|
+
|
|
28288
28328
|
// src/net/policy.ts
|
|
28289
28329
|
function isLoopbackHostname(hostname) {
|
|
28290
28330
|
const host = hostname.replace(/^\[|\]$/g, "").toLowerCase();
|
|
@@ -28327,7 +28367,8 @@ function policedFetch(policy, fetchImpl) {
|
|
|
28327
28367
|
if (!outboundAllowed(policy, url)) {
|
|
28328
28368
|
throw Object.assign(new TypeError("fetch failed"), { cause: outboundBlockedError(url) });
|
|
28329
28369
|
}
|
|
28330
|
-
|
|
28370
|
+
const proxy = policy.proxy ?? await discoverEgress(fetchImpl);
|
|
28371
|
+
if (proxy) return await fetchThroughProxy(proxy, fetchImpl, input, init);
|
|
28331
28372
|
try {
|
|
28332
28373
|
return await fetchImpl(input, init);
|
|
28333
28374
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sandboxedjs",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "A Linux-like container that runs entirely inside Node.js — POSIX shell, ~140 coreutils, Node.js and Python runtimes, virtual filesystem and networking. No Docker, no VM, no native modules.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|