agentschat-mcp 0.36.26 → 0.36.27

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.
@@ -933,9 +933,15 @@ function parse(toml, { maxDepth = 1000, integersAsBigInt } = {}) {
933
933
  */
934
934
 
935
935
  // codex/owner.ts
936
+ var OWNER_FORBIDDEN_KEYS = new Set([
937
+ "__proto__",
938
+ "prototype",
939
+ ...Object.getOwnPropertyNames(Object.prototype),
940
+ ...Object.getOwnPropertyNames(Object.prototype).map((k) => k.toLowerCase())
941
+ ]);
936
942
  function blockedServerHost(url) {
937
943
  const host = url.hostname.toLowerCase().replace(/\.+$/, "").replace(/^\[|\]$/g, "");
938
- if (!host || host === "0.0.0.0" || /^0\./.test(host) || host === "::" || host === "0:0:0:0:0:0:0:0" || /^169\.254\./.test(host) || host === "100.100.100.200" || host === "fd00:ec2::254" || host === "fd00:ec2:0:0:0:0:0:254" || host === "metadata" || host === "instance-data" || host === "metadata.google.internal" || host.endsWith(".metadata.google.internal") || host === "metadata.goog" || host.endsWith(".metadata.goog") || /^fe[89ab][0-9a-f]:/.test(host)) {
944
+ if (!host || host === "0.0.0.0" || /^0\./.test(host) || host === "::" || host === "0:0:0:0:0:0:0:0" || /^169\.254\./.test(host) || host === "100.100.100.200" || /^100\.(?:6[4-9]|[7-9]\d|1[01]\d|12[0-7])\.\d{1,3}\.\d{1,3}$/.test(host) || host === "fd00:ec2::254" || host === "fd00:ec2:0:0:0:0:0:254" || host === "metadata" || host === "instance-data" || host === "metadata.google.internal" || host.endsWith(".metadata.google.internal") || host === "metadata.goog" || host.endsWith(".metadata.goog") || /^fe[89ab][0-9a-f]:/.test(host)) {
939
945
  return true;
940
946
  }
941
947
  if (host.startsWith("::ffff:")) {
@@ -943,26 +949,44 @@ function blockedServerHost(url) {
943
949
  if (rawTail === "0:0" || rawTail === "0.0.0.0")
944
950
  return true;
945
951
  const tail = /^0:(?:[0-9a-f]{1,4}:|\d{1,3}\.)/.test(rawTail) ? rawTail.slice(2) : rawTail;
946
- if (tail === "0:0" || tail === "0.0.0.0" || /^0\./.test(tail) || /^[0-9a-f]{1,2}:[0-9a-f]{1,4}$/.test(tail) || /^127\./.test(tail) || /^7f[0-9a-f]{2}:/.test(tail) || /^169\.254\./.test(tail) || /^a9fe:/.test(tail) || tail === "100.100.100.200" || tail === "6464:64c8") {
952
+ if (tail === "0:0" || tail === "0.0.0.0" || /^0\./.test(tail) || /^[0-9a-f]{1,2}:[0-9a-f]{1,4}$/.test(tail) || /^127\./.test(tail) || /^7f[0-9a-f]{2}:/.test(tail) || /^169\.254\./.test(tail) || /^a9fe:/.test(tail) || tail === "100.100.100.200" || /^100\.(?:6[4-9]|[7-9]\d|1[01]\d|12[0-7])\.\d{1,3}\.\d{1,3}$/.test(tail) || tail === "6464:64c8") {
947
953
  return true;
948
954
  }
955
+ const hexMatch = tail.match(/^([0-9a-f]{1,4}):([0-9a-f]{1,4})$/);
956
+ if (hexMatch) {
957
+ const hi = parseInt(hexMatch[1], 16);
958
+ const lo = parseInt(hexMatch[2], 16);
959
+ const firstOctet = hi >> 8 & 255;
960
+ const secondOctet = hi & 255;
961
+ if (firstOctet === 0 || firstOctet === 127 || firstOctet === 169 && secondOctet === 254 || firstOctet === 100 && (secondOctet & 192) === 64 || hi === 25700 && lo === 25800) {
962
+ return true;
963
+ }
964
+ }
949
965
  }
950
966
  return false;
951
967
  }
952
968
 
953
969
  // codex/config.ts
954
970
  var CONTROL_CHAR_RE = /[\x00-\x1f\x7f-\x9f\u2028\u2029]/;
971
+ var PROTO_KEY_RE = /^(?:__proto__|constructor|prototype)$/i;
972
+ var RESERVED_OBJECT_STEMS = new Set([
973
+ "__proto__",
974
+ "constructor",
975
+ "prototype",
976
+ ...Object.getOwnPropertyNames(Object.prototype).map((k) => k.toLowerCase())
977
+ ]);
978
+ var WINDOWS_DEVICE_STEM_RE = /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])$/i;
955
979
  function reasoningEffort(value) {
956
980
  if (value === undefined)
957
981
  return;
958
- if (typeof value !== "string" || !value.trim() || CONTROL_CHAR_RE.test(value))
982
+ if (typeof value !== "string" || !value.trim() || value.trim().length > 64 || CONTROL_CHAR_RE.test(value) || PROTO_KEY_RE.test(value.trim()))
959
983
  throw new Error("effort must be a nonempty model-supported reasoning effort name");
960
984
  return value.trim();
961
985
  }
962
986
  function modelName(value) {
963
987
  if (value === undefined)
964
988
  return;
965
- if (typeof value !== "string" || !value.trim() || CONTROL_CHAR_RE.test(value))
989
+ if (typeof value !== "string" || !value.trim() || value.trim().length > 256 || CONTROL_CHAR_RE.test(value) || PROTO_KEY_RE.test(value.trim()))
966
990
  throw new Error("model must be a nonempty model ID");
967
991
  return value.trim();
968
992
  }
@@ -982,10 +1006,8 @@ function codexHomeMode(value) {
982
1006
  }
983
1007
  var MAX_CONFIG_BYTES = 1048576;
984
1008
  function reservedProfileStem(selector) {
985
- return [
986
- "__proto__",
987
- "constructor",
988
- "prototype",
1009
+ const stem = selector.replace(/\.json$/i, "").toLowerCase();
1010
+ return RESERVED_OBJECT_STEMS.has(stem) || WINDOWS_DEVICE_STEM_RE.test(stem) || [
989
1011
  "grok-binds",
990
1012
  "session-binds",
991
1013
  "agy-binds",
@@ -994,7 +1016,7 @@ function reservedProfileStem(selector) {
994
1016
  "wake-pids",
995
1017
  "config",
996
1018
  "codex-bots"
997
- ].includes(selector.replace(/\.json$/i, "").toLowerCase());
1019
+ ].includes(stem);
998
1020
  }
999
1021
  function checkSingleAncestorDir(path) {
1000
1022
  const stat = lstatSync(path, { throwIfNoEntry: false });
@@ -1233,8 +1255,9 @@ function loadBots(file = defaultRegistry(), home = homedir2()) {
1233
1255
  if (!object(x) || Object.getOwnPropertyNames(x).some((k) => !keys.includes(k)))
1234
1256
  throw new Error("Unknown or invalid bot registry field");
1235
1257
  };
1236
- const text = (x) => typeof x === "string" && x.trim().length > 0 && !/[\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(x);
1237
- const reserved = (s) => ["__proto__", "constructor", "prototype"].includes(s.toLowerCase());
1258
+ const text = (x, max = 4096) => typeof x === "string" && x.trim().length > 0 && x.length <= max && !/[\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(x);
1259
+ const reservedNames = new Set(["__proto__", "constructor", "prototype", ...Object.getOwnPropertyNames(Object.prototype).map((k) => k.toLowerCase())]);
1260
+ const reserved = (s) => reservedNames.has(s.toLowerCase());
1238
1261
  fields(doc, ["version", "default_workdir", "codex_bin", "bots"]);
1239
1262
  if (doc.version !== 1 || !Array.isArray(doc.bots) || doc.bots.length > 128)
1240
1263
  throw new Error("Registry requires version 1 and bots array");
@@ -1480,14 +1503,16 @@ function start(w, spawnWorker = spawn) {
1480
1503
  } catch {}
1481
1504
  });
1482
1505
  let buffer = "";
1506
+ const escapedAgentId = w.config.agentId.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1507
+ const connectedRe = new RegExp(`(?:^|[\\r\\n])AgentsChat connected as ${escapedAgentId}(?![A-Za-z0-9_.-])`);
1483
1508
  child.stderr?.on("data", (data) => {
1484
1509
  buffer = (buffer + String(data)).slice(-8192);
1485
- if (buffer.includes(`AgentsChat connected as ${w.config.agentId}`)) {
1510
+ if (connectedRe.test(buffer)) {
1486
1511
  w.status = "connected";
1487
1512
  w.failures = 0;
1488
1513
  buffer = "";
1489
1514
  save();
1490
- } else if (buffer.includes("disconnected")) {
1515
+ } else if (/(?:^|[\r\n]).*\bdisconnected\b/i.test(buffer)) {
1491
1516
  w.status = "reconnecting";
1492
1517
  buffer = "";
1493
1518
  save();
@@ -1567,7 +1592,7 @@ Watch polls external Codex processes every 5 seconds.`);
1567
1592
  if (stat.isSymbolicLink() || !stat.isFile() || stat.size > 1048576)
1568
1593
  throw new Error("Unsafe status file");
1569
1594
  const raw = readFileSync3(statusFile, "utf8"), status = JSON.parse(raw);
1570
- if (!status || typeof status !== "object" || Array.isArray(status) || Object.prototype.hasOwnProperty.call(status, "__proto__"))
1595
+ if (!status || typeof status !== "object" || Array.isArray(status) || Object.prototype.hasOwnProperty.call(status, "__proto__") || status.pid !== undefined && (typeof status.pid !== "number" || !Number.isSafeInteger(status.pid) || status.pid <= 0) || !Array.isArray(status.bots) || status.bots.some((b) => !b || typeof b !== "object" || Array.isArray(b) || Object.prototype.hasOwnProperty.call(b, "__proto__")))
1571
1596
  throw new Error("Invalid status file");
1572
1597
  console.log(raw);
1573
1598
  } catch {
@@ -919,9 +919,16 @@ function parse(toml, { maxDepth = 1000, integersAsBigInt } = {}) {
919
919
  */
920
920
 
921
921
  // codex/owner.ts
922
+ var OWNER_FORBIDDEN_KEYS = new Set([
923
+ "__proto__",
924
+ "prototype",
925
+ ...Object.getOwnPropertyNames(Object.prototype),
926
+ ...Object.getOwnPropertyNames(Object.prototype).map((k) => k.toLowerCase())
927
+ ]);
928
+ var isOwnerForbiddenKey = (key) => OWNER_FORBIDDEN_KEYS.has(key) || OWNER_FORBIDDEN_KEYS.has(key.toLowerCase());
922
929
  function blockedServerHost(url) {
923
930
  const host = url.hostname.toLowerCase().replace(/\.+$/, "").replace(/^\[|\]$/g, "");
924
- if (!host || host === "0.0.0.0" || /^0\./.test(host) || host === "::" || host === "0:0:0:0:0:0:0:0" || /^169\.254\./.test(host) || host === "100.100.100.200" || host === "fd00:ec2::254" || host === "fd00:ec2:0:0:0:0:0:254" || host === "metadata" || host === "instance-data" || host === "metadata.google.internal" || host.endsWith(".metadata.google.internal") || host === "metadata.goog" || host.endsWith(".metadata.goog") || /^fe[89ab][0-9a-f]:/.test(host)) {
931
+ if (!host || host === "0.0.0.0" || /^0\./.test(host) || host === "::" || host === "0:0:0:0:0:0:0:0" || /^169\.254\./.test(host) || host === "100.100.100.200" || /^100\.(?:6[4-9]|[7-9]\d|1[01]\d|12[0-7])\.\d{1,3}\.\d{1,3}$/.test(host) || host === "fd00:ec2::254" || host === "fd00:ec2:0:0:0:0:0:254" || host === "metadata" || host === "instance-data" || host === "metadata.google.internal" || host.endsWith(".metadata.google.internal") || host === "metadata.goog" || host.endsWith(".metadata.goog") || /^fe[89ab][0-9a-f]:/.test(host)) {
925
932
  return true;
926
933
  }
927
934
  if (host.startsWith("::ffff:")) {
@@ -929,9 +936,19 @@ function blockedServerHost(url) {
929
936
  if (rawTail === "0:0" || rawTail === "0.0.0.0")
930
937
  return true;
931
938
  const tail = /^0:(?:[0-9a-f]{1,4}:|\d{1,3}\.)/.test(rawTail) ? rawTail.slice(2) : rawTail;
932
- if (tail === "0:0" || tail === "0.0.0.0" || /^0\./.test(tail) || /^[0-9a-f]{1,2}:[0-9a-f]{1,4}$/.test(tail) || /^127\./.test(tail) || /^7f[0-9a-f]{2}:/.test(tail) || /^169\.254\./.test(tail) || /^a9fe:/.test(tail) || tail === "100.100.100.200" || tail === "6464:64c8") {
939
+ if (tail === "0:0" || tail === "0.0.0.0" || /^0\./.test(tail) || /^[0-9a-f]{1,2}:[0-9a-f]{1,4}$/.test(tail) || /^127\./.test(tail) || /^7f[0-9a-f]{2}:/.test(tail) || /^169\.254\./.test(tail) || /^a9fe:/.test(tail) || tail === "100.100.100.200" || /^100\.(?:6[4-9]|[7-9]\d|1[01]\d|12[0-7])\.\d{1,3}\.\d{1,3}$/.test(tail) || tail === "6464:64c8") {
933
940
  return true;
934
941
  }
942
+ const hexMatch = tail.match(/^([0-9a-f]{1,4}):([0-9a-f]{1,4})$/);
943
+ if (hexMatch) {
944
+ const hi = parseInt(hexMatch[1], 16);
945
+ const lo = parseInt(hexMatch[2], 16);
946
+ const firstOctet = hi >> 8 & 255;
947
+ const secondOctet = hi & 255;
948
+ if (firstOctet === 0 || firstOctet === 127 || firstOctet === 169 && secondOctet === 254 || firstOctet === 100 && (secondOctet & 192) === 64 || hi === 25700 && lo === 25800) {
949
+ return true;
950
+ }
951
+ }
935
952
  }
936
953
  return false;
937
954
  }
@@ -966,7 +983,7 @@ async function ownerJson(response) {
966
983
  }
967
984
  async function getBotOwner(base, agentId, token, request = fetch) {
968
985
  try {
969
- if (!base || base !== base.trim() || /[\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(base) || !agentId || agentId !== agentId.trim() || /[\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(agentId) || /%(?:2e%2e|2f|5c|00)/i.test(agentId) || [".", "..", "__proto__", "constructor", "prototype"].includes(agentId.toLowerCase()) || /[\/\\\s]/.test(agentId) || !token || token !== token.trim() || /[\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(token))
986
+ if (!base || base !== base.trim() || /[\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(base) || !agentId || agentId !== agentId.trim() || /[\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(agentId) || /%(?:2e%2e|2f|5c|00)/i.test(agentId) || agentId === "." || agentId.includes("..") || isOwnerForbiddenKey(agentId) || /[\/\\\s]/.test(agentId) || !token || token !== token.trim() || /[\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(token))
970
987
  return null;
971
988
  const parsed = new URL(base);
972
989
  const loopback = ["127.0.0.1", "localhost", "[::1]", "::1"].includes(parsed.hostname.toLowerCase().replace(/\.$/, ""));
@@ -1004,7 +1021,7 @@ async function getBotOwner(base, agentId, token, request = fetch) {
1004
1021
  if (!entitlement || typeof entitlement !== "object" || Array.isArray(entitlement) || Object.hasOwn(entitlement, "__proto__"))
1005
1022
  return null;
1006
1023
  const owner = entitlement.owner_account_id;
1007
- return typeof owner === "string" && owner.trim().length > 0 && owner === owner.trim() && !/[\/\\\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(owner) && !/%(?:2e%2e|2f|5c|00)/i.test(owner) && owner !== agentId && ![".", "..", "__proto__", "constructor", "prototype"].includes(owner.toLowerCase()) ? owner : null;
1024
+ return typeof owner === "string" && owner.trim().length > 0 && owner === owner.trim() && !/[\/\\\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(owner) && !/%(?:2e%2e|2f|5c|00)/i.test(owner) && owner !== agentId && owner !== "." && !owner.includes("..") && !isOwnerForbiddenKey(owner) ? owner : null;
1008
1025
  } catch {
1009
1026
  return null;
1010
1027
  }
@@ -1012,17 +1029,25 @@ async function getBotOwner(base, agentId, token, request = fetch) {
1012
1029
 
1013
1030
  // codex/config.ts
1014
1031
  var CONTROL_CHAR_RE = /[\x00-\x1f\x7f-\x9f\u2028\u2029]/;
1032
+ var PROTO_KEY_RE = /^(?:__proto__|constructor|prototype)$/i;
1033
+ var RESERVED_OBJECT_STEMS = new Set([
1034
+ "__proto__",
1035
+ "constructor",
1036
+ "prototype",
1037
+ ...Object.getOwnPropertyNames(Object.prototype).map((k) => k.toLowerCase())
1038
+ ]);
1039
+ var WINDOWS_DEVICE_STEM_RE = /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])$/i;
1015
1040
  function reasoningEffort(value) {
1016
1041
  if (value === undefined)
1017
1042
  return;
1018
- if (typeof value !== "string" || !value.trim() || CONTROL_CHAR_RE.test(value))
1043
+ if (typeof value !== "string" || !value.trim() || value.trim().length > 64 || CONTROL_CHAR_RE.test(value) || PROTO_KEY_RE.test(value.trim()))
1019
1044
  throw new Error("effort must be a nonempty model-supported reasoning effort name");
1020
1045
  return value.trim();
1021
1046
  }
1022
1047
  function modelName(value) {
1023
1048
  if (value === undefined)
1024
1049
  return;
1025
- if (typeof value !== "string" || !value.trim() || CONTROL_CHAR_RE.test(value))
1050
+ if (typeof value !== "string" || !value.trim() || value.trim().length > 256 || CONTROL_CHAR_RE.test(value) || PROTO_KEY_RE.test(value.trim()))
1026
1051
  throw new Error("model must be a nonempty model ID");
1027
1052
  return value.trim();
1028
1053
  }
@@ -1042,10 +1067,8 @@ function codexHomeMode(value) {
1042
1067
  }
1043
1068
  var MAX_CONFIG_BYTES = 1048576;
1044
1069
  function reservedProfileStem(selector) {
1045
- return [
1046
- "__proto__",
1047
- "constructor",
1048
- "prototype",
1070
+ const stem = selector.replace(/\.json$/i, "").toLowerCase();
1071
+ return RESERVED_OBJECT_STEMS.has(stem) || WINDOWS_DEVICE_STEM_RE.test(stem) || [
1049
1072
  "grok-binds",
1050
1073
  "session-binds",
1051
1074
  "agy-binds",
@@ -1054,7 +1077,7 @@ function reservedProfileStem(selector) {
1054
1077
  "wake-pids",
1055
1078
  "config",
1056
1079
  "codex-bots"
1057
- ].includes(selector.replace(/\.json$/i, "").toLowerCase());
1080
+ ].includes(stem);
1058
1081
  }
1059
1082
  function checkSingleAncestorDir(path) {
1060
1083
  const stat = lstatSync(path, { throwIfNoEntry: false });
@@ -1276,8 +1299,9 @@ function resolveConfig(opts, env = process.env, home = homedir()) {
1276
1299
  // codex/runtime-home.ts
1277
1300
  import { homedir as homedir2 } from "node:os";
1278
1301
  import { delimiter, isAbsolute as isAbsolute2, join as join2, relative, resolve as resolve2, sep } from "node:path";
1302
+ var RUNTIME_CTRL_RE = /[\x00-\x1f\x7f-\x9f\u2028\u2029]/;
1279
1303
  function executablePath(bin) {
1280
- if (!bin || /[\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(bin))
1304
+ if (!bin || RUNTIME_CTRL_RE.test(bin))
1281
1305
  return;
1282
1306
  const exts = process.platform === "win32" && !/\.[A-Za-z0-9]+$/.test(bin) ? ["", ...(process.env.PATHEXT ?? ".EXE;.CMD;.BAT;.COM").split(";").filter(Boolean)] : [""];
1283
1307
  const bases = isAbsolute2(bin) || bin.includes("/") || bin.includes("\\") ? [resolve2(bin)] : (process.env.PATH ?? "").split(delimiter).filter(Boolean).map((dir) => join2(dir, bin));
@@ -1336,12 +1360,20 @@ function assertIndependentTree(home, allowedAuthOrigin, codexExecutable) {
1336
1360
  function prepareRuntimeHome(stateDir, source = process.env.CODEX_HOME || join2(homedir2(), ".codex"), mode = "linked", codexBin = "codex") {
1337
1361
  if (mode !== "linked" && mode !== "isolated" && mode !== "auth-only")
1338
1362
  throw new Error("Invalid Codex home mode");
1363
+ if (typeof stateDir !== "string" || !stateDir.trim() || stateDir.length > 4096 || RUNTIME_CTRL_RE.test(stateDir)) {
1364
+ throw new Error("Invalid bot state directory");
1365
+ }
1339
1366
  if (mode === "isolated") {
1340
1367
  const home2 = join2(stateDir, "codex-home-isolated");
1341
1368
  prepareHomeDirectory(stateDir, home2);
1342
1369
  assertIndependentTree(home2, undefined, executablePath(codexBin));
1343
1370
  return { home: realpathSync2(home2) };
1344
1371
  }
1372
+ if (typeof source !== "string" || !source.trim() || source.length > 4096 || RUNTIME_CTRL_RE.test(source)) {
1373
+ throw new Error("Invalid Codex source home");
1374
+ }
1375
+ assertDirectoryLeaf(source, "Source Codex home");
1376
+ assertDirectoryAncestors(source);
1345
1377
  if (mode === "auth-only") {
1346
1378
  const legacyHome2 = realpathSync2(source);
1347
1379
  const origin = join2(legacyHome2, "auth.json");
@@ -1760,8 +1792,9 @@ function loadBots(file = defaultRegistry(), home = homedir3()) {
1760
1792
  if (!object(x) || Object.getOwnPropertyNames(x).some((k) => !keys.includes(k)))
1761
1793
  throw new Error("Unknown or invalid bot registry field");
1762
1794
  };
1763
- const text = (x) => typeof x === "string" && x.trim().length > 0 && !/[\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(x);
1764
- const reserved = (s) => ["__proto__", "constructor", "prototype"].includes(s.toLowerCase());
1795
+ const text = (x, max = 4096) => typeof x === "string" && x.trim().length > 0 && x.length <= max && !/[\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(x);
1796
+ const reservedNames = new Set(["__proto__", "constructor", "prototype", ...Object.getOwnPropertyNames(Object.prototype).map((k) => k.toLowerCase())]);
1797
+ const reserved = (s) => reservedNames.has(s.toLowerCase());
1765
1798
  fields(doc, ["version", "default_workdir", "codex_bin", "bots"]);
1766
1799
  if (doc.version !== 1 || !Array.isArray(doc.bots) || doc.bots.length > 128)
1767
1800
  throw new Error("Registry requires version 1 and bots array");
@@ -1911,6 +1944,10 @@ class ThreadBusyError extends Error {
1911
1944
  this.name = "ThreadBusyError";
1912
1945
  }
1913
1946
  }
1947
+ var APP_SERVER_CTRL_RE = /[\x00-\x1f\x7f-\x9f\u2028\u2029]/;
1948
+ function validThreadId(id) {
1949
+ return typeof id === "string" && id.trim().length > 0 && id.length <= 256 && !APP_SERVER_CTRL_RE.test(id);
1950
+ }
1914
1951
 
1915
1952
  class AppServer {
1916
1953
  bin;
@@ -1948,8 +1985,19 @@ class AppServer {
1948
1985
  return this.runtime?.home;
1949
1986
  }
1950
1987
  async start() {
1951
- if (this.model !== undefined && (typeof this.model !== "string" || !this.model.trim() || this.model.length > 256 || /[\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(this.model)))
1988
+ if (this.model !== undefined && (typeof this.model !== "string" || !this.model.trim() || this.model.length > 256 || APP_SERVER_CTRL_RE.test(this.model)))
1952
1989
  throw new Error("Invalid app-server model");
1990
+ if (this.runtime) {
1991
+ if (typeof this.runtime.home !== "string" || !this.runtime.home.trim() || this.runtime.home.length > 4096 || APP_SERVER_CTRL_RE.test(this.runtime.home) || this.runtime.legacyHome !== undefined && (typeof this.runtime.legacyHome !== "string" || !this.runtime.legacyHome.trim() || this.runtime.legacyHome.length > 4096 || APP_SERVER_CTRL_RE.test(this.runtime.legacyHome))) {
1992
+ throw new Error("Invalid app-server runtime home");
1993
+ }
1994
+ }
1995
+ if (this.toolIdentity) {
1996
+ const { profileFile, agentId, apiUrl, wsUrl } = this.toolIdentity;
1997
+ if ([profileFile, agentId, apiUrl, wsUrl].some((v) => typeof v !== "string" || !v.trim() || v.length > 4096 || APP_SERVER_CTRL_RE.test(v)) || agentId.length > 256) {
1998
+ throw new Error("Invalid app-server tool identity");
1999
+ }
2000
+ }
1953
2001
  const env = Object.fromEntries(Object.entries(process.env).filter(([k]) => !/^AGENTS?CHAT_|^RELAY_/.test(k)));
1954
2002
  env.AGENTSCHAT_LOCK_OWNER_PID = String(process.pid);
1955
2003
  env.AGENTSCHAT_TOOL_ONLY = "1";
@@ -2113,9 +2161,9 @@ class AppServer {
2113
2161
  }
2114
2162
  }
2115
2163
  async thread(cwd, existing, ephemeral = false, permissions = this.permissions) {
2116
- if (typeof cwd !== "string" || !cwd.trim() || cwd.length > 4096 || /[\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(cwd))
2164
+ if (typeof cwd !== "string" || !cwd.trim() || cwd.length > 4096 || APP_SERVER_CTRL_RE.test(cwd))
2117
2165
  throw new Error("Invalid app-server cwd");
2118
- if (existing !== undefined && (typeof existing !== "string" || !existing.trim() || existing.length > 256 || /[\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(existing)))
2166
+ if (existing !== undefined && !validThreadId(existing))
2119
2167
  throw new Error("Invalid app-server thread ID");
2120
2168
  const configured = existing ? this.threadPermissions.get(existing) : undefined;
2121
2169
  if (configured !== undefined && configured !== permissions) {
@@ -2144,6 +2192,8 @@ class AppServer {
2144
2192
  return r.thread.id;
2145
2193
  }
2146
2194
  async readThread(thread) {
2195
+ if (!validThreadId(thread))
2196
+ throw new Error("Invalid app-server thread ID");
2147
2197
  const result = await this.request("thread/read", { threadId: thread, includeTurns: true });
2148
2198
  if (result.thread?.id !== thread || !Array.isArray(result.thread.turns))
2149
2199
  throw new Error("Original thread history unavailable");
@@ -2152,6 +2202,8 @@ class AppServer {
2152
2202
  return { id: thread, createdAt: result.thread.createdAt, turns: result.thread.turns };
2153
2203
  }
2154
2204
  async readLegacyThread(thread) {
2205
+ if (!validThreadId(thread))
2206
+ throw new Error("Invalid app-server thread ID");
2155
2207
  if (!this.runtime?.legacyHome)
2156
2208
  return this.readThread(thread);
2157
2209
  const reader = new AppServer(this.bin, undefined, undefined, this.permissions, { home: this.runtime.legacyHome });
@@ -2163,6 +2215,10 @@ class AppServer {
2163
2215
  }
2164
2216
  }
2165
2217
  async nameThread(thread, name) {
2218
+ if (!validThreadId(thread))
2219
+ throw new Error("Invalid app-server thread ID");
2220
+ if (typeof name !== "string" || !name.trim() || name.length > 256 || APP_SERVER_CTRL_RE.test(name))
2221
+ throw new Error("Invalid app-server thread name");
2166
2222
  await this.request("thread/name/set", { threadId: thread, name });
2167
2223
  }
2168
2224
  async generate(thread, text, effort = this.effort) {
@@ -2267,11 +2323,18 @@ import { randomBytes as randomBytes2 } from "node:crypto";
2267
2323
  import { createHash as createHash2, randomBytes } from "node:crypto";
2268
2324
  import { chmodSync, lstatSync as lstatSync6, mkdirSync as mkdirSync4, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2 } from "node:fs";
2269
2325
  import { join as join6 } from "node:path";
2326
+ var HISTORY_FORBIDDEN_KEYS = new Set([
2327
+ "__proto__",
2328
+ "prototype",
2329
+ ...Object.getOwnPropertyNames(Object.prototype),
2330
+ ...Object.getOwnPropertyNames(Object.prototype).map((k) => k.toLowerCase())
2331
+ ]);
2332
+ var isHistoryForbiddenKey = (key) => HISTORY_FORBIDDEN_KEYS.has(key) || HISTORY_FORBIDDEN_KEYS.has(key.toLowerCase());
2270
2333
  function priorChannelThreads(threads, channel) {
2271
2334
  if (!threads || typeof threads !== "object" || typeof channel !== "string" || !channel)
2272
2335
  return [];
2273
2336
  return [...new Set(Object.entries(threads).filter(([key, id]) => {
2274
- if (["__proto__", "constructor", "prototype"].includes(key.toLowerCase()))
2337
+ if (isHistoryForbiddenKey(key))
2275
2338
  return false;
2276
2339
  if (typeof id !== "string" || !id.trim())
2277
2340
  return false;
@@ -2286,7 +2349,7 @@ function priorChannelThreads(threads, channel) {
2286
2349
  }).map(([, id]) => id))];
2287
2350
  }
2288
2351
  function preserveChannelHistory(directory, channel, histories, redact) {
2289
- if (typeof channel !== "string" || !channel.trim() || channel.length > 256 || /[\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(channel)) {
2352
+ if (typeof channel !== "string" || !channel.trim() || channel !== channel.trim() || channel.length > 256 || channel === "." || channel.includes("..") || /[\/\\\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(channel) || /%(?:2e%2e|2f|5c|00)/i.test(channel) || isHistoryForbiddenKey(channel)) {
2290
2353
  throw new Error("Invalid history channel");
2291
2354
  }
2292
2355
  const checkDirectory = (path) => {
@@ -2359,7 +2422,7 @@ function preserveChannelHistory(directory, channel, histories, redact) {
2359
2422
  try {
2360
2423
  let message = JSON.parse(text.slice(text.lastIndexOf(marker) + marker.length));
2361
2424
  if (message && typeof message === "object" && !Array.isArray(message)) {
2362
- message = Object.fromEntries(Object.entries(message).filter(([key]) => !["__proto__", "constructor", "prototype"].includes(key.toLowerCase())));
2425
+ message = Object.fromEntries(Object.entries(message).filter(([key]) => !isHistoryForbiddenKey(key)));
2363
2426
  if (message.channel_id === channel)
2364
2427
  records.push({ order, sequence: sequence++, value: { ...message, role: "user" } });
2365
2428
  continue;
@@ -2414,6 +2477,14 @@ End of historical context.
2414
2477
  // codex/loop-grants.ts
2415
2478
  import { lstatSync as lstatSync7, readFileSync as readFileSync6 } from "node:fs";
2416
2479
  import { join as join7 } from "node:path";
2480
+ var GRANT_FORBIDDEN_KEYS = new Set([
2481
+ "__proto__",
2482
+ "prototype",
2483
+ ...Object.getOwnPropertyNames(Object.prototype),
2484
+ ...Object.getOwnPropertyNames(Object.prototype).map((k) => k.toLowerCase())
2485
+ ]);
2486
+ var isGrantForbiddenKey = (key) => GRANT_FORBIDDEN_KEYS.has(key) || GRANT_FORBIDDEN_KEYS.has(key.toLowerCase());
2487
+ var ownProto = (value) => Boolean(value && typeof value === "object" && Object.prototype.hasOwnProperty.call(value, "__proto__"));
2417
2488
  function grants(config, opts) {
2418
2489
  try {
2419
2490
  const platform = opts?.platform ?? process.platform;
@@ -2430,11 +2501,10 @@ function grants(config, opts) {
2430
2501
  return [];
2431
2502
  }
2432
2503
  const doc = JSON.parse(readFileSync6(file, "utf8"));
2433
- const ownProto = (value) => Object.prototype.hasOwnProperty.call(value, "__proto__");
2434
2504
  if (doc?.version !== 1 || ownProto(doc) || !Array.isArray(doc.grants) || doc.grants.length > 256)
2435
2505
  return [];
2436
- const safeId = (value) => typeof value === "string" && value.length > 0 && value.length <= 128 && value.trim() === value && value !== "." && value !== ".." && !/[\/\\\s\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(value) && !/%(?:2e%2e|2f|5c|00)/i.test(value) && !["__proto__", "constructor", "prototype"].includes(value.toLowerCase());
2437
- const safeOwnerId = (value) => typeof value === "string" && value.length > 0 && value.length <= 254 && value.trim() === value && value !== "." && !value.includes("..") && !/[\/\\\s\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(value) && !/%(?:2e%2e|2f|5c|00)/i.test(value) && !["__proto__", "constructor", "prototype"].includes(value.toLowerCase());
2506
+ const safeId = (value) => typeof value === "string" && value.length > 0 && value.length <= 128 && value.trim() === value && value !== "." && !value.includes("..") && !/[\/\\\s\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(value) && !/%(?:2e%2e|2f|5c|00)/i.test(value) && !isGrantForbiddenKey(value);
2507
+ const safeOwnerId = (value) => typeof value === "string" && value.length > 0 && value.length <= 254 && value.trim() === value && value !== "." && !value.includes("..") && !/[\/\\\s\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(value) && !/%(?:2e%2e|2f|5c|00)/i.test(value) && !isGrantForbiddenKey(value);
2438
2508
  return doc.grants.filter((g) => g && !ownProto(g) && [g.loop_id, g.channel_id, g.agent_id, g.owner_id, g.prompt].every((v) => typeof v === "string" && v.trim()) && /^loop_[A-Za-z0-9_-]+$/.test(g.loop_id) && [g.loop_id, g.channel_id, g.agent_id].every(safeId) && safeOwnerId(g.owner_id) && g.agent_id === config.agentId && g.prompt.length <= 4000 && Number.isSafeInteger(g.interval_ms) && g.interval_ms >= 60000 && g.interval_ms <= 86400000);
2439
2509
  } catch {
2440
2510
  return [];
@@ -2466,7 +2536,7 @@ async function verifyLoopTick(raw, config, owner, list, opts) {
2466
2536
  if (rows.length !== 1)
2467
2537
  return null;
2468
2538
  const loop = rows[0];
2469
- if (!loop || loop.status !== "active" || loop.channel_id !== grant.channel_id || loop.prompt !== grant.prompt || loop.interval_ms !== grant.interval_ms || loop.expires_at !== null || loop.mode !== undefined && loop.mode !== "static" || !Number.isSafeInteger(loop.last_tick_at) || loop.last_tick_at <= 0 || !Number.isSafeInteger(loop.next_tick_ms) || loop.next_tick_ms !== raw.meta.next_tick_ms || loop.last_tick_at + grant.interval_ms !== loop.next_tick_ms)
2539
+ if (!loop || ownProto(loop) || loop.status !== "active" || loop.channel_id !== grant.channel_id || loop.prompt !== grant.prompt || loop.interval_ms !== grant.interval_ms || loop.expires_at !== null || loop.mode !== undefined && loop.mode !== "static" || !Number.isSafeInteger(loop.last_tick_at) || loop.last_tick_at <= 0 || !Number.isSafeInteger(loop.next_tick_ms) || loop.next_tick_ms !== raw.meta.next_tick_ms || loop.last_tick_at + grant.interval_ms !== loop.next_tick_ms)
2470
2540
  return null;
2471
2541
  const current = authorizedLoopTick(raw, config, opts);
2472
2542
  return current && current.owner_id === owner ? current : null;
@@ -2493,10 +2563,17 @@ import {
2493
2563
  import { dirname as dirname4, join as join8, resolve as resolve5 } from "path";
2494
2564
  var defaultWarn = (m) => process.stderr.write(m);
2495
2565
  var MAX_PROFILE_JSON_BYTES = 64 * 1024;
2566
+ var MAX_PROFILE_PATH_LEN = 4096;
2496
2567
  var CONTROL_CHAR_GLOBAL_RE = /[\x00-\x1f\x7f-\x9f\u2028\u2029]/g;
2568
+ var RESERVED_PROTO_STEMS = new Set([
2569
+ "__proto__",
2570
+ "constructor",
2571
+ "prototype",
2572
+ ...Object.getOwnPropertyNames(Object.prototype).map((k) => k.toLowerCase())
2573
+ ]);
2497
2574
  var DARWIN_SYSTEM_SYMLINKS = new Set(["/var", "/tmp", "/etc"]);
2498
2575
  function sanitizeWarnPart(value) {
2499
- return redactSecrets(String(value ?? "")).replace(/\b(https?:\/\/?)([^/\s@]*@)/gi, "$1[REDACTED]@").replace(/\b(?:Bearer|Basic)\s+[A-Za-z0-9._~+/=-]{8,}/gi, "[REDACTED]").replace(/\b(?:agent_key_|sk-|whsec_|rk_(?:live|test)_|gh[pousr]_|github_pat_|glpat-|xox[baprs]-|hf_|npm_|mr_|AIza|(?:AKIA|ASIA))[A-Za-z0-9_+/=.-]{8,}/g, "[REDACTED]").replace(CONTROL_CHAR_GLOBAL_RE, "?");
2576
+ return redactSecrets(String(value ?? "")).replace(/\b(https?:\/\/?)([^/\s@]*@)/gi, "$1[REDACTED]@").replace(/\b(?:Bearer|Basic)\s+[A-Za-z0-9._~+/=-]{8,}/gi, "[REDACTED]").replace(/(?:ac_|mcp_at_|mcp_rt_|mcp_|agent_key_|sk-|whsec_|rk_(?:live|test)_|gh[pousr]_|github_pat_|glpat-|xox[baprs]-|hf_|npm_|mr_|AIza|(?:AKIA|ASIA))[A-Za-z0-9_+/=.-]{8,}/g, "[REDACTED]").replace(CONTROL_CHAR_GLOBAL_RE, "?");
2500
2577
  }
2501
2578
  function safeLstat(target) {
2502
2579
  try {
@@ -2569,6 +2646,9 @@ function hasSafeAncestorDirs(targetPath) {
2569
2646
  return true;
2570
2647
  }
2571
2648
  function safeWriteProfile(path, data, warn = defaultWarn) {
2649
+ if (typeof path !== "string" || !path || path.length > MAX_PROFILE_PATH_LEN || path.includes("\x00")) {
2650
+ throw new Error(`Refusing to write profile into invalid path: ${sanitizeWarnPart(path)}`);
2651
+ }
2572
2652
  const parentDir = dirname4(path);
2573
2653
  const parentStat = safeLstat(parentDir);
2574
2654
  if (!parentStat || parentStat.isSymbolicLink() || !parentStat.isDirectory() || !hasSafeAncestorDirs(path)) {
@@ -2578,6 +2658,9 @@ function safeWriteProfile(path, data, warn = defaultWarn) {
2578
2658
  if (pathStat?.isSymbolicLink()) {
2579
2659
  throw new Error(`Refusing to write profile through symlink: ${sanitizeWarnPart(path)}`);
2580
2660
  }
2661
+ if (pathStat && !pathStat.isFile() && !pathStat.isDirectory()) {
2662
+ throw new Error(`Refusing to write profile into non-regular target: ${sanitizeWarnPart(path)}`);
2663
+ }
2581
2664
  const tmp = path + ".tmp";
2582
2665
  const tmpStat = safeLstat(tmp);
2583
2666
  if (tmpStat) {
@@ -2705,6 +2788,12 @@ var LOCK_FILE_MAX_BYTES = 64 * 1024;
2705
2788
  var LOCK_KEY_MAX_CHARS = 128;
2706
2789
  var SESSION_BINDS_MAX_BYTES = 1024 * 1024;
2707
2790
  var CONTROL_CHAR_RE2 = /[\x00-\x1f\x7f-\x9f\u2028\u2029]/;
2791
+ var UNSAFE_BIND_KEYS = new Set([
2792
+ "__proto__",
2793
+ "constructor",
2794
+ "prototype",
2795
+ ...Object.getOwnPropertyNames(Object.prototype).map((k) => k.toLowerCase())
2796
+ ]);
2708
2797
  var RESERVED_BIND_SIDECARS = new Set([
2709
2798
  "session-binds",
2710
2799
  "session-binds.meta",
@@ -2929,8 +3018,7 @@ function releaseAgentLock(opts) {
2929
3018
  }
2930
3019
  }
2931
3020
  function isUnsafeBindKey(key) {
2932
- const lower = key.toLowerCase();
2933
- return lower === "__proto__" || lower === "constructor" || lower === "prototype";
3021
+ return UNSAFE_BIND_KEYS.has(key.toLowerCase());
2934
3022
  }
2935
3023
  var DSH_HEALTH_MAX_BYTES = 256 * 1024;
2936
3024
 
@@ -2942,11 +3030,12 @@ function permitted(m, c) {
2942
3030
  return (!c.channels.length || c.channels.includes(m.channel_id)) && (!c.senders.length || c.senders.includes(m.sender_id));
2943
3031
  }
2944
3032
  var isPrototypeKey = (key) => /^(?:__proto__|constructor|prototype)$/i.test(key);
3033
+ var cleanBridgeLog = (text) => text.replace(/[\x00-\x1f\x7f-\x9f\u2028\u2029]+/g, " ");
2945
3034
  function isPlainObject(value) {
2946
3035
  return value !== null && typeof value === "object" && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
2947
3036
  }
2948
3037
  function safeMessageId(value) {
2949
- return typeof value === "string" && value.length > 0 && value.length <= 256 && value.trim() === value && value !== "." && value !== ".." && !/[\/\\\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(value) && !/%(?:2e%2e|2f|5c|00)/i.test(value) && !isPrototypeKey(value);
3038
+ return typeof value === "string" && value.length > 0 && value.length <= 256 && value.trim() === value && value !== "." && !value.includes("..") && !/[\/\\\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(value) && !/%(?:2e%2e|2f|5c|00)/i.test(value) && !isPrototypeKey(value);
2950
3039
  }
2951
3040
  function validMentions(value) {
2952
3041
  return value === undefined || Array.isArray(value) && value.length <= 128 && [...value].every((id) => typeof id === "string");
@@ -3040,7 +3129,7 @@ class Bridge {
3040
3129
  throw error;
3041
3130
  }
3042
3131
  this.state = hasState ? JSON.parse(readFileSync9(this.file, "utf8")) : { version: 1, threads: {}, entries: [] };
3043
- if (this.state?.version !== 1 || Object.prototype.hasOwnProperty.call(this.state, "__proto__") || !isPlainObject(this.state.threads) || !Array.isArray(this.state.entries) || Object.prototype.hasOwnProperty.call(this.state, "channels") && !isPlainObject(this.state.channels))
3132
+ if (this.state?.version !== 1 || Object.prototype.hasOwnProperty.call(this.state, "__proto__") || !isPlainObject(this.state.threads) || Object.prototype.hasOwnProperty.call(this.state.threads, "__proto__") || !Array.isArray(this.state.entries) || Object.prototype.hasOwnProperty.call(this.state, "channels") && (!isPlainObject(this.state.channels) || Object.prototype.hasOwnProperty.call(this.state.channels, "__proto__")))
3044
3133
  throw new Error("Invalid bridge state");
3045
3134
  for (const e of this.state.entries) {
3046
3135
  if (!isPlainObject(e) || Object.prototype.hasOwnProperty.call(e, "__proto__") || !entryStatuses.has(e.status) || !isPlainObject(e.message) || Object.prototype.hasOwnProperty.call(e.message, "__proto__") || ![e.message.id, e.message.channel_id, e.message.sender_id].every(safeMessageId) || typeof e.message.content !== "string" || !validMentions(e.message.mentions) || !validMentions(e.message.mentioned_ids))
@@ -3251,7 +3340,7 @@ AgentsChat message:
3251
3340
  delete e.answer;
3252
3341
  e.message.content = "";
3253
3342
  this.save();
3254
- this.log(`Scheduled skill completed quietly in ${JSON.stringify(chat)}`);
3343
+ this.log(cleanBridgeLog(`Scheduled skill completed quietly in ${JSON.stringify(chat)}`));
3255
3344
  continue;
3256
3345
  }
3257
3346
  e.status = "ready";
@@ -3266,7 +3355,7 @@ AgentsChat message:
3266
3355
  delete e.answer;
3267
3356
  e.message.content = "";
3268
3357
  this.save();
3269
- this.log(`Replied in ${JSON.stringify(e.message.channel_id)}`);
3358
+ this.log(cleanBridgeLog(`Replied in ${JSON.stringify(e.message.channel_id)}`));
3270
3359
  } catch (error) {
3271
3360
  if (error instanceof ThreadBusyError) {
3272
3361
  e.status = "pending";
@@ -3285,7 +3374,7 @@ AgentsChat message:
3285
3374
  e.error = this.redact(error instanceof Error ? error.message : "Bridge operation failed").slice(0, 240);
3286
3375
  e.status = e.status === "sending" ? "uncertain" : "failed";
3287
3376
  this.save();
3288
- this.log(`Message ${JSON.stringify(e.message.id)} ${e.status}; inspect private state before retrying`);
3377
+ this.log(cleanBridgeLog(`Message ${JSON.stringify(e.message.id)} ${e.status}; inspect private state before retrying`));
3289
3378
  } finally {
3290
3379
  this.activity(e.message.channel_id, false);
3291
3380
  }
@@ -3498,8 +3587,18 @@ function timestamp(value) {
3498
3587
  throw new Error("Invalid history timestamp");
3499
3588
  return normalized;
3500
3589
  }
3590
+ var INBOX_FORBIDDEN_KEYS = new Set([
3591
+ "__proto__",
3592
+ "prototype",
3593
+ ...Object.getOwnPropertyNames(Object.prototype),
3594
+ ...Object.getOwnPropertyNames(Object.prototype).map((k) => k.toLowerCase())
3595
+ ]);
3596
+ var isInboxForbiddenKey = (key) => INBOX_FORBIDDEN_KEYS.has(key) || INBOX_FORBIDDEN_KEYS.has(key.toLowerCase());
3501
3597
  function validChannel(channel) {
3502
- return typeof channel === "string" && channel.length > 0 && channel.length <= 128 && channel === channel.trim() && channel !== "." && !channel.includes("..") && !/[\/\\]/.test(channel) && !/%(?:2e%2e|2f|5c|00)/i.test(channel) && !/[\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(channel) && !["__proto__", "constructor", "prototype"].includes(channel.trim().toLowerCase());
3598
+ return typeof channel === "string" && channel.length > 0 && channel.length <= 128 && channel === channel.trim() && channel !== "." && !channel.includes("..") && !/[\/\\]/.test(channel) && !/%(?:2e%2e|2f|5c|00)/i.test(channel) && !/[\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(channel) && !isInboxForbiddenKey(channel);
3599
+ }
3600
+ function validHistoryMessageId(id) {
3601
+ return typeof id === "string" && id.length > 0 && id.length <= 256 && id === id.trim() && id !== "." && !id.includes("..") && !/[\/\\\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(id) && !/%(?:2e%2e|2f|5c|00)/i.test(id) && !isInboxForbiddenKey(id);
3503
3602
  }
3504
3603
  function validateChannel(channel) {
3505
3604
  if (!validChannel(channel))
@@ -3625,7 +3724,7 @@ class InboxSync {
3625
3724
  if (!Array.isArray(messages))
3626
3725
  throw new Error("Invalid history response");
3627
3726
  const rows = messages.map((m) => {
3628
- if (!m || m.channel_id !== channel || typeof m.id !== "string" || m.id.trim().length === 0 || /[\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(m.id))
3727
+ if (!m || typeof m !== "object" || Object.hasOwn(m, "__proto__") || m.channel_id !== channel || !validHistoryMessageId(m.id))
3629
3728
  throw new Error("Invalid history message");
3630
3729
  return { message: m, time: timestamp(m.timestamp) };
3631
3730
  }).sort((a, b) => a.time.localeCompare(b.time));
@@ -3662,8 +3761,15 @@ class InboxSync {
3662
3761
  }
3663
3762
 
3664
3763
  // codex/transport.ts
3764
+ var TRANSPORT_FORBIDDEN_KEYS = new Set([
3765
+ "__proto__",
3766
+ "prototype",
3767
+ ...Object.getOwnPropertyNames(Object.prototype),
3768
+ ...Object.getOwnPropertyNames(Object.prototype).map((k) => k.toLowerCase())
3769
+ ]);
3770
+ var cleanTransportLog = (value) => value.replace(/[\x00-\x1f\x7f-\x9f\u2028\u2029]+/g, " ");
3665
3771
  function safeChannel(channel) {
3666
- return typeof channel === "string" && channel.trim().length > 0 && channel === channel.trim() && channel.length <= 128 && !/[.\/\\\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(channel) && !/%(?:2e%2e|2f|5c|00)/i.test(channel) && !/^(?:__proto__|constructor|prototype)$/i.test(channel);
3772
+ return typeof channel === "string" && channel.trim().length > 0 && channel === channel.trim() && channel.length <= 128 && !/[.\/\\\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(channel) && !/%(?:2e%2e|2f|5c|00)/i.test(channel) && !TRANSPORT_FORBIDDEN_KEYS.has(channel) && !TRANSPORT_FORBIDDEN_KEYS.has(channel.toLowerCase());
3667
3773
  }
3668
3774
  function requireChannel(channel) {
3669
3775
  if (!safeChannel(channel))
@@ -3905,7 +4011,7 @@ class AgentsChatTransport {
3905
4011
  if (data.type === "auth_ok") {
3906
4012
  this.authenticated = true;
3907
4013
  this.delay = 1000;
3908
- this.log(`AgentsChat connected as ${this.config.agentId}`);
4014
+ this.log(cleanTransportLog(`AgentsChat connected as ${this.config.agentId}`));
3909
4015
  if (this.inboxSync && !this.syncTimer) {
3910
4016
  this.syncTimer = setInterval(() => {
3911
4017
  this.inboxSync.sync();
@@ -3930,11 +4036,14 @@ class AgentsChatTransport {
3930
4036
  }
3931
4037
  });
3932
4038
  } else if (data.type === "message_ack") {
3933
- const id = data.message_id ?? data.id, pending = this.pending.get(id);
3934
- if (pending) {
3935
- clearTimeout(pending.timer);
3936
- this.pending.delete(id);
3937
- pending.resolve();
4039
+ const id = data.message_id ?? data.id;
4040
+ if (typeof id === "string") {
4041
+ const pending = this.pending.get(id);
4042
+ if (pending) {
4043
+ clearTimeout(pending.timer);
4044
+ this.pending.delete(id);
4045
+ pending.resolve();
4046
+ }
3938
4047
  }
3939
4048
  } else if (data.type === "channel_created" && typeof data.channel_id === "string")
3940
4049
  join12(data.channel_id);