@buildanagent/harness 0.0.0-bootstrap.0 → 0.1.0-alpha.28

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.
Files changed (364) hide show
  1. package/LICENSE +54 -0
  2. package/LICENSE-APACHE +202 -0
  3. package/LICENSE-MIT +21 -0
  4. package/README.md +717 -0
  5. package/dist/ablation.d.ts +2 -0
  6. package/dist/ablation.js +3 -0
  7. package/dist/ablation.js.map +1 -0
  8. package/dist/completion/check.d.ts +64 -0
  9. package/dist/completion/check.js +152 -0
  10. package/dist/completion/check.js.map +1 -0
  11. package/dist/completion/checks.d.ts +45 -0
  12. package/dist/completion/checks.js +173 -0
  13. package/dist/completion/checks.js.map +1 -0
  14. package/dist/completion/flags.d.ts +25 -0
  15. package/dist/completion/flags.js +87 -0
  16. package/dist/completion/flags.js.map +1 -0
  17. package/dist/completion/index.d.ts +8 -0
  18. package/dist/completion/index.js +9 -0
  19. package/dist/completion/index.js.map +1 -0
  20. package/dist/completion/snapshot.d.ts +33 -0
  21. package/dist/completion/snapshot.js +83 -0
  22. package/dist/completion/snapshot.js.map +1 -0
  23. package/dist/context/cap.d.ts +32 -0
  24. package/dist/context/cap.js +50 -0
  25. package/dist/context/cap.js.map +1 -0
  26. package/dist/context/estimate.d.ts +18 -0
  27. package/dist/context/estimate.js +20 -0
  28. package/dist/context/estimate.js.map +1 -0
  29. package/dist/context/file-spill.d.ts +5 -0
  30. package/dist/context/file-spill.js +25 -0
  31. package/dist/context/file-spill.js.map +1 -0
  32. package/dist/context/index.d.ts +10 -0
  33. package/dist/context/index.js +10 -0
  34. package/dist/context/index.js.map +1 -0
  35. package/dist/context/mask.d.ts +27 -0
  36. package/dist/context/mask.js +71 -0
  37. package/dist/context/mask.js.map +1 -0
  38. package/dist/context/mid-turn.d.ts +40 -0
  39. package/dist/context/mid-turn.js +82 -0
  40. package/dist/context/mid-turn.js.map +1 -0
  41. package/dist/context/policy.d.ts +9 -0
  42. package/dist/context/policy.js +140 -0
  43. package/dist/context/policy.js.map +1 -0
  44. package/dist/context/spill-ledger.d.ts +25 -0
  45. package/dist/context/spill-ledger.js +54 -0
  46. package/dist/context/spill-ledger.js.map +1 -0
  47. package/dist/context/spill.d.ts +6 -0
  48. package/dist/context/spill.js +14 -0
  49. package/dist/context/spill.js.map +1 -0
  50. package/dist/context/summarize.d.ts +53 -0
  51. package/dist/context/summarize.js +204 -0
  52. package/dist/context/summarize.js.map +1 -0
  53. package/dist/context/summary-template.d.ts +29 -0
  54. package/dist/context/summary-template.js +69 -0
  55. package/dist/context/summary-template.js.map +1 -0
  56. package/dist/context/types.d.ts +150 -0
  57. package/dist/context/types.js +2 -0
  58. package/dist/context/types.js.map +1 -0
  59. package/dist/context/write-cap.d.ts +19 -0
  60. package/dist/context/write-cap.js +41 -0
  61. package/dist/context/write-cap.js.map +1 -0
  62. package/dist/create-harness.d.ts +7 -0
  63. package/dist/create-harness.js +21 -0
  64. package/dist/create-harness.js.map +1 -0
  65. package/dist/credentials/addresses.d.ts +14 -0
  66. package/dist/credentials/addresses.js +144 -0
  67. package/dist/credentials/addresses.js.map +1 -0
  68. package/dist/credentials/allowlist.d.ts +34 -0
  69. package/dist/credentials/allowlist.js +77 -0
  70. package/dist/credentials/allowlist.js.map +1 -0
  71. package/dist/credentials/egress-proxy.d.ts +70 -0
  72. package/dist/credentials/egress-proxy.js +482 -0
  73. package/dist/credentials/egress-proxy.js.map +1 -0
  74. package/dist/credentials/index.d.ts +9 -0
  75. package/dist/credentials/index.js +10 -0
  76. package/dist/credentials/index.js.map +1 -0
  77. package/dist/credentials/scrub.d.ts +16 -0
  78. package/dist/credentials/scrub.js +93 -0
  79. package/dist/credentials/scrub.js.map +1 -0
  80. package/dist/errors.d.ts +56 -0
  81. package/dist/errors.js +63 -0
  82. package/dist/errors.js.map +1 -0
  83. package/dist/extensions/compose.d.ts +27 -0
  84. package/dist/extensions/compose.js +83 -0
  85. package/dist/extensions/compose.js.map +1 -0
  86. package/dist/extensions/context-files-node.d.ts +28 -0
  87. package/dist/extensions/context-files-node.js +74 -0
  88. package/dist/extensions/context-files-node.js.map +1 -0
  89. package/dist/extensions/context-files.d.ts +68 -0
  90. package/dist/extensions/context-files.js +214 -0
  91. package/dist/extensions/context-files.js.map +1 -0
  92. package/dist/extensions/digest.d.ts +6 -0
  93. package/dist/extensions/digest.js +68 -0
  94. package/dist/extensions/digest.js.map +1 -0
  95. package/dist/extensions/index.d.ts +10 -0
  96. package/dist/extensions/index.js +10 -0
  97. package/dist/extensions/index.js.map +1 -0
  98. package/dist/extensions/load.d.ts +42 -0
  99. package/dist/extensions/load.js +211 -0
  100. package/dist/extensions/load.js.map +1 -0
  101. package/dist/extensions/lock.d.ts +8 -0
  102. package/dist/extensions/lock.js +95 -0
  103. package/dist/extensions/lock.js.map +1 -0
  104. package/dist/extensions/node.d.ts +10 -0
  105. package/dist/extensions/node.js +11 -0
  106. package/dist/extensions/node.js.map +1 -0
  107. package/dist/extensions/project-dirs.d.ts +24 -0
  108. package/dist/extensions/project-dirs.js +97 -0
  109. package/dist/extensions/project-dirs.js.map +1 -0
  110. package/dist/extensions/skills-node.d.ts +34 -0
  111. package/dist/extensions/skills-node.js +123 -0
  112. package/dist/extensions/skills-node.js.map +1 -0
  113. package/dist/extensions/skills.d.ts +51 -0
  114. package/dist/extensions/skills.js +175 -0
  115. package/dist/extensions/skills.js.map +1 -0
  116. package/dist/extensions/trust-file.d.ts +3 -0
  117. package/dist/extensions/trust-file.js +62 -0
  118. package/dist/extensions/trust-file.js.map +1 -0
  119. package/dist/extensions/trust-store-node.d.ts +10 -0
  120. package/dist/extensions/trust-store-node.js +33 -0
  121. package/dist/extensions/trust-store-node.js.map +1 -0
  122. package/dist/extensions/types.d.ts +42 -0
  123. package/dist/extensions/types.js +2 -0
  124. package/dist/extensions/types.js.map +1 -0
  125. package/dist/harness.d.ts +156 -0
  126. package/dist/harness.js +2 -0
  127. package/dist/harness.js.map +1 -0
  128. package/dist/index.d.ts +4 -0
  129. package/dist/index.js +5 -0
  130. package/dist/index.js.map +1 -0
  131. package/dist/mcp/connection.d.ts +22 -0
  132. package/dist/mcp/connection.js +267 -0
  133. package/dist/mcp/connection.js.map +1 -0
  134. package/dist/mcp/content.d.ts +27 -0
  135. package/dist/mcp/content.js +177 -0
  136. package/dist/mcp/content.js.map +1 -0
  137. package/dist/mcp/errors.d.ts +19 -0
  138. package/dist/mcp/errors.js +21 -0
  139. package/dist/mcp/errors.js.map +1 -0
  140. package/dist/mcp/index.d.ts +10 -0
  141. package/dist/mcp/index.js +10 -0
  142. package/dist/mcp/index.js.map +1 -0
  143. package/dist/mcp/manager.d.ts +7 -0
  144. package/dist/mcp/manager.js +173 -0
  145. package/dist/mcp/manager.js.map +1 -0
  146. package/dist/mcp/record.d.ts +7 -0
  147. package/dist/mcp/record.js +20 -0
  148. package/dist/mcp/record.js.map +1 -0
  149. package/dist/mcp/stdio.d.ts +39 -0
  150. package/dist/mcp/stdio.js +382 -0
  151. package/dist/mcp/stdio.js.map +1 -0
  152. package/dist/mcp/types.d.ts +172 -0
  153. package/dist/mcp/types.js +2 -0
  154. package/dist/mcp/types.js.map +1 -0
  155. package/dist/memory/index.d.ts +2 -0
  156. package/dist/memory/index.js +3 -0
  157. package/dist/memory/index.js.map +1 -0
  158. package/dist/permissions/default-rules.d.ts +7 -0
  159. package/dist/permissions/default-rules.js +42 -0
  160. package/dist/permissions/default-rules.js.map +1 -0
  161. package/dist/permissions/errors.d.ts +11 -0
  162. package/dist/permissions/errors.js +14 -0
  163. package/dist/permissions/errors.js.map +1 -0
  164. package/dist/permissions/index.d.ts +9 -0
  165. package/dist/permissions/index.js +9 -0
  166. package/dist/permissions/index.js.map +1 -0
  167. package/dist/permissions/match.d.ts +33 -0
  168. package/dist/permissions/match.js +287 -0
  169. package/dist/permissions/match.js.map +1 -0
  170. package/dist/permissions/pipeline.d.ts +9 -0
  171. package/dist/permissions/pipeline.js +235 -0
  172. package/dist/permissions/pipeline.js.map +1 -0
  173. package/dist/permissions/rules.d.ts +22 -0
  174. package/dist/permissions/rules.js +74 -0
  175. package/dist/permissions/rules.js.map +1 -0
  176. package/dist/permissions/shadow.d.ts +5 -0
  177. package/dist/permissions/shadow.js +22 -0
  178. package/dist/permissions/shadow.js.map +1 -0
  179. package/dist/permissions/types.d.ts +104 -0
  180. package/dist/permissions/types.js +2 -0
  181. package/dist/permissions/types.js.map +1 -0
  182. package/dist/sandbox/base.d.ts +35 -0
  183. package/dist/sandbox/base.js +60 -0
  184. package/dist/sandbox/base.js.map +1 -0
  185. package/dist/sandbox/docker/index.d.ts +35 -0
  186. package/dist/sandbox/docker/index.js +448 -0
  187. package/dist/sandbox/docker/index.js.map +1 -0
  188. package/dist/sandbox/errors.d.ts +16 -0
  189. package/dist/sandbox/errors.js +22 -0
  190. package/dist/sandbox/errors.js.map +1 -0
  191. package/dist/sandbox/host-files.d.ts +63 -0
  192. package/dist/sandbox/host-files.js +248 -0
  193. package/dist/sandbox/host-files.js.map +1 -0
  194. package/dist/sandbox/index.d.ts +8 -0
  195. package/dist/sandbox/index.js +8 -0
  196. package/dist/sandbox/index.js.map +1 -0
  197. package/dist/sandbox/none.d.ts +17 -0
  198. package/dist/sandbox/none.js +108 -0
  199. package/dist/sandbox/none.js.map +1 -0
  200. package/dist/sandbox/process.d.ts +61 -0
  201. package/dist/sandbox/process.js +253 -0
  202. package/dist/sandbox/process.js.map +1 -0
  203. package/dist/sandbox/spawn-env.d.ts +20 -0
  204. package/dist/sandbox/spawn-env.js +128 -0
  205. package/dist/sandbox/spawn-env.js.map +1 -0
  206. package/dist/sandbox/srt/index.d.ts +35 -0
  207. package/dist/sandbox/srt/index.js +264 -0
  208. package/dist/sandbox/srt/index.js.map +1 -0
  209. package/dist/sandbox/srt/settings.d.ts +48 -0
  210. package/dist/sandbox/srt/settings.js +31 -0
  211. package/dist/sandbox/srt/settings.js.map +1 -0
  212. package/dist/sandbox/types.d.ts +88 -0
  213. package/dist/sandbox/types.js +6 -0
  214. package/dist/sandbox/types.js.map +1 -0
  215. package/dist/server/answers.d.ts +16 -0
  216. package/dist/server/answers.js +43 -0
  217. package/dist/server/answers.js.map +1 -0
  218. package/dist/server/connection.d.ts +99 -0
  219. package/dist/server/connection.js +309 -0
  220. package/dist/server/connection.js.map +1 -0
  221. package/dist/server/dispatcher.d.ts +86 -0
  222. package/dist/server/dispatcher.js +800 -0
  223. package/dist/server/dispatcher.js.map +1 -0
  224. package/dist/server/index.d.ts +13 -0
  225. package/dist/server/index.js +12 -0
  226. package/dist/server/index.js.map +1 -0
  227. package/dist/server/local-transport.d.ts +44 -0
  228. package/dist/server/local-transport.js +103 -0
  229. package/dist/server/local-transport.js.map +1 -0
  230. package/dist/server/outbox.d.ts +31 -0
  231. package/dist/server/outbox.js +130 -0
  232. package/dist/server/outbox.js.map +1 -0
  233. package/dist/server/params.d.ts +25 -0
  234. package/dist/server/params.js +112 -0
  235. package/dist/server/params.js.map +1 -0
  236. package/dist/server/protocol.schema.json +2448 -0
  237. package/dist/server/rpc-session.d.ts +43 -0
  238. package/dist/server/rpc-session.js +167 -0
  239. package/dist/server/rpc-session.js.map +1 -0
  240. package/dist/server/stdio-streams.d.ts +67 -0
  241. package/dist/server/stdio-streams.js +218 -0
  242. package/dist/server/stdio-streams.js.map +1 -0
  243. package/dist/server/stdio.d.ts +59 -0
  244. package/dist/server/stdio.js +189 -0
  245. package/dist/server/stdio.js.map +1 -0
  246. package/dist/server/websocket.d.ts +106 -0
  247. package/dist/server/websocket.js +327 -0
  248. package/dist/server/websocket.js.map +1 -0
  249. package/dist/session/approvals.d.ts +81 -0
  250. package/dist/session/approvals.js +217 -0
  251. package/dist/session/approvals.js.map +1 -0
  252. package/dist/session/code-call-log.d.ts +42 -0
  253. package/dist/session/code-call-log.js +63 -0
  254. package/dist/session/code-call-log.js.map +1 -0
  255. package/dist/session/code-call-result.d.ts +19 -0
  256. package/dist/session/code-call-result.js +95 -0
  257. package/dist/session/code-call-result.js.map +1 -0
  258. package/dist/session/code-call.d.ts +49 -0
  259. package/dist/session/code-call.js +345 -0
  260. package/dist/session/code-call.js.map +1 -0
  261. package/dist/session/effect-scope.d.ts +11 -0
  262. package/dist/session/effect-scope.js +10 -0
  263. package/dist/session/effect-scope.js.map +1 -0
  264. package/dist/session/errors.d.ts +19 -0
  265. package/dist/session/errors.js +27 -0
  266. package/dist/session/errors.js.map +1 -0
  267. package/dist/session/file-index.d.ts +8 -0
  268. package/dist/session/file-index.js +70 -0
  269. package/dist/session/file-index.js.map +1 -0
  270. package/dist/session/file-key-store.d.ts +16 -0
  271. package/dist/session/file-key-store.js +169 -0
  272. package/dist/session/file-key-store.js.map +1 -0
  273. package/dist/session/file-lock.d.ts +52 -0
  274. package/dist/session/file-lock.js +324 -0
  275. package/dist/session/file-lock.js.map +1 -0
  276. package/dist/session/index.d.ts +22 -0
  277. package/dist/session/index.js +20 -0
  278. package/dist/session/index.js.map +1 -0
  279. package/dist/session/jsonl-store.d.ts +37 -0
  280. package/dist/session/jsonl-store.js +386 -0
  281. package/dist/session/jsonl-store.js.map +1 -0
  282. package/dist/session/jsonl.d.ts +9 -0
  283. package/dist/session/jsonl.js +10 -0
  284. package/dist/session/jsonl.js.map +1 -0
  285. package/dist/session/lock.d.ts +19 -0
  286. package/dist/session/lock.js +2 -0
  287. package/dist/session/lock.js.map +1 -0
  288. package/dist/session/memory-store.d.ts +12 -0
  289. package/dist/session/memory-store.js +60 -0
  290. package/dist/session/memory-store.js.map +1 -0
  291. package/dist/session/migrate.d.ts +41 -0
  292. package/dist/session/migrate.js +86 -0
  293. package/dist/session/migrate.js.map +1 -0
  294. package/dist/session/pointer.d.ts +15 -0
  295. package/dist/session/pointer.js +22 -0
  296. package/dist/session/pointer.js.map +1 -0
  297. package/dist/session/rebuild.d.ts +53 -0
  298. package/dist/session/rebuild.js +230 -0
  299. package/dist/session/rebuild.js.map +1 -0
  300. package/dist/session/resume.d.ts +26 -0
  301. package/dist/session/resume.js +128 -0
  302. package/dist/session/resume.js.map +1 -0
  303. package/dist/session/retention.d.ts +97 -0
  304. package/dist/session/retention.js +702 -0
  305. package/dist/session/retention.js.map +1 -0
  306. package/dist/session/runner.d.ts +156 -0
  307. package/dist/session/runner.js +656 -0
  308. package/dist/session/runner.js.map +1 -0
  309. package/dist/session/scheduler.d.ts +47 -0
  310. package/dist/session/scheduler.js +85 -0
  311. package/dist/session/scheduler.js.map +1 -0
  312. package/dist/session/secret-key-store.d.ts +47 -0
  313. package/dist/session/secret-key-store.js +79 -0
  314. package/dist/session/secret-key-store.js.map +1 -0
  315. package/dist/session/session.d.ts +106 -0
  316. package/dist/session/session.js +353 -0
  317. package/dist/session/session.js.map +1 -0
  318. package/dist/session/sticky.d.ts +48 -0
  319. package/dist/session/sticky.js +232 -0
  320. package/dist/session/sticky.js.map +1 -0
  321. package/dist/session/store.d.ts +108 -0
  322. package/dist/session/store.js +163 -0
  323. package/dist/session/store.js.map +1 -0
  324. package/dist/telemetry/index.d.ts +2 -0
  325. package/dist/telemetry/index.js +3 -0
  326. package/dist/telemetry/index.js.map +1 -0
  327. package/dist/testing/fake-sandbox.d.ts +34 -0
  328. package/dist/testing/fake-sandbox.js +221 -0
  329. package/dist/testing/fake-sandbox.js.map +1 -0
  330. package/dist/testing/index.d.ts +10 -0
  331. package/dist/testing/index.js +11 -0
  332. package/dist/testing/index.js.map +1 -0
  333. package/dist/testing/key-store-conformance.d.ts +22 -0
  334. package/dist/testing/key-store-conformance.js +97 -0
  335. package/dist/testing/key-store-conformance.js.map +1 -0
  336. package/dist/testing/run-cases.d.ts +21 -0
  337. package/dist/testing/run-cases.js +20 -0
  338. package/dist/testing/run-cases.js.map +1 -0
  339. package/dist/testing/sandbox-conformance.d.ts +64 -0
  340. package/dist/testing/sandbox-conformance.js +361 -0
  341. package/dist/testing/sandbox-conformance.js.map +1 -0
  342. package/dist/testing/scheduler-conformance.d.ts +32 -0
  343. package/dist/testing/scheduler-conformance.js +72 -0
  344. package/dist/testing/scheduler-conformance.js.map +1 -0
  345. package/dist/testing/store-conformance.d.ts +21 -0
  346. package/dist/testing/store-conformance.js +320 -0
  347. package/dist/testing/store-conformance.js.map +1 -0
  348. package/dist/tools/errors.d.ts +13 -0
  349. package/dist/tools/errors.js +17 -0
  350. package/dist/tools/errors.js.map +1 -0
  351. package/dist/tools/index.d.ts +8 -0
  352. package/dist/tools/index.js +8 -0
  353. package/dist/tools/index.js.map +1 -0
  354. package/dist/tools/registry.d.ts +3 -0
  355. package/dist/tools/registry.js +234 -0
  356. package/dist/tools/registry.js.map +1 -0
  357. package/dist/tools/tool-search.d.ts +30 -0
  358. package/dist/tools/tool-search.js +118 -0
  359. package/dist/tools/tool-search.js.map +1 -0
  360. package/dist/tools/types.d.ts +106 -0
  361. package/dist/tools/types.js +2 -0
  362. package/dist/tools/types.js.map +1 -0
  363. package/llms.txt +435 -0
  364. package/package.json +119 -5
@@ -0,0 +1,482 @@
1
+ /**
2
+ * `startEgressProxy()`: the host-side proxy that keeps credentials out of the sandbox. Nothing leaves the sandbox except
3
+ * through it, it refuses everything that isn't on its allowlist, and it logs each request without its headers. A tool
4
+ * that needs a credential sends its request to a local route, such as `http://127.0.0.1:<port>/github/user`, with the
5
+ * route's sentinel where the credential goes. The proxy checks the sentinel and the method, swaps in the real secret and
6
+ * forwards the request over HTTPS. It never intercepts TLS: everything else leaves through `CONNECT` to an
7
+ * allowlisted name, and a name is connected to only at an address the proxy checked. It is Node-only.
8
+ */
9
+ import { HarnessError } from "../errors.js";
10
+ import { isAddressLiteral, isPublicAddress } from "./addresses.js";
11
+ import { isAllowed, parseAllow, parseRoutes, } from "./allowlist.js";
12
+ function nodeModules() {
13
+ if (typeof process === "undefined" || typeof process.getBuiltinModule !== "function") {
14
+ throw new HarnessError("invalid_egress_options", "the egress proxy needs Node's network modules, which this runtime lacks");
15
+ }
16
+ return {
17
+ http: process.getBuiltinModule("node:http"),
18
+ https: process.getBuiltinModule("node:https"),
19
+ net: process.getBuiltinModule("node:net"),
20
+ dns: process.getBuiltinModule("node:dns"),
21
+ crypto: process.getBuiltinModule("node:crypto"),
22
+ stream: process.getBuiltinModule("node:stream"),
23
+ };
24
+ }
25
+ // Headers that belong to one connection, and are never passed on to the next.
26
+ const HOP_BY_HOP = new Set([
27
+ "connection",
28
+ "keep-alive",
29
+ "proxy-authenticate",
30
+ "proxy-authorization",
31
+ "proxy-connection",
32
+ "te",
33
+ "trailer",
34
+ "transfer-encoding",
35
+ "upgrade",
36
+ "host",
37
+ ]);
38
+ const DEFAULT_IDLE_MS = 120_000;
39
+ // What Node refuses in a header value: anything but tab, printable ASCII and the Latin-1 range. A secret with a line break
40
+ // or another control character would split or break the request, so it is refused before it is sent.
41
+ const INVALID_HEADER_VALUE = /[^\t\x20-\x7e\x80-\xff]/;
42
+ // The origin an in-process tool uses for a route, in either mode, because a Unix socket has no address of its own.
43
+ const ROUTE_ORIGIN = "http://egress.proxy";
44
+ const refusal = (status, reason) => ({
45
+ status,
46
+ headers: { "content-type": "text/plain" },
47
+ body: undefined,
48
+ reason,
49
+ });
50
+ class EgressGate {
51
+ modules;
52
+ allow;
53
+ routes;
54
+ sentinels = {};
55
+ options;
56
+ unsafe;
57
+ sockets = new Set();
58
+ requests = new Set();
59
+ origin = "";
60
+ constructor(modules, options) {
61
+ this.modules = modules;
62
+ this.options = options;
63
+ this.allow = parseAllow(options.allow);
64
+ this.routes = new Map(parseRoutes(options.routes ?? []).map((route) => [route.route, route]));
65
+ this.unsafe = new Set(options.unsafeAllowAddresses ?? []);
66
+ for (const route of this.routes.keys()) {
67
+ this.sentinels[route] = `sentinel_${modules.crypto.randomBytes(18).toString("base64url")}`;
68
+ }
69
+ }
70
+ setOrigin(origin) {
71
+ this.origin = origin;
72
+ }
73
+ sentinelMap() {
74
+ return this.sentinels;
75
+ }
76
+ record(record) {
77
+ try {
78
+ this.options.log({ time: new Date().toISOString(), ...record });
79
+ }
80
+ catch {
81
+ // A logger that throws must not take the proxy down.
82
+ }
83
+ }
84
+ /** A `lookup` for `net` and `https`: it resolves in the proxy, checks every address, and connects only to those. */
85
+ checkedLookup = (hostname, lookupOptions, callback) => {
86
+ const resolve = this.options.resolve ??
87
+ (async (host) => (await this.modules.dns.promises.lookup(host, { all: true })).map((found) => found.address));
88
+ resolve(hostname).then((addresses) => {
89
+ const refused = addresses.length === 0 || addresses.some((a) => !isPublicAddress(a) && !this.unsafe.has(a));
90
+ if (refused) {
91
+ callback(Object.assign(new Error(`${hostname} resolves to an address the proxy refuses`), {
92
+ code: "EGRESS_ADDRESS",
93
+ }));
94
+ return;
95
+ }
96
+ const family = (address) => (address.includes(":") ? 6 : 4);
97
+ if (lookupOptions.all === true) {
98
+ callback(null, addresses.map((address) => ({ address, family: family(address) })));
99
+ }
100
+ else {
101
+ callback(null, addresses[0], family(addresses[0] ?? ""));
102
+ }
103
+ }, (error) => callback(error));
104
+ };
105
+ reasonOf(error) {
106
+ const code = error.code;
107
+ if (code === "EGRESS_ADDRESS")
108
+ return "address_refused";
109
+ return code === "ETIMEDOUT" ? "timeout" : "connect_failed";
110
+ }
111
+ /** The host and port of a `CONNECT` target, or `undefined` for one that isn't `host:port`. */
112
+ parseTarget(target) {
113
+ const match = /^(\[[0-9a-fA-F:.]+\]|[^:[\]]+):([0-9]{1,5})$/.exec(target);
114
+ if (match === null)
115
+ return undefined;
116
+ const host = (match[1] ?? "").toLowerCase().replace(/\.$/, "");
117
+ const port = Number(match[2]);
118
+ return port >= 1 && port <= 65535 ? { host, port } : undefined;
119
+ }
120
+ /** Handles one `CONNECT`: allow-checks the name, then tunnels to the address the proxy checked. */
121
+ handleConnect(request, client, head) {
122
+ this.track(client);
123
+ const target = this.parseTarget(request.url ?? "");
124
+ const host = target?.host ?? "(invalid)";
125
+ const port = target?.port ?? 0;
126
+ const deny = (reason, status = 403) => {
127
+ client.end(`HTTP/1.1 ${status} ${status === 403 ? "Forbidden" : "Bad Gateway"}\r\nConnection: close\r\n\r\n`);
128
+ this.record({ kind: "connect", host, port, method: "CONNECT", status, bytes: 0, reason });
129
+ };
130
+ const refusedBecause = target === undefined
131
+ ? "bad_target"
132
+ : isAddressLiteral(host)
133
+ ? "address_literal"
134
+ : isAllowed(this.allow, host, port)
135
+ ? undefined
136
+ : "not_allowed";
137
+ if (refusedBecause !== undefined) {
138
+ deny(refusedBecause);
139
+ return;
140
+ }
141
+ let established = false;
142
+ const upstream = this.modules.net.connect({ host, port, lookup: this.checkedLookup });
143
+ this.track(upstream);
144
+ // A client that leaves before the tunnel is up takes the connection attempt with it.
145
+ client.once("close", () => upstream.destroy());
146
+ upstream.setTimeout(this.options.idleTimeoutMs ?? DEFAULT_IDLE_MS, () => upstream.destroy(Object.assign(new Error("idle"), { code: "ETIMEDOUT" })));
147
+ upstream.once("error", (error) => {
148
+ if (established)
149
+ client.destroy();
150
+ else
151
+ deny(this.reasonOf(error), 502);
152
+ upstream.destroy();
153
+ });
154
+ upstream.once("connect", () => {
155
+ established = true;
156
+ client.write("HTTP/1.1 200 Connection Established\r\n\r\n");
157
+ if (head.length > 0)
158
+ upstream.write(head);
159
+ upstream.pipe(client);
160
+ client.pipe(upstream);
161
+ const done = () => {
162
+ client.destroy();
163
+ upstream.destroy();
164
+ };
165
+ client.once("close", done);
166
+ upstream.once("close", () => {
167
+ this.record({
168
+ kind: "connect",
169
+ host,
170
+ port,
171
+ method: "CONNECT",
172
+ status: 200,
173
+ bytes: upstream.bytesRead + upstream.bytesWritten,
174
+ });
175
+ done();
176
+ });
177
+ });
178
+ client.once("error", () => upstream.destroy());
179
+ }
180
+ track(socket) {
181
+ if (this.sockets.has(socket))
182
+ return;
183
+ this.sockets.add(socket);
184
+ socket.once("close", () => this.sockets.delete(socket));
185
+ socket.on("error", () => { });
186
+ }
187
+ /** Handles one request that isn't a `CONNECT`: a route request, or a refusal of anything else. */
188
+ handleRequest(request, response) {
189
+ this.track(request.socket);
190
+ const url = request.url ?? "";
191
+ if (!url.startsWith("/")) {
192
+ // A proxy request in absolute form: only a tunnel may leave, so the name is not even looked at.
193
+ this.finish(response, refusal(403, "only_connect"), {
194
+ kind: "route",
195
+ host: "(proxy request)",
196
+ port: 0,
197
+ method: request.method ?? "",
198
+ });
199
+ return;
200
+ }
201
+ // A client that goes away takes the upstream request with it, so a credential isn't spent for nobody.
202
+ const gone = new AbortController();
203
+ response.once("close", () => gone.abort());
204
+ const base = {
205
+ kind: "route",
206
+ host: "(route)",
207
+ port: 0,
208
+ method: request.method ?? "GET",
209
+ route: undefined,
210
+ };
211
+ this.routeRequest(request.method ?? "GET", url, request.headers, request, gone.signal).then((reply) => this.finish(response, reply.reply, reply.base), () => this.finish(response, refusal(502, "request_failed"), base));
212
+ }
213
+ finish(response, reply, base) {
214
+ response.writeHead(reply.status, reply.headers);
215
+ let bytes = 0;
216
+ const report = () => this.record({
217
+ ...base,
218
+ status: reply.status,
219
+ bytes,
220
+ ...(reply.reason === undefined ? {} : { reason: reply.reason }),
221
+ });
222
+ if (reply.body === undefined) {
223
+ response.end(reply.status === 403 || reply.status >= 400 ? `${reply.reason ?? "refused"}\n` : undefined);
224
+ report();
225
+ return;
226
+ }
227
+ reply.body.on("data", (chunk) => {
228
+ bytes += chunk.length;
229
+ });
230
+ reply.body.once("close", report);
231
+ reply.body.once("error", () => response.destroy());
232
+ response.once("close", () => reply.body?.destroy());
233
+ reply.body.pipe(response);
234
+ }
235
+ /**
236
+ * Resolves a request for `/<route>/…`. It checks the route, the method and the sentinel, swaps in the secret, and
237
+ * forwards the request to the route's host. A request that fails any check is answered here, and nothing is sent.
238
+ */
239
+ async routeRequest(method, rawPath, headers, body, signal) {
240
+ const match = /^\/([^/?#]+)(\/[^?#]*)?(\?[^#]*)?$/.exec(rawPath);
241
+ const route = match === null ? undefined : this.routes.get(match[1] ?? "");
242
+ const base = {
243
+ kind: "route",
244
+ host: route?.hostname ?? "(no route)",
245
+ port: route?.port ?? 0,
246
+ method,
247
+ route: route?.route,
248
+ };
249
+ if (route === undefined || match === null)
250
+ return { reply: refusal(403, "unknown_route"), base };
251
+ if (!route.methods.has(method.toUpperCase()))
252
+ return { reply: refusal(405, "method_not_allowed"), base };
253
+ const presented = headers[route.header];
254
+ const sentinel = this.sentinels[route.route] ?? "";
255
+ if (typeof presented !== "string" || sentinel === "" || !presented.includes(sentinel)) {
256
+ return { reply: refusal(403, "bad_sentinel"), base };
257
+ }
258
+ const secret = await route.secret().catch(() => "");
259
+ if (secret === "" || INVALID_HEADER_VALUE.test(secret))
260
+ return { reply: refusal(502, "secret_unavailable"), base };
261
+ const outgoing = this.outgoingHeaders(headers, route, presented.replaceAll(sentinel, () => secret));
262
+ const reply = await this.forward(route, method, `${match[2] ?? "/"}${match[3] ?? ""}`, outgoing, body, signal);
263
+ return { reply, base };
264
+ }
265
+ outgoingHeaders(headers, route, credential) {
266
+ const out = {};
267
+ for (const [name, value] of Object.entries(headers)) {
268
+ if (value !== undefined && !HOP_BY_HOP.has(name))
269
+ out[name] = value;
270
+ }
271
+ out[route.header] = credential;
272
+ out.host = route.port === 443 ? route.hostname : `${route.hostname}:${route.port}`;
273
+ return out;
274
+ }
275
+ forward(route, method, path, headers, body, signal) {
276
+ return new Promise((resolve) => {
277
+ let upstream;
278
+ try {
279
+ upstream = this.openRoute(route, method, path, headers);
280
+ }
281
+ catch {
282
+ resolve(refusal(502, "request_invalid"));
283
+ return;
284
+ }
285
+ const stop = () => upstream.destroy(new Error("client gone"));
286
+ if (signal?.aborted === true)
287
+ stop();
288
+ else
289
+ signal?.addEventListener("abort", stop, { once: true });
290
+ upstream.once("close", () => signal?.removeEventListener("abort", stop));
291
+ this.requests.add(upstream);
292
+ upstream.setTimeout(this.options.idleTimeoutMs ?? DEFAULT_IDLE_MS, () => upstream.destroy(new Error("idle")));
293
+ upstream.once("close", () => this.requests.delete(upstream));
294
+ upstream.once("response", (reply) => {
295
+ const passed = {};
296
+ for (const [name, value] of Object.entries(reply.headers)) {
297
+ if (value !== undefined && !HOP_BY_HOP.has(name))
298
+ passed[name] = value;
299
+ }
300
+ resolve({ status: reply.statusCode ?? 502, headers: passed, body: reply });
301
+ });
302
+ upstream.once("error", (error) => resolve(refusal(502, this.reasonOf(error))));
303
+ if (body === undefined)
304
+ upstream.end();
305
+ else if (body instanceof Uint8Array)
306
+ upstream.end(body);
307
+ else
308
+ body.pipe(upstream);
309
+ });
310
+ }
311
+ /** Opens the HTTPS request to a route's host, which throws for a header or path Node refuses. */
312
+ openRoute(route, method, path, headers) {
313
+ return this.modules.https.request({
314
+ host: route.hostname,
315
+ port: route.port,
316
+ servername: route.hostname,
317
+ method,
318
+ path,
319
+ headers,
320
+ agent: false,
321
+ lookup: this.checkedLookup,
322
+ ...(this.options.ca === undefined ? {} : { ca: this.options.ca }),
323
+ });
324
+ }
325
+ /** An in-process fetch under the same allowlist, with the same address checks and pinned connection. */
326
+ async fetch(input, init) {
327
+ const request = new Request(input, init);
328
+ request.signal.throwIfAborted();
329
+ const url = new URL(request.url);
330
+ const host = url.hostname.toLowerCase().replace(/\.$/, "");
331
+ const port = url.port === "" ? 443 : Number(url.port);
332
+ const bodyBytes = request.method === "GET" || request.method === "HEAD" ? undefined : new Uint8Array(await request.arrayBuffer());
333
+ if (url.origin === ROUTE_ORIGIN || (this.origin !== "" && url.origin === this.origin)) {
334
+ return this.fetchRoute(request, url, bodyBytes);
335
+ }
336
+ const refuse = (reason) => {
337
+ this.record({ kind: "fetch", host, port, method: request.method, status: 403, bytes: 0, reason });
338
+ throw new HarnessError("egress_denied", `the egress proxy refused ${url.host}: ${reason}`);
339
+ };
340
+ if (url.protocol !== "https:")
341
+ return refuse("only_https");
342
+ if (isAddressLiteral(host))
343
+ return refuse("address_literal");
344
+ if (!isAllowed(this.allow, host, port))
345
+ return refuse("not_allowed");
346
+ return this.sendFetch(request, url, host, port, bodyBytes);
347
+ }
348
+ async fetchRoute(request, url, body) {
349
+ const headers = {};
350
+ request.headers.forEach((value, name) => {
351
+ headers[name.toLowerCase()] = value;
352
+ });
353
+ const path = `${url.pathname}${url.search}`;
354
+ const { reply, base } = await this.routeRequest(request.method, path, headers, body, request.signal);
355
+ const stream = reply.body;
356
+ let bytes = 0;
357
+ stream?.on("data", (chunk) => {
358
+ bytes += chunk.length;
359
+ });
360
+ const finished = () => this.record({
361
+ ...base,
362
+ status: reply.status,
363
+ bytes,
364
+ ...(reply.reason === undefined ? {} : { reason: reply.reason }),
365
+ });
366
+ if (stream === undefined)
367
+ finished();
368
+ else
369
+ stream.once("close", finished);
370
+ return this.toResponse(reply.status, reply.headers, stream);
371
+ }
372
+ sendFetch(request, url, host, port, body) {
373
+ return new Promise((resolve, reject) => {
374
+ const headers = {};
375
+ request.headers.forEach((value, name) => {
376
+ if (!HOP_BY_HOP.has(name.toLowerCase()))
377
+ headers[name] = value;
378
+ });
379
+ const upstream = this.modules.https.request({
380
+ host,
381
+ port,
382
+ servername: host,
383
+ method: request.method,
384
+ path: `${url.pathname}${url.search}`,
385
+ headers: { ...headers, host: url.host },
386
+ agent: false,
387
+ lookup: this.checkedLookup,
388
+ ...(this.options.ca === undefined ? {} : { ca: this.options.ca }),
389
+ });
390
+ this.requests.add(upstream);
391
+ const abort = () => upstream.destroy(request.signal.reason);
392
+ request.signal.addEventListener("abort", abort, { once: true });
393
+ upstream.once("close", () => {
394
+ this.requests.delete(upstream);
395
+ request.signal.removeEventListener("abort", abort);
396
+ });
397
+ upstream.setTimeout(this.options.idleTimeoutMs ?? DEFAULT_IDLE_MS, () => upstream.destroy(new Error("idle")));
398
+ upstream.once("response", (reply) => {
399
+ let bytes = 0;
400
+ reply.on("data", (chunk) => {
401
+ bytes += chunk.length;
402
+ });
403
+ // The record is written when the response is done with, which also covers one that is never read to its end.
404
+ reply.once("close", () => this.record({ kind: "fetch", host, port, method: request.method, status: reply.statusCode ?? 0, bytes }));
405
+ resolve(this.toResponse(reply.statusCode ?? 502, reply.headers, reply));
406
+ });
407
+ upstream.once("error", (error) => {
408
+ if (request.signal.aborted) {
409
+ reject(request.signal.reason);
410
+ return;
411
+ }
412
+ const reason = this.reasonOf(error);
413
+ this.record({ kind: "fetch", host, port, method: request.method, status: 502, bytes: 0, reason });
414
+ reject(new HarnessError("egress_denied", `the egress proxy could not reach ${url.host}: ${reason}`, {
415
+ cause: error,
416
+ }));
417
+ });
418
+ upstream.end(body);
419
+ });
420
+ }
421
+ toResponse(status, headers, stream) {
422
+ const out = new Headers();
423
+ for (const [name, value] of Object.entries(headers)) {
424
+ for (const one of Array.isArray(value) ? value : [value])
425
+ out.append(name, one);
426
+ }
427
+ const bodiless = stream === undefined || [101, 204, 205, 304].includes(status);
428
+ // A response with no body is drained, so its socket and its log record don't wait for a reader that never comes.
429
+ if (bodiless)
430
+ stream?.resume();
431
+ const web = bodiless ? null : this.modules.stream.Readable.toWeb(stream);
432
+ return new Response(web, { status, headers: out });
433
+ }
434
+ async knownSecrets() {
435
+ const secrets = await Promise.all([...this.routes.values()].map((route) => route.secret().catch(() => "")));
436
+ return [...new Set(secrets.filter((secret) => secret !== ""))];
437
+ }
438
+ close(server) {
439
+ return new Promise((resolve) => {
440
+ for (const socket of this.sockets)
441
+ socket.destroy();
442
+ for (const request of this.requests)
443
+ request.destroy();
444
+ server.close(() => resolve());
445
+ server.closeAllConnections();
446
+ });
447
+ }
448
+ }
449
+ /**
450
+ * Starts the egress proxy on `127.0.0.1` with a port the system picks, or on `socketPath`. The allowlist and routes are
451
+ * checked first, and a bad entry throws `invalid_egress_options`. Give the sandbox `proxy.url` as `HTTPS_PROXY`, and
452
+ * give a tool that needs a credential the route's URL and its sentinel.
453
+ */
454
+ export async function startEgressProxy(options) {
455
+ const modules = nodeModules();
456
+ const proxy = new EgressGate(modules, options);
457
+ const server = modules.http.createServer((request, response) => proxy.handleRequest(request, response));
458
+ server.on("connect", (request, socket, head) => proxy.handleConnect(request, socket, head));
459
+ server.on("clientError", (_error, socket) => socket.destroy());
460
+ await new Promise((resolve, reject) => {
461
+ server.once("error", reject);
462
+ if (options.socketPath === undefined)
463
+ server.listen(0, "127.0.0.1", resolve);
464
+ else
465
+ server.listen(options.socketPath, resolve);
466
+ });
467
+ const address = server.address();
468
+ const url = options.socketPath !== undefined
469
+ ? `unix:${options.socketPath}`
470
+ : `http://127.0.0.1:${address.port}`;
471
+ if (options.socketPath === undefined)
472
+ proxy.setOrigin(url);
473
+ return {
474
+ url,
475
+ ...(options.socketPath === undefined ? {} : { socketPath: options.socketPath }),
476
+ sentinels: proxy.sentinelMap(),
477
+ fetch: (input, init) => proxy.fetch(input, init),
478
+ knownSecrets: () => proxy.knownSecrets(),
479
+ close: () => proxy.close(server),
480
+ };
481
+ }
482
+ //# sourceMappingURL=egress-proxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"egress-proxy.js","sourceRoot":"","sources":["../../src/credentials/egress-proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAGL,SAAS,EAET,UAAU,EACV,WAAW,GACZ,MAAM,gBAAgB,CAAC;AA8ExB,SAAS,WAAW;IAClB,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,OAAO,CAAC,gBAAgB,KAAK,UAAU,EAAE,CAAC;QACrF,MAAM,IAAI,YAAY,CACpB,wBAAwB,EACxB,yEAAyE,CAC1E,CAAC;IACJ,CAAC;IACD,OAAO;QACL,IAAI,EAAE,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC;QAC3C,KAAK,EAAE,OAAO,CAAC,gBAAgB,CAAC,YAAY,CAAC;QAC7C,GAAG,EAAE,OAAO,CAAC,gBAAgB,CAAC,UAAU,CAAC;QACzC,GAAG,EAAE,OAAO,CAAC,gBAAgB,CAAC,UAAU,CAAC;QACzC,MAAM,EAAE,OAAO,CAAC,gBAAgB,CAAC,aAAa,CAAC;QAC/C,MAAM,EAAE,OAAO,CAAC,gBAAgB,CAAC,aAAa,CAAC;KAChD,CAAC;AACJ,CAAC;AAED,8EAA8E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ACjC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * `startEgressProxy()`: the host-side proxy that keeps credentials out of the sandbox. Nothing leaves the sandbox except\n * through it, it refuses everything that isn't on its allowlist, and it logs each request without its headers. A tool\n * that needs a credential sends its request to a local route, such as `http://127.0.0.1:<port>/github/user`, with the\n * route's sentinel where the credential goes. The proxy checks the sentinel and the method, swaps in the real secret and\n * forwards the request over HTTPS. It never intercepts TLS: everything else leaves through `CONNECT` to an\n * allowlisted name, and a name is connected to only at an address the proxy checked. It is Node-only.\n */\nimport { HarnessError } from \"../errors.js\";\nimport { isAddressLiteral, isPublicAddress } from \"./addresses.js\";\nimport {\n type AllowEntry,\n type CredentialRoute,\n isAllowed,\n type ParsedRoute,\n parseAllow,\n parseRoutes,\n} from \"./allowlist.js\";\n\nexport type { CredentialRoute } from \"./allowlist.js\";\n\n/** One line of the egress log. It names the host and the outcome, and never holds a header, a body or a secret. */\nexport interface EgressRecord {\n /** When the request ended, as an ISO 8601 string. */\n readonly time: string;\n /** `connect` for a tunnel, `route` for a credential route and `fetch` for an in-process call. */\n readonly kind: \"connect\" | \"route\" | \"fetch\";\n /** The host the request was for. */\n readonly host: string;\n readonly port: number;\n readonly method: string;\n /** The status the sandbox saw: 200 for an established tunnel, 403 for a refusal, 502 for a failed connection. */\n readonly status: number;\n /** The bytes that went both ways, 0 for a refusal. */\n readonly bytes: number;\n /** The route's name, for a route request. */\n readonly route?: string | undefined;\n /** Why a request was refused or failed, as a short code such as `not_allowed` or `address_refused`. */\n readonly reason?: string;\n}\n\n/** The options of `startEgressProxy()`. */\nexport interface EgressProxyOptions {\n /** The names a tunnel or an in-process fetch may reach: `example.com`, `*.example.com`, or either with `:port`. */\n readonly allow: readonly string[];\n /** The credential routes. Without any, the proxy only tunnels. */\n readonly routes?: readonly CredentialRoute[];\n /** Receives one record for each request. A throw from it is ignored. */\n readonly log: (record: EgressRecord) => void;\n /** Listens on this Unix socket instead of a port on `127.0.0.1`, so a container can mount it (`dockerSandbox`'s `proxySocket`). */\n readonly socketPath?: string;\n /** Extra certificate authorities to trust for the routes' hosts and for the fetch, such as a test's own. */\n readonly ca?: string | Uint8Array | readonly (string | Uint8Array)[];\n /** Resolves a name to its addresses. Defaults to the system resolver. Every address it returns is checked. */\n readonly resolve?: (host: string) => Promise<readonly string[]>;\n /**\n * Addresses that skip the public-address check. This exists so a test can reach a server on `127.0.0.1`. Never set it\n * for a real run: the check is what keeps a name that points at the host's own network from being reached.\n */\n readonly unsafeAllowAddresses?: readonly string[];\n /** Ends a tunnel or a forwarded request that is idle this long. Defaults to 120000. */\n readonly idleTimeoutMs?: number;\n}\n\n/** A running egress proxy. */\nexport interface EgressProxy {\n /**\n * Where the sandbox sends its requests: give it as `HTTPS_PROXY`, and join a route's name to it for a route. On a Unix\n * socket it is `unix:<path>`, which is not a proxy URL: the program that uses the socket connects to it itself.\n */\n readonly url: string;\n /** The Unix socket the proxy listens on, when it was started with `socketPath`. */\n readonly socketPath?: string;\n /** For each route, the placeholder the sandbox puts where the credential goes. The real secret never leaves the host. */\n readonly sentinels: Readonly<Record<string, string>>;\n /**\n * Fetches `input` for an in-process tool, under the same allowlist. A host that isn't on it rejects with `egress_denied`.\n * A route is reached at `${proxy.url}/<route>/…`, or at `http://egress.proxy/<route>/…`, which also works on a Unix socket.\n */\n fetch(input: string | URL, init?: RequestInit): Promise<Response>;\n /** The routes' secrets now, for `scrubSecrets()`. */\n knownSecrets(): Promise<readonly string[]>;\n /** Stops listening and ends every open tunnel and request. */\n close(): Promise<void>;\n}\n\ntype Modules = {\n readonly http: typeof import(\"node:http\");\n readonly https: typeof import(\"node:https\");\n readonly net: typeof import(\"node:net\");\n readonly dns: typeof import(\"node:dns\");\n readonly crypto: typeof import(\"node:crypto\");\n readonly stream: typeof import(\"node:stream\");\n};\n\nfunction nodeModules(): Modules {\n if (typeof process === \"undefined\" || typeof process.getBuiltinModule !== \"function\") {\n throw new HarnessError(\n \"invalid_egress_options\",\n \"the egress proxy needs Node's network modules, which this runtime lacks\",\n );\n }\n return {\n http: process.getBuiltinModule(\"node:http\"),\n https: process.getBuiltinModule(\"node:https\"),\n net: process.getBuiltinModule(\"node:net\"),\n dns: process.getBuiltinModule(\"node:dns\"),\n crypto: process.getBuiltinModule(\"node:crypto\"),\n stream: process.getBuiltinModule(\"node:stream\"),\n };\n}\n\n// Headers that belong to one connection, and are never passed on to the next.\nconst HOP_BY_HOP = new Set([\n \"connection\",\n \"keep-alive\",\n \"proxy-authenticate\",\n \"proxy-authorization\",\n \"proxy-connection\",\n \"te\",\n \"trailer\",\n \"transfer-encoding\",\n \"upgrade\",\n \"host\",\n]);\nconst DEFAULT_IDLE_MS = 120_000;\n// What Node refuses in a header value: anything but tab, printable ASCII and the Latin-1 range. A secret with a line break\n// or another control character would split or break the request, so it is refused before it is sent.\nconst INVALID_HEADER_VALUE = /[^\\t\\x20-\\x7e\\x80-\\xff]/;\n// The origin an in-process tool uses for a route, in either mode, because a Unix socket has no address of its own.\nconst ROUTE_ORIGIN = \"http://egress.proxy\";\n\n/** What a request for a route resolves to, before it is written to a socket or wrapped in a `Response`. */\ninterface RouteReply {\n readonly status: number;\n readonly headers: Record<string, string | string[]>;\n readonly body: import(\"node:stream\").Readable | undefined;\n readonly reason?: string;\n}\n\nconst refusal = (status: number, reason: string): RouteReply => ({\n status,\n headers: { \"content-type\": \"text/plain\" },\n body: undefined,\n reason,\n});\n\nclass EgressGate {\n private readonly modules: Modules;\n private readonly allow: readonly AllowEntry[];\n private readonly routes: ReadonlyMap<string, ParsedRoute>;\n private readonly sentinels: Record<string, string> = {};\n private readonly options: EgressProxyOptions;\n private readonly unsafe: ReadonlySet<string>;\n private readonly sockets = new Set<import(\"node:net\").Socket>();\n private readonly requests = new Set<import(\"node:http\").ClientRequest>();\n private origin = \"\";\n\n constructor(modules: Modules, options: EgressProxyOptions) {\n this.modules = modules;\n this.options = options;\n this.allow = parseAllow(options.allow);\n this.routes = new Map(parseRoutes(options.routes ?? []).map((route) => [route.route, route]));\n this.unsafe = new Set(options.unsafeAllowAddresses ?? []);\n for (const route of this.routes.keys()) {\n this.sentinels[route] = `sentinel_${modules.crypto.randomBytes(18).toString(\"base64url\")}`;\n }\n }\n\n setOrigin(origin: string): void {\n this.origin = origin;\n }\n\n sentinelMap(): Readonly<Record<string, string>> {\n return this.sentinels;\n }\n\n private record(record: Omit<EgressRecord, \"time\">): void {\n try {\n this.options.log({ time: new Date().toISOString(), ...record });\n } catch {\n // A logger that throws must not take the proxy down.\n }\n }\n\n /** A `lookup` for `net` and `https`: it resolves in the proxy, checks every address, and connects only to those. */\n private readonly checkedLookup = (\n hostname: string,\n lookupOptions: { all?: boolean },\n callback: (error: Error | null, address?: unknown, family?: number) => void,\n ): void => {\n const resolve =\n this.options.resolve ??\n (async (host: string) =>\n (await this.modules.dns.promises.lookup(host, { all: true })).map((found) => found.address));\n resolve(hostname).then(\n (addresses) => {\n const refused = addresses.length === 0 || addresses.some((a) => !isPublicAddress(a) && !this.unsafe.has(a));\n if (refused) {\n callback(\n Object.assign(new Error(`${hostname} resolves to an address the proxy refuses`), {\n code: \"EGRESS_ADDRESS\",\n }),\n );\n return;\n }\n const family = (address: string) => (address.includes(\":\") ? 6 : 4);\n if (lookupOptions.all === true) {\n callback(\n null,\n addresses.map((address) => ({ address, family: family(address) })),\n );\n } else {\n callback(null, addresses[0], family(addresses[0] ?? \"\"));\n }\n },\n (error: unknown) => callback(error as Error),\n );\n };\n\n private reasonOf(error: unknown): string {\n const code = (error as { code?: string }).code;\n if (code === \"EGRESS_ADDRESS\") return \"address_refused\";\n return code === \"ETIMEDOUT\" ? \"timeout\" : \"connect_failed\";\n }\n\n /** The host and port of a `CONNECT` target, or `undefined` for one that isn't `host:port`. */\n private parseTarget(target: string): { host: string; port: number } | undefined {\n const match = /^(\\[[0-9a-fA-F:.]+\\]|[^:[\\]]+):([0-9]{1,5})$/.exec(target);\n if (match === null) return undefined;\n const host = (match[1] ?? \"\").toLowerCase().replace(/\\.$/, \"\");\n const port = Number(match[2]);\n return port >= 1 && port <= 65535 ? { host, port } : undefined;\n }\n\n /** Handles one `CONNECT`: allow-checks the name, then tunnels to the address the proxy checked. */\n handleConnect(request: import(\"node:http\").IncomingMessage, client: import(\"node:net\").Socket, head: Buffer): void {\n this.track(client);\n const target = this.parseTarget(request.url ?? \"\");\n const host = target?.host ?? \"(invalid)\";\n const port = target?.port ?? 0;\n const deny = (reason: string, status = 403) => {\n client.end(`HTTP/1.1 ${status} ${status === 403 ? \"Forbidden\" : \"Bad Gateway\"}\\r\\nConnection: close\\r\\n\\r\\n`);\n this.record({ kind: \"connect\", host, port, method: \"CONNECT\", status, bytes: 0, reason });\n };\n const refusedBecause =\n target === undefined\n ? \"bad_target\"\n : isAddressLiteral(host)\n ? \"address_literal\"\n : isAllowed(this.allow, host, port)\n ? undefined\n : \"not_allowed\";\n if (refusedBecause !== undefined) {\n deny(refusedBecause);\n return;\n }\n let established = false;\n const upstream = this.modules.net.connect({ host, port, lookup: this.checkedLookup as never });\n this.track(upstream);\n // A client that leaves before the tunnel is up takes the connection attempt with it.\n client.once(\"close\", () => upstream.destroy());\n upstream.setTimeout(this.options.idleTimeoutMs ?? DEFAULT_IDLE_MS, () =>\n upstream.destroy(Object.assign(new Error(\"idle\"), { code: \"ETIMEDOUT\" })),\n );\n upstream.once(\"error\", (error) => {\n if (established) client.destroy();\n else deny(this.reasonOf(error), 502);\n upstream.destroy();\n });\n upstream.once(\"connect\", () => {\n established = true;\n client.write(\"HTTP/1.1 200 Connection Established\\r\\n\\r\\n\");\n if (head.length > 0) upstream.write(head);\n upstream.pipe(client);\n client.pipe(upstream);\n const done = () => {\n client.destroy();\n upstream.destroy();\n };\n client.once(\"close\", done);\n upstream.once(\"close\", () => {\n this.record({\n kind: \"connect\",\n host,\n port,\n method: \"CONNECT\",\n status: 200,\n bytes: upstream.bytesRead + upstream.bytesWritten,\n });\n done();\n });\n });\n client.once(\"error\", () => upstream.destroy());\n }\n\n private track(socket: import(\"node:net\").Socket): void {\n if (this.sockets.has(socket)) return;\n this.sockets.add(socket);\n socket.once(\"close\", () => this.sockets.delete(socket));\n socket.on(\"error\", () => {});\n }\n\n /** Handles one request that isn't a `CONNECT`: a route request, or a refusal of anything else. */\n handleRequest(request: import(\"node:http\").IncomingMessage, response: import(\"node:http\").ServerResponse): void {\n this.track(request.socket);\n const url = request.url ?? \"\";\n if (!url.startsWith(\"/\")) {\n // A proxy request in absolute form: only a tunnel may leave, so the name is not even looked at.\n this.finish(response, refusal(403, \"only_connect\"), {\n kind: \"route\",\n host: \"(proxy request)\",\n port: 0,\n method: request.method ?? \"\",\n });\n return;\n }\n // A client that goes away takes the upstream request with it, so a credential isn't spent for nobody.\n const gone = new AbortController();\n response.once(\"close\", () => gone.abort());\n const base = {\n kind: \"route\" as const,\n host: \"(route)\",\n port: 0,\n method: request.method ?? \"GET\",\n route: undefined,\n };\n this.routeRequest(request.method ?? \"GET\", url, request.headers, request, gone.signal).then(\n (reply) => this.finish(response, reply.reply, reply.base),\n () => this.finish(response, refusal(502, \"request_failed\"), base),\n );\n }\n\n private finish(\n response: import(\"node:http\").ServerResponse,\n reply: RouteReply,\n base: Pick<EgressRecord, \"kind\" | \"host\" | \"port\" | \"method\" | \"route\">,\n ): void {\n response.writeHead(reply.status, reply.headers);\n let bytes = 0;\n const report = () =>\n this.record({\n ...base,\n status: reply.status,\n bytes,\n ...(reply.reason === undefined ? {} : { reason: reply.reason }),\n });\n if (reply.body === undefined) {\n response.end(reply.status === 403 || reply.status >= 400 ? `${reply.reason ?? \"refused\"}\\n` : undefined);\n report();\n return;\n }\n reply.body.on(\"data\", (chunk: Buffer) => {\n bytes += chunk.length;\n });\n reply.body.once(\"close\", report);\n reply.body.once(\"error\", () => response.destroy());\n response.once(\"close\", () => reply.body?.destroy());\n reply.body.pipe(response);\n }\n\n /**\n * Resolves a request for `/<route>/…`. It checks the route, the method and the sentinel, swaps in the secret, and\n * forwards the request to the route's host. A request that fails any check is answered here, and nothing is sent.\n */\n async routeRequest(\n method: string,\n rawPath: string,\n headers: Record<string, string | string[] | undefined>,\n body: import(\"node:stream\").Readable | Uint8Array | undefined,\n signal?: AbortSignal,\n ): Promise<{ reply: RouteReply; base: Pick<EgressRecord, \"kind\" | \"host\" | \"port\" | \"method\" | \"route\"> }> {\n const match = /^\\/([^/?#]+)(\\/[^?#]*)?(\\?[^#]*)?$/.exec(rawPath);\n const route = match === null ? undefined : this.routes.get(match[1] ?? \"\");\n const base = {\n kind: \"route\" as const,\n host: route?.hostname ?? \"(no route)\",\n port: route?.port ?? 0,\n method,\n route: route?.route,\n };\n if (route === undefined || match === null) return { reply: refusal(403, \"unknown_route\"), base };\n if (!route.methods.has(method.toUpperCase())) return { reply: refusal(405, \"method_not_allowed\"), base };\n const presented = headers[route.header];\n const sentinel = this.sentinels[route.route] ?? \"\";\n if (typeof presented !== \"string\" || sentinel === \"\" || !presented.includes(sentinel)) {\n return { reply: refusal(403, \"bad_sentinel\"), base };\n }\n const secret = await route.secret().catch(() => \"\");\n if (secret === \"\" || INVALID_HEADER_VALUE.test(secret)) return { reply: refusal(502, \"secret_unavailable\"), base };\n const outgoing = this.outgoingHeaders(\n headers,\n route,\n presented.replaceAll(sentinel, () => secret),\n );\n const reply = await this.forward(route, method, `${match[2] ?? \"/\"}${match[3] ?? \"\"}`, outgoing, body, signal);\n return { reply, base };\n }\n\n private outgoingHeaders(\n headers: Record<string, string | string[] | undefined>,\n route: ParsedRoute,\n credential: string,\n ): Record<string, string | string[]> {\n const out: Record<string, string | string[]> = {};\n for (const [name, value] of Object.entries(headers)) {\n if (value !== undefined && !HOP_BY_HOP.has(name)) out[name] = value;\n }\n out[route.header] = credential;\n out.host = route.port === 443 ? route.hostname : `${route.hostname}:${route.port}`;\n return out;\n }\n\n private forward(\n route: ParsedRoute,\n method: string,\n path: string,\n headers: Record<string, string | string[]>,\n body: import(\"node:stream\").Readable | Uint8Array | undefined,\n signal?: AbortSignal,\n ): Promise<RouteReply> {\n return new Promise((resolve) => {\n let upstream: import(\"node:http\").ClientRequest;\n try {\n upstream = this.openRoute(route, method, path, headers);\n } catch {\n resolve(refusal(502, \"request_invalid\"));\n return;\n }\n const stop = () => upstream.destroy(new Error(\"client gone\"));\n if (signal?.aborted === true) stop();\n else signal?.addEventListener(\"abort\", stop, { once: true });\n upstream.once(\"close\", () => signal?.removeEventListener(\"abort\", stop));\n this.requests.add(upstream);\n upstream.setTimeout(this.options.idleTimeoutMs ?? DEFAULT_IDLE_MS, () => upstream.destroy(new Error(\"idle\")));\n upstream.once(\"close\", () => this.requests.delete(upstream));\n upstream.once(\"response\", (reply) => {\n const passed: Record<string, string | string[]> = {};\n for (const [name, value] of Object.entries(reply.headers)) {\n if (value !== undefined && !HOP_BY_HOP.has(name)) passed[name] = value;\n }\n resolve({ status: reply.statusCode ?? 502, headers: passed, body: reply });\n });\n upstream.once(\"error\", (error) => resolve(refusal(502, this.reasonOf(error))));\n if (body === undefined) upstream.end();\n else if (body instanceof Uint8Array) upstream.end(body);\n else body.pipe(upstream);\n });\n }\n\n /** Opens the HTTPS request to a route's host, which throws for a header or path Node refuses. */\n private openRoute(\n route: ParsedRoute,\n method: string,\n path: string,\n headers: Record<string, string | string[]>,\n ): import(\"node:http\").ClientRequest {\n return this.modules.https.request({\n host: route.hostname,\n port: route.port,\n servername: route.hostname,\n method,\n path,\n headers,\n agent: false,\n lookup: this.checkedLookup as never,\n ...(this.options.ca === undefined ? {} : { ca: this.options.ca as never }),\n });\n }\n\n /** An in-process fetch under the same allowlist, with the same address checks and pinned connection. */\n async fetch(input: string | URL, init?: RequestInit): Promise<Response> {\n const request = new Request(input, init);\n request.signal.throwIfAborted();\n const url = new URL(request.url);\n const host = url.hostname.toLowerCase().replace(/\\.$/, \"\");\n const port = url.port === \"\" ? 443 : Number(url.port);\n const bodyBytes =\n request.method === \"GET\" || request.method === \"HEAD\" ? undefined : new Uint8Array(await request.arrayBuffer());\n if (url.origin === ROUTE_ORIGIN || (this.origin !== \"\" && url.origin === this.origin)) {\n return this.fetchRoute(request, url, bodyBytes);\n }\n const refuse = (reason: string): never => {\n this.record({ kind: \"fetch\", host, port, method: request.method, status: 403, bytes: 0, reason });\n throw new HarnessError(\"egress_denied\", `the egress proxy refused ${url.host}: ${reason}`);\n };\n if (url.protocol !== \"https:\") return refuse(\"only_https\");\n if (isAddressLiteral(host)) return refuse(\"address_literal\");\n if (!isAllowed(this.allow, host, port)) return refuse(\"not_allowed\");\n return this.sendFetch(request, url, host, port, bodyBytes);\n }\n\n private async fetchRoute(request: Request, url: URL, body: Uint8Array | undefined): Promise<Response> {\n const headers: Record<string, string> = {};\n request.headers.forEach((value, name) => {\n headers[name.toLowerCase()] = value;\n });\n const path = `${url.pathname}${url.search}`;\n const { reply, base } = await this.routeRequest(request.method, path, headers, body, request.signal);\n const stream = reply.body;\n let bytes = 0;\n stream?.on(\"data\", (chunk: Buffer) => {\n bytes += chunk.length;\n });\n const finished = () =>\n this.record({\n ...base,\n status: reply.status,\n bytes,\n ...(reply.reason === undefined ? {} : { reason: reply.reason }),\n });\n if (stream === undefined) finished();\n else stream.once(\"close\", finished);\n return this.toResponse(reply.status, reply.headers, stream);\n }\n\n private sendFetch(\n request: Request,\n url: URL,\n host: string,\n port: number,\n body: Uint8Array | undefined,\n ): Promise<Response> {\n return new Promise((resolve, reject) => {\n const headers: Record<string, string> = {};\n request.headers.forEach((value, name) => {\n if (!HOP_BY_HOP.has(name.toLowerCase())) headers[name] = value;\n });\n const upstream = this.modules.https.request({\n host,\n port,\n servername: host,\n method: request.method,\n path: `${url.pathname}${url.search}`,\n headers: { ...headers, host: url.host },\n agent: false,\n lookup: this.checkedLookup as never,\n ...(this.options.ca === undefined ? {} : { ca: this.options.ca as never }),\n });\n this.requests.add(upstream);\n const abort = () => upstream.destroy(request.signal.reason as Error);\n request.signal.addEventListener(\"abort\", abort, { once: true });\n upstream.once(\"close\", () => {\n this.requests.delete(upstream);\n request.signal.removeEventListener(\"abort\", abort);\n });\n upstream.setTimeout(this.options.idleTimeoutMs ?? DEFAULT_IDLE_MS, () => upstream.destroy(new Error(\"idle\")));\n upstream.once(\"response\", (reply) => {\n let bytes = 0;\n reply.on(\"data\", (chunk: Buffer) => {\n bytes += chunk.length;\n });\n // The record is written when the response is done with, which also covers one that is never read to its end.\n reply.once(\"close\", () =>\n this.record({ kind: \"fetch\", host, port, method: request.method, status: reply.statusCode ?? 0, bytes }),\n );\n resolve(this.toResponse(reply.statusCode ?? 502, reply.headers as Record<string, string | string[]>, reply));\n });\n upstream.once(\"error\", (error) => {\n if (request.signal.aborted) {\n reject(request.signal.reason);\n return;\n }\n const reason = this.reasonOf(error);\n this.record({ kind: \"fetch\", host, port, method: request.method, status: 502, bytes: 0, reason });\n reject(\n new HarnessError(\"egress_denied\", `the egress proxy could not reach ${url.host}: ${reason}`, {\n cause: error,\n }),\n );\n });\n upstream.end(body);\n });\n }\n\n private toResponse(\n status: number,\n headers: Record<string, string | string[]>,\n stream: import(\"node:stream\").Readable | undefined,\n ): Response {\n const out = new Headers();\n for (const [name, value] of Object.entries(headers)) {\n for (const one of Array.isArray(value) ? value : [value]) out.append(name, one);\n }\n const bodiless = stream === undefined || [101, 204, 205, 304].includes(status);\n // A response with no body is drained, so its socket and its log record don't wait for a reader that never comes.\n if (bodiless) stream?.resume();\n const web = bodiless ? null : (this.modules.stream.Readable.toWeb(stream) as ReadableStream);\n return new Response(web, { status, headers: out });\n }\n\n async knownSecrets(): Promise<readonly string[]> {\n const secrets = await Promise.all([...this.routes.values()].map((route) => route.secret().catch(() => \"\")));\n return [...new Set(secrets.filter((secret) => secret !== \"\"))];\n }\n\n close(server: import(\"node:http\").Server): Promise<void> {\n return new Promise((resolve) => {\n for (const socket of this.sockets) socket.destroy();\n for (const request of this.requests) request.destroy();\n server.close(() => resolve());\n server.closeAllConnections();\n });\n }\n}\n\n/**\n * Starts the egress proxy on `127.0.0.1` with a port the system picks, or on `socketPath`. The allowlist and routes are\n * checked first, and a bad entry throws `invalid_egress_options`. Give the sandbox `proxy.url` as `HTTPS_PROXY`, and\n * give a tool that needs a credential the route's URL and its sentinel.\n */\nexport async function startEgressProxy(options: EgressProxyOptions): Promise<EgressProxy> {\n const modules = nodeModules();\n const proxy = new EgressGate(modules, options);\n const server = modules.http.createServer((request, response) => proxy.handleRequest(request, response));\n server.on(\"connect\", (request, socket, head) => proxy.handleConnect(request, socket as never, head));\n server.on(\"clientError\", (_error, socket) => socket.destroy());\n await new Promise<void>((resolve, reject) => {\n server.once(\"error\", reject);\n if (options.socketPath === undefined) server.listen(0, \"127.0.0.1\", resolve);\n else server.listen(options.socketPath, resolve);\n });\n const address = server.address();\n const url =\n options.socketPath !== undefined\n ? `unix:${options.socketPath}`\n : `http://127.0.0.1:${(address as { port: number }).port}`;\n if (options.socketPath === undefined) proxy.setOrigin(url);\n return {\n url,\n ...(options.socketPath === undefined ? {} : { socketPath: options.socketPath }),\n sentinels: proxy.sentinelMap(),\n fetch: (input, init) => proxy.fetch(input, init),\n knownSecrets: () => proxy.knownSecrets(),\n close: () => proxy.close(server),\n };\n}\n"]}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `@buildanagent/harness/credentials`: the credential boundary. `startEgressProxy()` is a host-side, default-deny
3
+ * egress proxy that logs each request, injects a host-scoped credential on a local route when the sentinel matches, and
4
+ * gates an in-process fetch under the same allowlist. `scrubSecrets()` removes known secrets from an entry before it is
5
+ * appended. The proxy is Node-only; the scrubber and the address check are portable.
6
+ */
7
+ export { isAddressLiteral, isPublicAddress } from "./addresses.js";
8
+ export { type CredentialRoute, type EgressProxy, type EgressProxyOptions, type EgressRecord, startEgressProxy, } from "./egress-proxy.js";
9
+ export { REDACTED, scrubSecrets } from "./scrub.js";
@@ -0,0 +1,10 @@
1
+ /**
2
+ * `@buildanagent/harness/credentials`: the credential boundary. `startEgressProxy()` is a host-side, default-deny
3
+ * egress proxy that logs each request, injects a host-scoped credential on a local route when the sentinel matches, and
4
+ * gates an in-process fetch under the same allowlist. `scrubSecrets()` removes known secrets from an entry before it is
5
+ * appended. The proxy is Node-only; the scrubber and the address check are portable.
6
+ */
7
+ export { isAddressLiteral, isPublicAddress } from "./addresses.js";
8
+ export { startEgressProxy, } from "./egress-proxy.js";
9
+ export { REDACTED, scrubSecrets } from "./scrub.js";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/credentials/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAKL,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC","sourcesContent":["/**\n * `@buildanagent/harness/credentials`: the credential boundary. `startEgressProxy()` is a host-side, default-deny\n * egress proxy that logs each request, injects a host-scoped credential on a local route when the sentinel matches, and\n * gates an in-process fetch under the same allowlist. `scrubSecrets()` removes known secrets from an entry before it is\n * appended. The proxy is Node-only; the scrubber and the address check are portable.\n */\nexport { isAddressLiteral, isPublicAddress } from \"./addresses.js\";\nexport {\n type CredentialRoute,\n type EgressProxy,\n type EgressProxyOptions,\n type EgressRecord,\n startEgressProxy,\n} from \"./egress-proxy.js\";\nexport { REDACTED, scrubSecrets } from \"./scrub.js\";\n"]}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * `scrubSecrets()`: removes known secrets from a session entry before it is appended, so a credential that reached a
3
+ * tool result, a model message or an error never reaches the log. It is the net under the credential boundary, not the
4
+ * boundary itself: the boundary keeps the secret out of the sandbox, and this catches what a host-side tool wrote
5
+ * anyway. It is pure and portable.
6
+ */
7
+ import type { SessionEntry } from "@buildanagent/protocol";
8
+ /** What replaces a secret. */
9
+ export declare const REDACTED = "[REDACTED]";
10
+ /**
11
+ * Returns a copy of `entry` with every secret replaced by `[REDACTED]`, in every string value and every key, at any depth.
12
+ * A secret is also removed when it appears percent-encoded, JSON-escaped or in base64. The entry's `type`, `id`,
13
+ * `parentId`, `seq`, `timestamp`, `origin` and `formatVersion` are kept as they are. An empty secret is ignored, and a short one redacts
14
+ * every place it occurs, so pass real credentials. The input is not changed.
15
+ */
16
+ export declare function scrubSecrets<T extends SessionEntry>(entry: T, secrets: readonly string[]): T;