@ai-ecoverse/slicc-kernel 1.177.0 → 1.178.1

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/index.js CHANGED
@@ -1181,6 +1181,9 @@ function systemTimeZone(given, fallback) {
1181
1181
  }
1182
1182
  var MAX_SHIFT_MS = 3 * HOUR_MS;
1183
1183
 
1184
+ // src/kernel/net/transport.ts
1185
+ var FORBIDDEN_HEADER = "forbidden-header";
1186
+
1184
1187
  // src/kernel/net/ws-queue.ts
1185
1188
  var INBOUND_LIMIT = 16 * 1024 * 1024;
1186
1189
  var MESSAGE_LIMIT = 64 * 1024 * 1024;
@@ -1377,6 +1380,44 @@ function sentHeaders(headers, inPage) {
1377
1380
  if (inPage) out.delete("user-agent");
1378
1381
  return out;
1379
1382
  }
1383
+ var TRANSPORT_OWN = /* @__PURE__ */ new Set([
1384
+ "accept-encoding",
1385
+ "connection",
1386
+ "content-length",
1387
+ "expect",
1388
+ "host",
1389
+ "keep-alive",
1390
+ "te",
1391
+ "trailer",
1392
+ "transfer-encoding",
1393
+ "upgrade"
1394
+ ]);
1395
+ var PROBE = "http://forbidden-headers.invalid/";
1396
+ var filters;
1397
+ function platformFilters() {
1398
+ filters ??= !new Request(PROBE, { headers: [["cookie", "probe=1"]] }).headers.has("cookie");
1399
+ return filters;
1400
+ }
1401
+ function unsendableHeaders(url, names, hint) {
1402
+ const which = names.length > 1 ? "headers" : "header";
1403
+ return Object.assign(
1404
+ new Error(
1405
+ `fetch ${url} refused: the page's fetch can't send the request ${which} ${names.join(", ")}, so it was not sent${hint ? `: ${hint}` : ""}`
1406
+ ),
1407
+ { status: 502, code: "ENOTSUP", detail: FORBIDDEN_HEADER, headers: [...names] }
1408
+ );
1409
+ }
1410
+ function refuseUnsendable(url, out, hint) {
1411
+ if (!platformFilters()) return;
1412
+ const kept = new Request(PROBE, { headers: out }).headers;
1413
+ const refused2 = [];
1414
+ for (const name of new Set(out.keys())) {
1415
+ if (kept.has(name)) continue;
1416
+ if (TRANSPORT_OWN.has(name)) out.delete(name);
1417
+ else refused2.push(name);
1418
+ }
1419
+ if (refused2.length > 0) throw unsendableHeaders(url, refused2, hint);
1420
+ }
1380
1421
  function streamOf(body) {
1381
1422
  const it = body[Symbol.asyncIterator]();
1382
1423
  return new ReadableStream(
@@ -1405,6 +1446,7 @@ function fetchTransport(options = {}) {
1405
1446
  const headers = options.webSocketHeaders === true;
1406
1447
  const instance = options.redirect ?? "follow";
1407
1448
  const inPage = !options.fetch && "location" in globalThis;
1449
+ const refuse = (options.forbiddenHeaders ?? (options.fetch ? "send" : "refuse")) === "refuse";
1408
1450
  return {
1409
1451
  traits: {
1410
1452
  manualRedirects: instance === "manual",
@@ -1417,11 +1459,13 @@ function fetchTransport(options = {}) {
1417
1459
  },
1418
1460
  ...Socket ? { websocket: (request) => openWebSocket(Socket, request, headers) } : {},
1419
1461
  async fetch(request) {
1462
+ const sent = sentHeaders(request.headers, inPage);
1463
+ if (refuse) refuseUnsendable(request.url, sent, options.hint);
1420
1464
  let response;
1421
1465
  try {
1422
1466
  response = await send(request.url, {
1423
1467
  method: request.method,
1424
- headers: sentHeaders(request.headers, inPage),
1468
+ headers: sent,
1425
1469
  ...requestBody(request),
1426
1470
  signal: request.signal,
1427
1471
  redirect: request.redirect ?? instance,
@@ -1522,7 +1566,7 @@ function serveTransport(peer, transport, {
1522
1566
  message: e instanceof Error ? e.message : String(e),
1523
1567
  ...typeof status === "number" ? { status } : {},
1524
1568
  ...typeof code === "string" ? { code } : {},
1525
- ...detail === "transport" ? { detail } : {}
1569
+ ...detail === "transport" || detail === FORBIDDEN_HEADER ? { detail } : {}
1526
1570
  });
1527
1571
  };
1528
1572
  const uploads = uploadsFor(peer);
@@ -1692,7 +1736,7 @@ var TransportError = class extends Error {
1692
1736
  super(message);
1693
1737
  this.status = status;
1694
1738
  this.code = code;
1695
- this.detail = detail === "transport" ? detail : void 0;
1739
+ this.detail = detail === "transport" || detail === FORBIDDEN_HEADER ? detail : void 0;
1696
1740
  }
1697
1741
  };
1698
1742
  function unfollowed(redirect) {