@buildanagent/harness 0.0.0-stage → 0.1.0-alpha.29

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 (397) hide show
  1. package/LICENSE +54 -0
  2. package/LICENSE-APACHE +202 -0
  3. package/LICENSE-MIT +21 -0
  4. package/README.md +822 -2
  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 +15 -0
  30. package/dist/context/file-spill.js +40 -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 +10 -0
  48. package/dist/context/spill.js +18 -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 +54 -0
  69. package/dist/credentials/allowlist.js +134 -0
  70. package/dist/credentials/allowlist.js.map +1 -0
  71. package/dist/credentials/egress-policy.d.ts +69 -0
  72. package/dist/credentials/egress-policy.js +170 -0
  73. package/dist/credentials/egress-policy.js.map +1 -0
  74. package/dist/credentials/egress-proxy.d.ts +82 -0
  75. package/dist/credentials/egress-proxy.js +650 -0
  76. package/dist/credentials/egress-proxy.js.map +1 -0
  77. package/dist/credentials/git-route.d.ts +68 -0
  78. package/dist/credentials/git-route.js +288 -0
  79. package/dist/credentials/git-route.js.map +1 -0
  80. package/dist/credentials/index.d.ts +13 -0
  81. package/dist/credentials/index.js +14 -0
  82. package/dist/credentials/index.js.map +1 -0
  83. package/dist/credentials/scrub.d.ts +23 -0
  84. package/dist/credentials/scrub.js +115 -0
  85. package/dist/credentials/scrub.js.map +1 -0
  86. package/dist/errors.d.ts +60 -0
  87. package/dist/errors.js +67 -0
  88. package/dist/errors.js.map +1 -0
  89. package/dist/extensions/compose.d.ts +27 -0
  90. package/dist/extensions/compose.js +83 -0
  91. package/dist/extensions/compose.js.map +1 -0
  92. package/dist/extensions/context-files-node.d.ts +28 -0
  93. package/dist/extensions/context-files-node.js +74 -0
  94. package/dist/extensions/context-files-node.js.map +1 -0
  95. package/dist/extensions/context-files.d.ts +68 -0
  96. package/dist/extensions/context-files.js +214 -0
  97. package/dist/extensions/context-files.js.map +1 -0
  98. package/dist/extensions/digest.d.ts +6 -0
  99. package/dist/extensions/digest.js +68 -0
  100. package/dist/extensions/digest.js.map +1 -0
  101. package/dist/extensions/index.d.ts +10 -0
  102. package/dist/extensions/index.js +10 -0
  103. package/dist/extensions/index.js.map +1 -0
  104. package/dist/extensions/load.d.ts +42 -0
  105. package/dist/extensions/load.js +211 -0
  106. package/dist/extensions/load.js.map +1 -0
  107. package/dist/extensions/lock.d.ts +8 -0
  108. package/dist/extensions/lock.js +95 -0
  109. package/dist/extensions/lock.js.map +1 -0
  110. package/dist/extensions/node.d.ts +10 -0
  111. package/dist/extensions/node.js +11 -0
  112. package/dist/extensions/node.js.map +1 -0
  113. package/dist/extensions/project-dirs.d.ts +24 -0
  114. package/dist/extensions/project-dirs.js +97 -0
  115. package/dist/extensions/project-dirs.js.map +1 -0
  116. package/dist/extensions/skills-node.d.ts +34 -0
  117. package/dist/extensions/skills-node.js +123 -0
  118. package/dist/extensions/skills-node.js.map +1 -0
  119. package/dist/extensions/skills.d.ts +51 -0
  120. package/dist/extensions/skills.js +175 -0
  121. package/dist/extensions/skills.js.map +1 -0
  122. package/dist/extensions/trust-file.d.ts +3 -0
  123. package/dist/extensions/trust-file.js +62 -0
  124. package/dist/extensions/trust-file.js.map +1 -0
  125. package/dist/extensions/trust-store-node.d.ts +10 -0
  126. package/dist/extensions/trust-store-node.js +33 -0
  127. package/dist/extensions/trust-store-node.js.map +1 -0
  128. package/dist/extensions/types.d.ts +42 -0
  129. package/dist/extensions/types.js +2 -0
  130. package/dist/extensions/types.js.map +1 -0
  131. package/dist/harness.d.ts +156 -0
  132. package/dist/harness.js +2 -0
  133. package/dist/harness.js.map +1 -0
  134. package/dist/index.d.ts +4 -0
  135. package/dist/index.js +5 -0
  136. package/dist/index.js.map +1 -0
  137. package/dist/mcp/connection.d.ts +22 -0
  138. package/dist/mcp/connection.js +267 -0
  139. package/dist/mcp/connection.js.map +1 -0
  140. package/dist/mcp/content.d.ts +27 -0
  141. package/dist/mcp/content.js +177 -0
  142. package/dist/mcp/content.js.map +1 -0
  143. package/dist/mcp/errors.d.ts +19 -0
  144. package/dist/mcp/errors.js +21 -0
  145. package/dist/mcp/errors.js.map +1 -0
  146. package/dist/mcp/index.d.ts +10 -0
  147. package/dist/mcp/index.js +10 -0
  148. package/dist/mcp/index.js.map +1 -0
  149. package/dist/mcp/manager.d.ts +7 -0
  150. package/dist/mcp/manager.js +173 -0
  151. package/dist/mcp/manager.js.map +1 -0
  152. package/dist/mcp/record.d.ts +7 -0
  153. package/dist/mcp/record.js +20 -0
  154. package/dist/mcp/record.js.map +1 -0
  155. package/dist/mcp/stdio.d.ts +39 -0
  156. package/dist/mcp/stdio.js +382 -0
  157. package/dist/mcp/stdio.js.map +1 -0
  158. package/dist/mcp/types.d.ts +172 -0
  159. package/dist/mcp/types.js +2 -0
  160. package/dist/mcp/types.js.map +1 -0
  161. package/dist/memory/index.d.ts +2 -0
  162. package/dist/memory/index.js +3 -0
  163. package/dist/memory/index.js.map +1 -0
  164. package/dist/permissions/default-rules.d.ts +7 -0
  165. package/dist/permissions/default-rules.js +42 -0
  166. package/dist/permissions/default-rules.js.map +1 -0
  167. package/dist/permissions/errors.d.ts +11 -0
  168. package/dist/permissions/errors.js +14 -0
  169. package/dist/permissions/errors.js.map +1 -0
  170. package/dist/permissions/index.d.ts +9 -0
  171. package/dist/permissions/index.js +9 -0
  172. package/dist/permissions/index.js.map +1 -0
  173. package/dist/permissions/match.d.ts +33 -0
  174. package/dist/permissions/match.js +287 -0
  175. package/dist/permissions/match.js.map +1 -0
  176. package/dist/permissions/pipeline.d.ts +9 -0
  177. package/dist/permissions/pipeline.js +235 -0
  178. package/dist/permissions/pipeline.js.map +1 -0
  179. package/dist/permissions/rules.d.ts +22 -0
  180. package/dist/permissions/rules.js +74 -0
  181. package/dist/permissions/rules.js.map +1 -0
  182. package/dist/permissions/shadow.d.ts +5 -0
  183. package/dist/permissions/shadow.js +22 -0
  184. package/dist/permissions/shadow.js.map +1 -0
  185. package/dist/permissions/types.d.ts +104 -0
  186. package/dist/permissions/types.js +2 -0
  187. package/dist/permissions/types.js.map +1 -0
  188. package/dist/sandbox/base.d.ts +45 -0
  189. package/dist/sandbox/base.js +74 -0
  190. package/dist/sandbox/base.js.map +1 -0
  191. package/dist/sandbox/docker/index.d.ts +41 -0
  192. package/dist/sandbox/docker/index.js +497 -0
  193. package/dist/sandbox/docker/index.js.map +1 -0
  194. package/dist/sandbox/errors.d.ts +44 -0
  195. package/dist/sandbox/errors.js +57 -0
  196. package/dist/sandbox/errors.js.map +1 -0
  197. package/dist/sandbox/host-files.d.ts +65 -0
  198. package/dist/sandbox/host-files.js +258 -0
  199. package/dist/sandbox/host-files.js.map +1 -0
  200. package/dist/sandbox/index.d.ts +10 -0
  201. package/dist/sandbox/index.js +10 -0
  202. package/dist/sandbox/index.js.map +1 -0
  203. package/dist/sandbox/none.d.ts +17 -0
  204. package/dist/sandbox/none.js +108 -0
  205. package/dist/sandbox/none.js.map +1 -0
  206. package/dist/sandbox/policy.d.ts +49 -0
  207. package/dist/sandbox/policy.js +149 -0
  208. package/dist/sandbox/policy.js.map +1 -0
  209. package/dist/sandbox/process.d.ts +61 -0
  210. package/dist/sandbox/process.js +253 -0
  211. package/dist/sandbox/process.js.map +1 -0
  212. package/dist/sandbox/spawn-env.d.ts +20 -0
  213. package/dist/sandbox/spawn-env.js +128 -0
  214. package/dist/sandbox/spawn-env.js.map +1 -0
  215. package/dist/sandbox/srt/index.d.ts +38 -0
  216. package/dist/sandbox/srt/index.js +283 -0
  217. package/dist/sandbox/srt/index.js.map +1 -0
  218. package/dist/sandbox/srt/settings.d.ts +60 -0
  219. package/dist/sandbox/srt/settings.js +84 -0
  220. package/dist/sandbox/srt/settings.js.map +1 -0
  221. package/dist/sandbox/types.d.ts +125 -0
  222. package/dist/sandbox/types.js +6 -0
  223. package/dist/sandbox/types.js.map +1 -0
  224. package/dist/server/answers.d.ts +16 -0
  225. package/dist/server/answers.js +43 -0
  226. package/dist/server/answers.js.map +1 -0
  227. package/dist/server/connection.d.ts +99 -0
  228. package/dist/server/connection.js +309 -0
  229. package/dist/server/connection.js.map +1 -0
  230. package/dist/server/dispatcher.d.ts +86 -0
  231. package/dist/server/dispatcher.js +800 -0
  232. package/dist/server/dispatcher.js.map +1 -0
  233. package/dist/server/index.d.ts +13 -0
  234. package/dist/server/index.js +12 -0
  235. package/dist/server/index.js.map +1 -0
  236. package/dist/server/local-transport.d.ts +44 -0
  237. package/dist/server/local-transport.js +103 -0
  238. package/dist/server/local-transport.js.map +1 -0
  239. package/dist/server/outbox.d.ts +31 -0
  240. package/dist/server/outbox.js +130 -0
  241. package/dist/server/outbox.js.map +1 -0
  242. package/dist/server/params.d.ts +25 -0
  243. package/dist/server/params.js +112 -0
  244. package/dist/server/params.js.map +1 -0
  245. package/dist/server/protocol.schema.json +2448 -0
  246. package/dist/server/rpc-session.d.ts +43 -0
  247. package/dist/server/rpc-session.js +167 -0
  248. package/dist/server/rpc-session.js.map +1 -0
  249. package/dist/server/stdio-streams.d.ts +67 -0
  250. package/dist/server/stdio-streams.js +218 -0
  251. package/dist/server/stdio-streams.js.map +1 -0
  252. package/dist/server/stdio.d.ts +59 -0
  253. package/dist/server/stdio.js +189 -0
  254. package/dist/server/stdio.js.map +1 -0
  255. package/dist/server/websocket.d.ts +106 -0
  256. package/dist/server/websocket.js +327 -0
  257. package/dist/server/websocket.js.map +1 -0
  258. package/dist/session/approvals.d.ts +81 -0
  259. package/dist/session/approvals.js +217 -0
  260. package/dist/session/approvals.js.map +1 -0
  261. package/dist/session/code-call-log.d.ts +42 -0
  262. package/dist/session/code-call-log.js +63 -0
  263. package/dist/session/code-call-log.js.map +1 -0
  264. package/dist/session/code-call-result.d.ts +19 -0
  265. package/dist/session/code-call-result.js +95 -0
  266. package/dist/session/code-call-result.js.map +1 -0
  267. package/dist/session/code-call.d.ts +49 -0
  268. package/dist/session/code-call.js +345 -0
  269. package/dist/session/code-call.js.map +1 -0
  270. package/dist/session/effect-scope.d.ts +11 -0
  271. package/dist/session/effect-scope.js +10 -0
  272. package/dist/session/effect-scope.js.map +1 -0
  273. package/dist/session/errors.d.ts +19 -0
  274. package/dist/session/errors.js +27 -0
  275. package/dist/session/errors.js.map +1 -0
  276. package/dist/session/file-index.d.ts +8 -0
  277. package/dist/session/file-index.js +70 -0
  278. package/dist/session/file-index.js.map +1 -0
  279. package/dist/session/file-key-store.d.ts +16 -0
  280. package/dist/session/file-key-store.js +169 -0
  281. package/dist/session/file-key-store.js.map +1 -0
  282. package/dist/session/file-lock.d.ts +52 -0
  283. package/dist/session/file-lock.js +324 -0
  284. package/dist/session/file-lock.js.map +1 -0
  285. package/dist/session/index.d.ts +22 -0
  286. package/dist/session/index.js +20 -0
  287. package/dist/session/index.js.map +1 -0
  288. package/dist/session/jsonl-store.d.ts +37 -0
  289. package/dist/session/jsonl-store.js +386 -0
  290. package/dist/session/jsonl-store.js.map +1 -0
  291. package/dist/session/jsonl.d.ts +9 -0
  292. package/dist/session/jsonl.js +10 -0
  293. package/dist/session/jsonl.js.map +1 -0
  294. package/dist/session/lock.d.ts +19 -0
  295. package/dist/session/lock.js +2 -0
  296. package/dist/session/lock.js.map +1 -0
  297. package/dist/session/memory-store.d.ts +12 -0
  298. package/dist/session/memory-store.js +60 -0
  299. package/dist/session/memory-store.js.map +1 -0
  300. package/dist/session/migrate.d.ts +41 -0
  301. package/dist/session/migrate.js +86 -0
  302. package/dist/session/migrate.js.map +1 -0
  303. package/dist/session/pointer.d.ts +15 -0
  304. package/dist/session/pointer.js +22 -0
  305. package/dist/session/pointer.js.map +1 -0
  306. package/dist/session/rebuild.d.ts +53 -0
  307. package/dist/session/rebuild.js +230 -0
  308. package/dist/session/rebuild.js.map +1 -0
  309. package/dist/session/resume.d.ts +26 -0
  310. package/dist/session/resume.js +128 -0
  311. package/dist/session/resume.js.map +1 -0
  312. package/dist/session/retention.d.ts +97 -0
  313. package/dist/session/retention.js +702 -0
  314. package/dist/session/retention.js.map +1 -0
  315. package/dist/session/runner.d.ts +156 -0
  316. package/dist/session/runner.js +656 -0
  317. package/dist/session/runner.js.map +1 -0
  318. package/dist/session/scheduler.d.ts +47 -0
  319. package/dist/session/scheduler.js +85 -0
  320. package/dist/session/scheduler.js.map +1 -0
  321. package/dist/session/secret-key-store.d.ts +47 -0
  322. package/dist/session/secret-key-store.js +79 -0
  323. package/dist/session/secret-key-store.js.map +1 -0
  324. package/dist/session/session.d.ts +106 -0
  325. package/dist/session/session.js +353 -0
  326. package/dist/session/session.js.map +1 -0
  327. package/dist/session/sticky.d.ts +48 -0
  328. package/dist/session/sticky.js +232 -0
  329. package/dist/session/sticky.js.map +1 -0
  330. package/dist/session/store.d.ts +108 -0
  331. package/dist/session/store.js +163 -0
  332. package/dist/session/store.js.map +1 -0
  333. package/dist/telemetry/index.d.ts +2 -0
  334. package/dist/telemetry/index.js +3 -0
  335. package/dist/telemetry/index.js.map +1 -0
  336. package/dist/testing/fake-sandbox.d.ts +52 -0
  337. package/dist/testing/fake-sandbox.js +370 -0
  338. package/dist/testing/fake-sandbox.js.map +1 -0
  339. package/dist/testing/index.d.ts +10 -0
  340. package/dist/testing/index.js +11 -0
  341. package/dist/testing/index.js.map +1 -0
  342. package/dist/testing/key-store-conformance.d.ts +22 -0
  343. package/dist/testing/key-store-conformance.js +97 -0
  344. package/dist/testing/key-store-conformance.js.map +1 -0
  345. package/dist/testing/run-cases.d.ts +21 -0
  346. package/dist/testing/run-cases.js +20 -0
  347. package/dist/testing/run-cases.js.map +1 -0
  348. package/dist/testing/sandbox-conformance.d.ts +64 -0
  349. package/dist/testing/sandbox-conformance.js +468 -0
  350. package/dist/testing/sandbox-conformance.js.map +1 -0
  351. package/dist/testing/scheduler-conformance.d.ts +32 -0
  352. package/dist/testing/scheduler-conformance.js +72 -0
  353. package/dist/testing/scheduler-conformance.js.map +1 -0
  354. package/dist/testing/store-conformance.d.ts +21 -0
  355. package/dist/testing/store-conformance.js +320 -0
  356. package/dist/testing/store-conformance.js.map +1 -0
  357. package/dist/tools/builtins/bash.d.ts +9 -0
  358. package/dist/tools/builtins/bash.js +75 -0
  359. package/dist/tools/builtins/bash.js.map +1 -0
  360. package/dist/tools/builtins/builtins.d.ts +38 -0
  361. package/dist/tools/builtins/builtins.js +48 -0
  362. package/dist/tools/builtins/builtins.js.map +1 -0
  363. package/dist/tools/builtins/descriptions.d.ts +69 -0
  364. package/dist/tools/builtins/descriptions.js +94 -0
  365. package/dist/tools/builtins/descriptions.js.map +1 -0
  366. package/dist/tools/builtins/fetch.d.ts +12 -0
  367. package/dist/tools/builtins/fetch.js +157 -0
  368. package/dist/tools/builtins/fetch.js.map +1 -0
  369. package/dist/tools/builtins/files.d.ts +27 -0
  370. package/dist/tools/builtins/files.js +274 -0
  371. package/dist/tools/builtins/files.js.map +1 -0
  372. package/dist/tools/builtins/paths.d.ts +30 -0
  373. package/dist/tools/builtins/paths.js +62 -0
  374. package/dist/tools/builtins/paths.js.map +1 -0
  375. package/dist/tools/builtins/results.d.ts +15 -0
  376. package/dist/tools/builtins/results.js +31 -0
  377. package/dist/tools/builtins/results.js.map +1 -0
  378. package/dist/tools/builtins/search.d.ts +18 -0
  379. package/dist/tools/builtins/search.js +217 -0
  380. package/dist/tools/builtins/search.js.map +1 -0
  381. package/dist/tools/errors.d.ts +13 -0
  382. package/dist/tools/errors.js +17 -0
  383. package/dist/tools/errors.js.map +1 -0
  384. package/dist/tools/index.d.ts +12 -0
  385. package/dist/tools/index.js +11 -0
  386. package/dist/tools/index.js.map +1 -0
  387. package/dist/tools/registry.d.ts +3 -0
  388. package/dist/tools/registry.js +234 -0
  389. package/dist/tools/registry.js.map +1 -0
  390. package/dist/tools/tool-search.d.ts +30 -0
  391. package/dist/tools/tool-search.js +118 -0
  392. package/dist/tools/tool-search.js.map +1 -0
  393. package/dist/tools/types.d.ts +106 -0
  394. package/dist/tools/types.js +2 -0
  395. package/dist/tools/types.js.map +1 -0
  396. package/llms.txt +469 -0
  397. package/package.json +118 -3
@@ -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;AACxB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAuB,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AA0FtH,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,aAA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;IAC3D,OAAO;QACL,GAAG;QACH,GAAG,CAAC,OAAO,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC;QAC/E,SAAS,EAAE,KAAK,CAAC,WAAW,EAAE;QAC9B,KAAK,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC;QAChD,YAAY,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,YAAY,EAAE;QACxC,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC;KACjC,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\";\nimport { basicCarries, basicHeader, type GitRouteFilter, gitEndpoint, PushReader, pushVerdict } from \"./git-route.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 /**\n * Ends a tunnel, a forwarded request or a push check that is idle this long. A whole number of milliseconds from 0 to\n * 2,147,483,647, where 0 turns the idle timeout off, as it does for a socket; anything else throws\n * `invalid_egress_options` when the proxy starts. Defaults to 120000.\n */\n readonly idleTimeoutMs?: number;\n /**\n * The longest a push's command list may take to arrive, from the start of its body, however often bytes come. The\n * clock starts once and is never reset, so a client that sends a byte just inside the idle timeout is still cut off;\n * a push that takes longer is refused with `git_timeout`. Only the command list is timed, not the pack after it. A\n * whole number of milliseconds from 1 to 2,147,483,647; anything else throws `invalid_egress_options` when the proxy\n * starts. Defaults to 60000.\n */\n readonly pushCheckTimeoutMs?: 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;\nconst DEFAULT_PUSH_CHECK_MS = 60_000;\n// How much of a refused request's unread body is discarded, and for how long, before its connection is closed.\nconst LINGER_BYTES = 1024 * 1024;\nconst LINGER_MS = 1000;\n// The longest delay a timer takes; past it, `setTimeout` fires at once.\nconst MAX_TIMER_MS = 2_147_483_647;\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\n/**\n * The answer to a git request whose credential is missing or wrong, or `undefined` when its HTTP Basic password is the\n * route's sentinel. A missing one gets 401 with a Basic challenge, so git asks its credential helper.\n */\nfunction gitCredentialRefusal(presented: string | string[] | undefined, sentinel: string): RouteReply | undefined {\n if (presented === undefined) {\n return { ...refusal(401, \"git_credential_missing\"), headers: { \"www-authenticate\": 'Basic realm=\"egress\"' } };\n }\n return typeof presented === \"string\" && basicCarries(presented, sentinel) ? undefined : refusal(403, \"bad_sentinel\");\n}\n\n/**\n * Checks a timeout option and returns the value to use: `fallback` when it is unset, or a whole number of milliseconds\n * from `min` to the longest delay a timer takes. The message names the option and never quotes the value.\n */\nfunction timeoutOption(name: string, ms: unknown, min: number, fallback: number): number {\n if (ms === undefined) return fallback;\n if (typeof ms === \"number\" && Number.isInteger(ms) && ms >= min && ms <= MAX_TIMER_MS) return ms;\n throw new HarnessError(\n \"invalid_egress_options\",\n `${name} must be a whole number of milliseconds from ${min} to ${MAX_TIMER_MS}`,\n );\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 readonly pushCheckMs: number;\n // 0 means no idle timeout, as it does for `socket.setTimeout`.\n private readonly idleMs: number;\n private origin = \"\";\n\n constructor(modules: Modules, options: EgressProxyOptions) {\n this.modules = modules;\n this.options = options;\n this.idleMs = timeoutOption(\"idleTimeoutMs\", options.idleTimeoutMs, 0, DEFAULT_IDLE_MS);\n this.pushCheckMs = timeoutOption(\"pushCheckTimeoutMs\", options.pushCheckTimeoutMs, 1, DEFAULT_PUSH_CHECK_MS);\n this.allow = parseAllow(options.allow);\n this.routes = new Map(parseRoutes(options.routes ?? [], this.allow).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.idleMs, () => upstream.destroy(Object.assign(new Error(\"idle\"), { code: \"ETIMEDOUT\" })));\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, request),\n () => this.finish(response, refusal(502, \"request_failed\"), base, request),\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 request?: import(\"node:http\").IncomingMessage,\n ): void {\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 && reply.status >= 400 && request !== undefined && !request.complete) {\n this.refuseAndClose(request, response, reply);\n report();\n return;\n }\n response.writeHead(reply.status, reply.headers);\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 * Refuses a request whose body has not been read to its end, and closes its connection. Node would otherwise read and\n * discard the rest of the body, a whole pack perhaps, to keep the connection alive. The answer is written whole, with\n * its length and `Connection: close`, and the response is ended, which closes the socket, only after the bytes already\n * on their way are discarded, up to `LINGER_BYTES` or for `LINGER_MS`. Closing a socket with unread bytes resets the\n * connection, and a client that has not yet read the answer would lose it.\n */\n private refuseAndClose(\n request: import(\"node:http\").IncomingMessage,\n response: import(\"node:http\").ServerResponse,\n reply: RouteReply,\n ): void {\n const text = `${reply.reason ?? \"refused\"}\\n`;\n response.writeHead(reply.status, { ...reply.headers, connection: \"close\", \"content-length\": String(text.length) });\n response.write(text);\n let discarded = 0;\n const done = () => {\n clearTimeout(timer);\n request.off(\"data\", onData);\n request.off(\"end\", done);\n request.off(\"close\", done);\n request.pause();\n response.end();\n };\n const onData = (chunk: Uint8Array) => {\n discarded += chunk.length;\n if (discarded >= LINGER_BYTES) done();\n };\n const timer = setTimeout(done, LINGER_MS);\n request.on(\"data\", onData);\n request.once(\"end\", done);\n request.once(\"close\", done);\n request.resume();\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 target = { path: match[2] ?? \"/\", query: match[3] ?? \"\" };\n const reply =\n route.git === undefined\n ? await this.headerRequest(route, method, target, headers, body, signal)\n : await this.gitRequest(route, route.git, method, target, headers, body, signal);\n return { reply, base };\n }\n\n /** Resolves a request on a header route: it swaps the sentinel in the route's header for the secret. */\n private async headerRequest(\n route: ParsedRoute,\n method: string,\n target: { readonly path: string; readonly query: string },\n headers: Record<string, string | string[] | undefined>,\n body: import(\"node:stream\").Readable | Uint8Array | undefined,\n signal?: AbortSignal,\n ): Promise<RouteReply> {\n const presented = headers[route.header];\n const sentinel = this.sentinels[route.route] ?? \"\";\n if (typeof presented !== \"string\" || sentinel === \"\" || !presented.includes(sentinel)) {\n return refusal(403, \"bad_sentinel\");\n }\n const secret = await route.secret().catch(() => \"\");\n if (secret === \"\" || INVALID_HEADER_VALUE.test(secret)) return refusal(502, \"secret_unavailable\");\n const outgoing = this.outgoingHeaders(\n headers,\n route,\n presented.replaceAll(sentinel, () => secret),\n );\n return this.forward(route, method, `${target.path}${target.query}`, outgoing, body, signal);\n }\n\n /**\n * Resolves a request on a git route. The endpoint and repository are checked first, then the sentinel in HTTP Basic,\n * then a push's command list, and only then is the secret read and the request forwarded with it. A missing\n * credential gets 401 with a Basic challenge, so git asks its credential helper for the sentinel.\n */\n private async gitRequest(\n route: ParsedRoute,\n filter: GitRouteFilter,\n method: string,\n target: { readonly path: string; readonly query: string },\n headers: Record<string, string | string[] | undefined>,\n body: import(\"node:stream\").Readable | Uint8Array | undefined,\n signal?: AbortSignal,\n ): Promise<RouteReply> {\n const endpoint = gitEndpoint(filter, method, target.path, target.query);\n if (\"refused\" in endpoint) return refusal(403, endpoint.refused);\n const unauthorized = gitCredentialRefusal(headers.authorization, this.sentinels[route.route] ?? \"\");\n if (unauthorized !== undefined) return unauthorized;\n let forwarded = body;\n if (endpoint.service === \"git-receive-pack\" && endpoint.phase === \"rpc\") {\n const encoding = headers[\"content-encoding\"];\n if (encoding !== undefined && encoding !== \"identity\") return refusal(403, \"git_encoded_push\");\n const checked = await this.checkPush(body, filter);\n if (\"refused\" in checked) return refusal(403, checked.refused);\n forwarded = checked.body;\n }\n const secret = await route.secret().catch(() => \"\");\n if (secret === \"\" || INVALID_HEADER_VALUE.test(secret)) return refusal(502, \"secret_unavailable\");\n const outgoing = this.outgoingHeaders(headers, route, basicHeader(filter.username, secret));\n return this.forward(route, method, `${target.path}${target.query}`, outgoing, forwarded, signal);\n }\n\n /**\n * Reads a push's command list and checks it, then hands back a body that starts with what was read. `PushReader`\n * reads each chunk once, so the check is linear in the bytes however small the chunks. The check gives up once the\n * body is idle for the idle timeout, which each chunk resets, or once `pushCheckTimeoutMs` has passed since it\n * started, which nothing resets.\n */\n private checkPush(\n body: import(\"node:stream\").Readable | Uint8Array | undefined,\n filter: GitRouteFilter,\n ): Promise<{ readonly refused: string } | { readonly body: import(\"node:stream\").Readable | Uint8Array }> {\n if (body === undefined) return Promise.resolve({ refused: \"git_bad_pkt_line\" });\n if (body instanceof Uint8Array) {\n const verdict = pushVerdict(body, filter, true);\n return Promise.resolve(verdict === \"allowed\" ? { body } : { refused: (verdict as { refused: string }).refused });\n }\n return new Promise((resolve) => {\n const reader = new PushReader(filter);\n const chunks: Uint8Array[] = [];\n const timedOut = () => settle({ refused: \"git_timeout\" });\n // An idle timeout of 0 is off, so only the deadline ends a quiet body.\n const startIdle = () => (this.idleMs === 0 ? undefined : setTimeout(timedOut, this.idleMs));\n let idle = startIdle();\n const deadline = setTimeout(timedOut, this.pushCheckMs);\n const settle = (outcome: { refused: string } | { body: import(\"node:stream\").Readable }) => {\n clearTimeout(idle);\n clearTimeout(deadline);\n body.off(\"data\", onData);\n body.off(\"end\", onEnd);\n body.off(\"error\", onError);\n body.off(\"close\", onError);\n // A refused body is not read further; the answer closes its connection.\n if (\"refused\" in outcome) body.pause();\n resolve(outcome);\n };\n const judge = (verdict: ReturnType<PushReader[\"add\"]>, ended: boolean) => {\n if (verdict === \"incomplete\") return;\n if (verdict !== \"allowed\") {\n settle(verdict);\n return;\n }\n const rest = new this.modules.stream.PassThrough();\n for (const chunk of chunks) rest.write(chunk);\n settle({ body: rest });\n if (ended) rest.end();\n else body.pipe(rest);\n };\n const onData = (chunk: Uint8Array) => {\n clearTimeout(idle);\n idle = startIdle();\n chunks.push(chunk);\n judge(reader.add(chunk), false);\n };\n const onEnd = () => judge(reader.end(), true);\n const onError = () => settle({ refused: \"request_failed\" });\n body.on(\"data\", onData);\n body.once(\"end\", onEnd);\n body.once(\"error\", onError);\n // A client that goes away before its command list ends would otherwise hold the check until a timeout.\n body.once(\"close\", onError);\n });\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.idleMs, () => 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.idleMs, () => 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,68 @@
1
+ /** What a git route lets through. */
2
+ export interface GitRouteFilter {
3
+ /** The repositories the route reaches, as `owner/name`. Compared without case, as GitHub does. */
4
+ readonly repositories: readonly string[];
5
+ /**
6
+ * The branches a push may create or update, as `refs/heads/<name>` or a prefix ending in `/*`, such as
7
+ * `refs/heads/agent/*`. Leave it empty to refuse every push. A deletion and a tag are always refused.
8
+ */
9
+ readonly pushRefs: readonly string[];
10
+ /** Whether a fetch or clone may read the repositories. A fetch is not limited by ref. */
11
+ readonly fetch: boolean;
12
+ /** The user name sent with the credential in HTTP Basic, such as `x-access-token` for a GitHub App token. */
13
+ readonly username: string;
14
+ }
15
+ /** A git request the route accepts: which service, and whether it is the ref advertisement or the request itself. */
16
+ export interface GitEndpoint {
17
+ readonly service: "git-receive-pack" | "git-upload-pack";
18
+ readonly phase: "advertise" | "rpc";
19
+ }
20
+ /** The most bytes of a push's command list, before its flush, that the route reads. A longer list is refused. */
21
+ export declare const GIT_MAX_COMMAND_BYTES: number;
22
+ /** The most ref updates in one push. */
23
+ export declare const GIT_MAX_COMMANDS = 64;
24
+ /** Whether `name` is a ref name git itself would accept, by `git check-ref-format`'s rules, under `refs/`. */
25
+ export declare function isValidRefName(name: string): boolean;
26
+ /** Throws unless every field of a git route's filter is usable. The message names the field, never its value. */
27
+ export declare function checkGitFilter(filter: GitRouteFilter): void;
28
+ /**
29
+ * The git endpoint a request is for, or the reason it is refused. `path` is the part after the route's name, and
30
+ * `query` is the search part with its `?`, or empty.
31
+ */
32
+ export declare function gitEndpoint(filter: GitRouteFilter, method: string, path: string, query: string): GitEndpoint | {
33
+ readonly refused: string;
34
+ };
35
+ /** A push check's verdict so far: `incomplete` until the command list reaches its flush, or the route's verdict. */
36
+ export type PushCheckVerdict = "incomplete" | "allowed" | {
37
+ readonly refused: string;
38
+ };
39
+ /**
40
+ * Reads the command list at the start of a push body as the body arrives, in pieces of any size, and gives the route's
41
+ * verdict once it can. The work is linear in the bytes received: pieces are joined only once they hold the next
42
+ * pkt-line's header or the whole line, and a line already read is never read again. A list whose lines end past
43
+ * `GIT_MAX_COMMAND_BYTES` is refused as soon as a header says so, however the body is split.
44
+ */
45
+ export declare class PushReader {
46
+ #private;
47
+ constructor(filter: GitRouteFilter);
48
+ /** Reads the next piece of the body and returns the verdict so far. Bytes after a verdict are not read. */
49
+ add(chunk: Uint8Array): PushCheckVerdict;
50
+ /** Says the body has ended and returns the final verdict: a list still incomplete is refused. */
51
+ end(): "allowed" | {
52
+ readonly refused: string;
53
+ };
54
+ }
55
+ /**
56
+ * The route's verdict on the start of a push body: `incomplete` while the command list hasn't reached its flush,
57
+ * `allowed` once every command creates or updates a ref the patterns allow, or the reason it is refused. A body that is
58
+ * exactly one flush packet, the probe git sends before a large push, is `allowed` once it has ended, because it updates
59
+ * no ref; a byte after that flush is refused. `ended` says the body has no more bytes, so a list still incomplete is
60
+ * refused. A list whose lines end past `GIT_MAX_COMMAND_BYTES` is refused, whether or not its flush has arrived.
61
+ */
62
+ export declare function pushVerdict(bytes: Uint8Array, filter: GitRouteFilter, ended: boolean): "incomplete" | "allowed" | {
63
+ readonly refused: string;
64
+ };
65
+ /** Whether an `Authorization` header is HTTP Basic whose password is exactly `sentinel`. */
66
+ export declare function basicCarries(header: string | undefined, sentinel: string): boolean;
67
+ /** The `Authorization` value that carries `secret` as the password of `username`. */
68
+ export declare function basicHeader(username: string, secret: string): string;
@@ -0,0 +1,288 @@
1
+ /**
2
+ * The checks of a git route: git's smart HTTP protocol over a credential route, limited to listed repositories and,
3
+ * for a push, to listed branches. It is pure and portable, so the proxy and any other backend can share it. Everything
4
+ * it doesn't understand is refused: an unknown path, a query, a push certificate, a pkt-line it can't read, a command
5
+ * list past its size limit, a deletion, a tag and any ref outside the patterns.
6
+ */
7
+ import { HarnessError } from "../errors.js";
8
+ /** The most bytes of a push's command list, before its flush, that the route reads. A longer list is refused. */
9
+ export const GIT_MAX_COMMAND_BYTES = 64 * 1024;
10
+ /** The most ref updates in one push. */
11
+ export const GIT_MAX_COMMANDS = 64;
12
+ const PKT_MAX = 65520;
13
+ const SEGMENT = /^[A-Za-z0-9_.-]+$/;
14
+ const REPOSITORY_PATH = /^\/([^/]+)\/([^/]+)\/(info\/refs|git-receive-pack|git-upload-pack)$/;
15
+ const OID = "([0-9a-f]{40}|[0-9a-f]{64})";
16
+ const COMMAND = new RegExp(`^${OID} ${OID} (\\S+)$`);
17
+ const SHALLOW = new RegExp(`^shallow ${OID}$`);
18
+ const ZERO = /^0+$/;
19
+ const USERNAME = /^[A-Za-z0-9._-]{1,64}$/;
20
+ const invalid = (message) => new HarnessError("invalid_egress_options", message);
21
+ /** Whether `name` is a ref name git itself would accept, by `git check-ref-format`'s rules, under `refs/`. */
22
+ export function isValidRefName(name) {
23
+ if (!name.startsWith("refs/") || name.length > 1024)
24
+ return false;
25
+ const control = [...name].some((char) => char.charCodeAt(0) <= 0x20 || char.charCodeAt(0) === 0x7f);
26
+ if (control || /[~^:?*[\\]/.test(name) || name.includes("..") || name.includes("@{") || name.includes("//")) {
27
+ return false;
28
+ }
29
+ if (name.endsWith("/") || name.endsWith("."))
30
+ return false;
31
+ return name.split("/").every((part) => part !== "" && !part.startsWith(".") && !part.endsWith(".lock"));
32
+ }
33
+ /** Throws unless `pattern` is a branch, or a branch prefix ending in `/*`, under `refs/heads/`. */
34
+ function checkPattern(pattern, index) {
35
+ const text = typeof pattern === "string" ? pattern : "";
36
+ const bare = text.endsWith("/*") ? `${text.slice(0, -2)}/x` : text;
37
+ if (!text.startsWith("refs/heads/") || !isValidRefName(bare)) {
38
+ throw invalid(`push ref ${index} must be a branch, or a branch prefix ending in /*, under refs/heads/`);
39
+ }
40
+ }
41
+ /** Throws unless every field of a git route's filter is usable. The message names the field, never its value. */
42
+ export function checkGitFilter(filter) {
43
+ const { repositories, pushRefs, fetch, username } = filter;
44
+ if (!Array.isArray(repositories) || repositories.length === 0) {
45
+ throw invalid("a git route needs at least one repository, as owner/name");
46
+ }
47
+ repositories.forEach((repository, index) => {
48
+ const parts = typeof repository === "string" ? repository.split("/") : [];
49
+ const usable = parts.length === 2 && parts.every((part) => SEGMENT.test(part) && !/^\.+$/.test(part));
50
+ if (!usable)
51
+ throw invalid(`repository ${index} must be owner/name`);
52
+ });
53
+ if (!Array.isArray(pushRefs))
54
+ throw invalid("a git route's pushRefs must be a list");
55
+ pushRefs.forEach(checkPattern);
56
+ if (typeof fetch !== "boolean")
57
+ throw invalid("a git route's fetch must be true or false");
58
+ if (pushRefs.length === 0 && !fetch)
59
+ throw invalid("a git route must allow a push, a fetch or both");
60
+ if (typeof username !== "string" || !USERNAME.test(username))
61
+ throw invalid("a git route's username is not usable");
62
+ }
63
+ /** The repository `owner/name` in lower case, without a trailing `.git`. */
64
+ const repositoryKey = (owner, name) => `${owner}/${name.replace(/\.git$/i, "")}`.toLowerCase();
65
+ /**
66
+ * The git endpoint a request is for, or the reason it is refused. `path` is the part after the route's name, and
67
+ * `query` is the search part with its `?`, or empty.
68
+ */
69
+ export function gitEndpoint(filter, method, path, query) {
70
+ const match = REPOSITORY_PATH.exec(path);
71
+ const [, owner = "", name = "", action = ""] = match ?? [];
72
+ if (match === null || ![owner, name].every((part) => SEGMENT.test(part) && !/^\.+$/.test(part))) {
73
+ return { refused: "git_path_refused" };
74
+ }
75
+ const listed = filter.repositories.map((repository) => repositoryKey(...repository.split("/")));
76
+ if (!listed.includes(repositoryKey(owner, name)))
77
+ return { refused: "git_repository_refused" };
78
+ const endpoint = endpointOf(action, method.toUpperCase(), query);
79
+ if (endpoint === undefined)
80
+ return { refused: "git_path_refused" };
81
+ if (endpoint.service === "git-receive-pack" && filter.pushRefs.length === 0)
82
+ return { refused: "git_push_refused" };
83
+ if (endpoint.service === "git-upload-pack" && !filter.fetch)
84
+ return { refused: "git_fetch_refused" };
85
+ return endpoint;
86
+ }
87
+ function endpointOf(action, method, query) {
88
+ if (action === "info/refs") {
89
+ if (method !== "GET")
90
+ return undefined;
91
+ if (query === "?service=git-receive-pack")
92
+ return { service: "git-receive-pack", phase: "advertise" };
93
+ if (query === "?service=git-upload-pack")
94
+ return { service: "git-upload-pack", phase: "advertise" };
95
+ return undefined;
96
+ }
97
+ if (method !== "POST" || query !== "")
98
+ return undefined;
99
+ return { service: action, phase: "rpc" };
100
+ }
101
+ const DECODER = new TextDecoder("utf-8", { fatal: true });
102
+ const LENGTH = /^[0-9a-fA-F]{4}$/;
103
+ const BAD = { refused: "git_bad_pkt_line" };
104
+ const FLUSH_LENGTH = 4;
105
+ /** The text of one pkt-line's payload without its line feed, or `undefined` when it isn't UTF-8. */
106
+ function payloadText(bytes) {
107
+ try {
108
+ return DECODER.decode(bytes).replace(/\n$/, "");
109
+ }
110
+ catch {
111
+ return undefined;
112
+ }
113
+ }
114
+ /** Reads one command line; the first carries the capabilities after a NUL, which are dropped. */
115
+ function readCommand(text, commands) {
116
+ if (commands.length === 0 && SHALLOW.test(text))
117
+ return undefined;
118
+ if (text.startsWith("push-cert"))
119
+ return "git_push_cert";
120
+ const line = commands.length === 0 ? (text.split("\0")[0] ?? "") : text;
121
+ if (commands.length > 0 && text.includes("\0"))
122
+ return "git_bad_pkt_line";
123
+ const match = COMMAND.exec(line);
124
+ if (match === null || match[1]?.length !== match[2]?.length)
125
+ return "git_bad_pkt_line";
126
+ commands.push({ old: match[1] ?? "", new: match[2] ?? "", ref: match[3] ?? "" });
127
+ return commands.length > GIT_MAX_COMMANDS ? "git_too_many_commands" : undefined;
128
+ }
129
+ /**
130
+ * One pkt-line at `at` in `bytes`, which starts at body offset `offset`: a flush, a payload's text, how many bytes from
131
+ * `at` it needs before it can be read, or a refusal. A line that would end past `GIT_MAX_COMMAND_BYTES` is refused from
132
+ * its header, so the reader never holds much more than the limit.
133
+ */
134
+ function readPacket(bytes, at, offset) {
135
+ if (bytes.length - at < 4)
136
+ return { needed: 4 };
137
+ const header = String.fromCharCode(...bytes.subarray(at, at + 4));
138
+ if (!LENGTH.test(header))
139
+ return BAD;
140
+ const length = Number.parseInt(header, 16);
141
+ if (length === 0)
142
+ return "flush";
143
+ if (length < 5 || length > PKT_MAX)
144
+ return BAD;
145
+ if (offset + at + length > GIT_MAX_COMMAND_BYTES)
146
+ return { refused: "git_too_large" };
147
+ if (bytes.length - at < length)
148
+ return { needed: length };
149
+ const text = payloadText(bytes.subarray(at + 4, at + length));
150
+ return text === undefined ? BAD : { text, length };
151
+ }
152
+ /** The chunks joined into one array, or the one chunk itself. */
153
+ function join(chunks) {
154
+ if (chunks.length === 1)
155
+ return chunks[0];
156
+ const joined = new Uint8Array(chunks.reduce((total, chunk) => total + chunk.length, 0));
157
+ let at = 0;
158
+ for (const chunk of chunks) {
159
+ joined.set(chunk, at);
160
+ at += chunk.length;
161
+ }
162
+ return joined;
163
+ }
164
+ /**
165
+ * Reads the command list at the start of a push body as the body arrives, in pieces of any size, and gives the route's
166
+ * verdict once it can. The work is linear in the bytes received: pieces are joined only once they hold the next
167
+ * pkt-line's header or the whole line, and a line already read is never read again. A list whose lines end past
168
+ * `GIT_MAX_COMMAND_BYTES` is refused as soon as a header says so, however the body is split.
169
+ */
170
+ export class PushReader {
171
+ #filter;
172
+ #pending = [];
173
+ #pendingBytes = 0;
174
+ /** The body offset of the first pending byte. Every byte before it belongs to a pkt-line already read. */
175
+ #offset = 0;
176
+ /** How many pending bytes the next pkt-line needs before it can be read. */
177
+ #needed = 4;
178
+ #commands = [];
179
+ /** Whether the body so far is exactly one flush, git's probe before a large push. */
180
+ #probe = false;
181
+ #verdict;
182
+ constructor(filter) {
183
+ this.#filter = filter;
184
+ }
185
+ /** Reads the next piece of the body and returns the verdict so far. Bytes after a verdict are not read. */
186
+ add(chunk) {
187
+ if (this.#verdict !== undefined)
188
+ return this.#verdict;
189
+ if (chunk.length === 0)
190
+ return "incomplete";
191
+ // The probe is a body of one flush and nothing else, so any byte after it is refused.
192
+ if (this.#probe)
193
+ return this.#settle(BAD);
194
+ this.#pending.push(chunk);
195
+ this.#pendingBytes += chunk.length;
196
+ return this.#pendingBytes < this.#needed ? "incomplete" : this.#read();
197
+ }
198
+ /** Says the body has ended and returns the final verdict: a list still incomplete is refused. */
199
+ end() {
200
+ return this.#verdict ?? this.#settle(this.#probe ? "allowed" : BAD);
201
+ }
202
+ #read() {
203
+ const bytes = join(this.#pending);
204
+ let at = 0;
205
+ for (;;) {
206
+ const packet = readPacket(bytes, at, this.#offset);
207
+ if (packet === "flush")
208
+ return this.#flush(bytes, at);
209
+ if ("refused" in packet)
210
+ return this.#settle(packet);
211
+ if ("needed" in packet) {
212
+ this.#pending = at < bytes.length ? [bytes.subarray(at)] : [];
213
+ this.#pendingBytes = bytes.length - at;
214
+ this.#offset += at;
215
+ this.#needed = packet.needed;
216
+ return "incomplete";
217
+ }
218
+ const refused = readCommand(packet.text, this.#commands);
219
+ if (refused !== undefined)
220
+ return this.#settle({ refused });
221
+ at += packet.length;
222
+ }
223
+ }
224
+ /** The verdict at a flush at `at`: the end of the command list, git's probe, or a flush with no command before it. */
225
+ #flush(bytes, at) {
226
+ if (this.#commands.length > 0)
227
+ return this.#settle(commandsVerdict(this.#commands, this.#filter));
228
+ if (this.#offset + at !== 0 || bytes.length > FLUSH_LENGTH)
229
+ return this.#settle(BAD);
230
+ this.#probe = true;
231
+ this.#pending = [];
232
+ this.#pendingBytes = 0;
233
+ return "incomplete";
234
+ }
235
+ #settle(verdict) {
236
+ this.#verdict = verdict;
237
+ this.#pending = [];
238
+ this.#pendingBytes = 0;
239
+ return verdict;
240
+ }
241
+ }
242
+ /** Whether `ref` is matched by one of the patterns: exactly, or under a prefix that ends in `/*`. */
243
+ function refAllowed(ref, patterns) {
244
+ return patterns.some((pattern) => pattern.endsWith("/*") ? ref.startsWith(pattern.slice(0, -1)) && ref.length > pattern.length - 1 : ref === pattern);
245
+ }
246
+ /** Whether every command creates or updates a ref the patterns allow, or why not. */
247
+ function commandsVerdict(commands, filter) {
248
+ for (const command of commands) {
249
+ if (ZERO.test(command.new))
250
+ return { refused: "git_delete_refused" };
251
+ if (!isValidRefName(command.ref) || !refAllowed(command.ref, filter.pushRefs))
252
+ return { refused: "git_ref_refused" };
253
+ }
254
+ return "allowed";
255
+ }
256
+ /**
257
+ * The route's verdict on the start of a push body: `incomplete` while the command list hasn't reached its flush,
258
+ * `allowed` once every command creates or updates a ref the patterns allow, or the reason it is refused. A body that is
259
+ * exactly one flush packet, the probe git sends before a large push, is `allowed` once it has ended, because it updates
260
+ * no ref; a byte after that flush is refused. `ended` says the body has no more bytes, so a list still incomplete is
261
+ * refused. A list whose lines end past `GIT_MAX_COMMAND_BYTES` is refused, whether or not its flush has arrived.
262
+ */
263
+ export function pushVerdict(bytes, filter, ended) {
264
+ const reader = new PushReader(filter);
265
+ const verdict = reader.add(bytes);
266
+ return verdict === "incomplete" && ended ? reader.end() : verdict;
267
+ }
268
+ /** Whether an `Authorization` header is HTTP Basic whose password is exactly `sentinel`. */
269
+ export function basicCarries(header, sentinel) {
270
+ const match = /^Basic ([A-Za-z0-9+/]+={0,2})$/i.exec(header ?? "");
271
+ if (match === null || sentinel === "")
272
+ return false;
273
+ let decoded;
274
+ try {
275
+ decoded = atob(match[1] ?? "");
276
+ }
277
+ catch {
278
+ return false;
279
+ }
280
+ const colon = decoded.indexOf(":");
281
+ return colon >= 0 && decoded.slice(colon + 1) === sentinel;
282
+ }
283
+ /** The `Authorization` value that carries `secret` as the password of `username`. */
284
+ export function basicHeader(username, secret) {
285
+ const bytes = new TextEncoder().encode(`${username}:${secret}`);
286
+ return `Basic ${btoa(String.fromCharCode(...bytes))}`;
287
+ }
288
+ //# sourceMappingURL=git-route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-route.js","sourceRoot":"","sources":["../../src/credentials/git-route.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAuB5C,iHAAiH;AACjH,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,GAAG,IAAI,CAAC;AAC/C,wCAAwC;AACxC,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAEnC,MAAM,OAAO,GAAG,KAAK,CAAC;AACtB,MAAM,OAAO,GAAG,mBAAmB,CAAC;AACpC,MAAM,eAAe,GAAG,qEAAqE,CAAC;AAC9F,MAAM,GAAG,GAAG,6BAA6B,CAAC;AAC1C,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,IAAI,GAAG,IAAI,GAAG,UAAU,CAAC,CAAC;AACrD,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,YAAY,GAAG,GAAG,CAAC,CAAC;AAC/C,MAAM,IAAI,GAAG,MAAM,CAAC;AACpB,MAAM,QAAQ,GAAG,wBAAwB,CAAC;AAE1C,MAAM,OAAO,GAAG,CAAC,OAAe,E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K,CAAC;IACpD,IAAI,OAAe,CAAC;IACpB,IAAI,CAAC;QACH,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACnC,OAAO,KAAK,IAAI,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,QAAQ,CAAC;AAC7D,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,WAAW,CAAC,QAAgB,EAAE,MAAc;IAC1D,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,QAAQ,IAAI,MAAM,EAAE,CAAC,CAAC;IAChE,OAAO,SAAS,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;AACxD,CAAC","sourcesContent":["/**\n * The checks of a git route: git's smart HTTP protocol over a credential route, limited to listed repositories and,\n * for a push, to listed branches. It is pure and portable, so the proxy and any other backend can share it. Everything\n * it doesn't understand is refused: an unknown path, a query, a push certificate, a pkt-line it can't read, a command\n * list past its size limit, a deletion, a tag and any ref outside the patterns.\n */\nimport { HarnessError } from \"../errors.js\";\n\n/** What a git route lets through. */\nexport interface GitRouteFilter {\n /** The repositories the route reaches, as `owner/name`. Compared without case, as GitHub does. */\n readonly repositories: readonly string[];\n /**\n * The branches a push may create or update, as `refs/heads/<name>` or a prefix ending in `/*`, such as\n * `refs/heads/agent/*`. Leave it empty to refuse every push. A deletion and a tag are always refused.\n */\n readonly pushRefs: readonly string[];\n /** Whether a fetch or clone may read the repositories. A fetch is not limited by ref. */\n readonly fetch: boolean;\n /** The user name sent with the credential in HTTP Basic, such as `x-access-token` for a GitHub App token. */\n readonly username: string;\n}\n\n/** A git request the route accepts: which service, and whether it is the ref advertisement or the request itself. */\nexport interface GitEndpoint {\n readonly service: \"git-receive-pack\" | \"git-upload-pack\";\n readonly phase: \"advertise\" | \"rpc\";\n}\n\n/** The most bytes of a push's command list, before its flush, that the route reads. A longer list is refused. */\nexport const GIT_MAX_COMMAND_BYTES = 64 * 1024;\n/** The most ref updates in one push. */\nexport const GIT_MAX_COMMANDS = 64;\n\nconst PKT_MAX = 65520;\nconst SEGMENT = /^[A-Za-z0-9_.-]+$/;\nconst REPOSITORY_PATH = /^\\/([^/]+)\\/([^/]+)\\/(info\\/refs|git-receive-pack|git-upload-pack)$/;\nconst OID = \"([0-9a-f]{40}|[0-9a-f]{64})\";\nconst COMMAND = new RegExp(`^${OID} ${OID} (\\\\S+)$`);\nconst SHALLOW = new RegExp(`^shallow ${OID}$`);\nconst ZERO = /^0+$/;\nconst USERNAME = /^[A-Za-z0-9._-]{1,64}$/;\n\nconst invalid = (message: string) => new HarnessError(\"invalid_egress_options\", message);\n\n/** Whether `name` is a ref name git itself would accept, by `git check-ref-format`'s rules, under `refs/`. */\nexport function isValidRefName(name: string): boolean {\n if (!name.startsWith(\"refs/\") || name.length > 1024) return false;\n const control = [...name].some((char) => char.charCodeAt(0) <= 0x20 || char.charCodeAt(0) === 0x7f);\n if (control || /[~^:?*[\\\\]/.test(name) || name.includes(\"..\") || name.includes(\"@{\") || name.includes(\"//\")) {\n return false;\n }\n if (name.endsWith(\"/\") || name.endsWith(\".\")) return false;\n return name.split(\"/\").every((part) => part !== \"\" && !part.startsWith(\".\") && !part.endsWith(\".lock\"));\n}\n\n/** Throws unless `pattern` is a branch, or a branch prefix ending in `/*`, under `refs/heads/`. */\nfunction checkPattern(pattern: unknown, index: number): void {\n const text = typeof pattern === \"string\" ? pattern : \"\";\n const bare = text.endsWith(\"/*\") ? `${text.slice(0, -2)}/x` : text;\n if (!text.startsWith(\"refs/heads/\") || !isValidRefName(bare)) {\n throw invalid(`push ref ${index} must be a branch, or a branch prefix ending in /*, under refs/heads/`);\n }\n}\n\n/** Throws unless every field of a git route's filter is usable. The message names the field, never its value. */\nexport function checkGitFilter(filter: GitRouteFilter): void {\n const { repositories, pushRefs, fetch, username } = filter;\n if (!Array.isArray(repositories) || repositories.length === 0) {\n throw invalid(\"a git route needs at least one repository, as owner/name\");\n }\n repositories.forEach((repository: unknown, index) => {\n const parts = typeof repository === \"string\" ? repository.split(\"/\") : [];\n const usable = parts.length === 2 && parts.every((part) => SEGMENT.test(part) && !/^\\.+$/.test(part));\n if (!usable) throw invalid(`repository ${index} must be owner/name`);\n });\n if (!Array.isArray(pushRefs)) throw invalid(\"a git route's pushRefs must be a list\");\n pushRefs.forEach(checkPattern);\n if (typeof fetch !== \"boolean\") throw invalid(\"a git route's fetch must be true or false\");\n if (pushRefs.length === 0 && !fetch) throw invalid(\"a git route must allow a push, a fetch or both\");\n if (typeof username !== \"string\" || !USERNAME.test(username)) throw invalid(\"a git route's username is not usable\");\n}\n\n/** The repository `owner/name` in lower case, without a trailing `.git`. */\nconst repositoryKey = (owner: string, name: string): string => `${owner}/${name.replace(/\\.git$/i, \"\")}`.toLowerCase();\n\n/**\n * The git endpoint a request is for, or the reason it is refused. `path` is the part after the route's name, and\n * `query` is the search part with its `?`, or empty.\n */\nexport function gitEndpoint(\n filter: GitRouteFilter,\n method: string,\n path: string,\n query: string,\n): GitEndpoint | { readonly refused: string } {\n const match = REPOSITORY_PATH.exec(path);\n const [, owner = \"\", name = \"\", action = \"\"] = match ?? [];\n if (match === null || ![owner, name].every((part) => SEGMENT.test(part) && !/^\\.+$/.test(part))) {\n return { refused: \"git_path_refused\" };\n }\n const listed = filter.repositories.map((repository) => repositoryKey(...(repository.split(\"/\") as [string, string])));\n if (!listed.includes(repositoryKey(owner, name))) return { refused: \"git_repository_refused\" };\n const endpoint = endpointOf(action, method.toUpperCase(), query);\n if (endpoint === undefined) return { refused: \"git_path_refused\" };\n if (endpoint.service === \"git-receive-pack\" && filter.pushRefs.length === 0) return { refused: \"git_push_refused\" };\n if (endpoint.service === \"git-upload-pack\" && !filter.fetch) return { refused: \"git_fetch_refused\" };\n return endpoint;\n}\n\nfunction endpointOf(action: string, method: string, query: string): GitEndpoint | undefined {\n if (action === \"info/refs\") {\n if (method !== \"GET\") return undefined;\n if (query === \"?service=git-receive-pack\") return { service: \"git-receive-pack\", phase: \"advertise\" };\n if (query === \"?service=git-upload-pack\") return { service: \"git-upload-pack\", phase: \"advertise\" };\n return undefined;\n }\n if (method !== \"POST\" || query !== \"\") return undefined;\n return { service: action as GitEndpoint[\"service\"], phase: \"rpc\" };\n}\n\n/** One ref update in a push. */\ninterface PushCommand {\n readonly old: string;\n readonly new: string;\n readonly ref: string;\n}\n\nconst DECODER = new TextDecoder(\"utf-8\", { fatal: true });\nconst LENGTH = /^[0-9a-fA-F]{4}$/;\nconst BAD: { readonly refused: string } = { refused: \"git_bad_pkt_line\" };\nconst FLUSH_LENGTH = 4;\n\n/** The text of one pkt-line's payload without its line feed, or `undefined` when it isn't UTF-8. */\nfunction payloadText(bytes: Uint8Array): string | undefined {\n try {\n return DECODER.decode(bytes).replace(/\\n$/, \"\");\n } catch {\n return undefined;\n }\n}\n\n/** Reads one command line; the first carries the capabilities after a NUL, which are dropped. */\nfunction readCommand(text: string, commands: PushCommand[]): string | undefined {\n if (commands.length === 0 && SHALLOW.test(text)) return undefined;\n if (text.startsWith(\"push-cert\")) return \"git_push_cert\";\n const line = commands.length === 0 ? (text.split(\"\\0\")[0] ?? \"\") : text;\n if (commands.length > 0 && text.includes(\"\\0\")) return \"git_bad_pkt_line\";\n const match = COMMAND.exec(line);\n if (match === null || match[1]?.length !== match[2]?.length) return \"git_bad_pkt_line\";\n commands.push({ old: match[1] ?? \"\", new: match[2] ?? \"\", ref: match[3] ?? \"\" });\n return commands.length > GIT_MAX_COMMANDS ? \"git_too_many_commands\" : undefined;\n}\n\n/**\n * One pkt-line at `at` in `bytes`, which starts at body offset `offset`: a flush, a payload's text, how many bytes from\n * `at` it needs before it can be read, or a refusal. A line that would end past `GIT_MAX_COMMAND_BYTES` is refused from\n * its header, so the reader never holds much more than the limit.\n */\nfunction readPacket(\n bytes: Uint8Array,\n at: number,\n offset: number,\n):\n | { readonly needed: number }\n | { readonly refused: string }\n | \"flush\"\n | { readonly text: string; readonly length: number } {\n if (bytes.length - at < 4) return { needed: 4 };\n const header = String.fromCharCode(...bytes.subarray(at, at + 4));\n if (!LENGTH.test(header)) return BAD;\n const length = Number.parseInt(header, 16);\n if (length === 0) return \"flush\";\n if (length < 5 || length > PKT_MAX) return BAD;\n if (offset + at + length > GIT_MAX_COMMAND_BYTES) return { refused: \"git_too_large\" };\n if (bytes.length - at < length) return { needed: length };\n const text = payloadText(bytes.subarray(at + 4, at + length));\n return text === undefined ? BAD : { text, length };\n}\n\n/** The chunks joined into one array, or the one chunk itself. */\nfunction join(chunks: readonly Uint8Array[]): Uint8Array {\n if (chunks.length === 1) return chunks[0] as Uint8Array;\n const joined = new Uint8Array(chunks.reduce((total, chunk) => total + chunk.length, 0));\n let at = 0;\n for (const chunk of chunks) {\n joined.set(chunk, at);\n at += chunk.length;\n }\n return joined;\n}\n\n/** A push check's verdict so far: `incomplete` until the command list reaches its flush, or the route's verdict. */\nexport type PushCheckVerdict = \"incomplete\" | \"allowed\" | { readonly refused: string };\n\n/**\n * Reads the command list at the start of a push body as the body arrives, in pieces of any size, and gives the route's\n * verdict once it can. The work is linear in the bytes received: pieces are joined only once they hold the next\n * pkt-line's header or the whole line, and a line already read is never read again. A list whose lines end past\n * `GIT_MAX_COMMAND_BYTES` is refused as soon as a header says so, however the body is split.\n */\nexport class PushReader {\n readonly #filter: GitRouteFilter;\n #pending: Uint8Array[] = [];\n #pendingBytes = 0;\n /** The body offset of the first pending byte. Every byte before it belongs to a pkt-line already read. */\n #offset = 0;\n /** How many pending bytes the next pkt-line needs before it can be read. */\n #needed = 4;\n readonly #commands: PushCommand[] = [];\n /** Whether the body so far is exactly one flush, git's probe before a large push. */\n #probe = false;\n #verdict: \"allowed\" | { readonly refused: string } | undefined;\n\n constructor(filter: GitRouteFilter) {\n this.#filter = filter;\n }\n\n /** Reads the next piece of the body and returns the verdict so far. Bytes after a verdict are not read. */\n add(chunk: Uint8Array): PushCheckVerdict {\n if (this.#verdict !== undefined) return this.#verdict;\n if (chunk.length === 0) return \"incomplete\";\n // The probe is a body of one flush and nothing else, so any byte after it is refused.\n if (this.#probe) return this.#settle(BAD);\n this.#pending.push(chunk);\n this.#pendingBytes += chunk.length;\n return this.#pendingBytes < this.#needed ? \"incomplete\" : this.#read();\n }\n\n /** Says the body has ended and returns the final verdict: a list still incomplete is refused. */\n end(): \"allowed\" | { readonly refused: string } {\n return this.#verdict ?? this.#settle(this.#probe ? \"allowed\" : BAD);\n }\n\n #read(): PushCheckVerdict {\n const bytes = join(this.#pending);\n let at = 0;\n for (;;) {\n const packet = readPacket(bytes, at, this.#offset);\n if (packet === \"flush\") return this.#flush(bytes, at);\n if (\"refused\" in packet) return this.#settle(packet);\n if (\"needed\" in packet) {\n this.#pending = at < bytes.length ? [bytes.subarray(at)] : [];\n this.#pendingBytes = bytes.length - at;\n this.#offset += at;\n this.#needed = packet.needed;\n return \"incomplete\";\n }\n const refused = readCommand(packet.text, this.#commands);\n if (refused !== undefined) return this.#settle({ refused });\n at += packet.length;\n }\n }\n\n /** The verdict at a flush at `at`: the end of the command list, git's probe, or a flush with no command before it. */\n #flush(bytes: Uint8Array, at: number): PushCheckVerdict {\n if (this.#commands.length > 0) return this.#settle(commandsVerdict(this.#commands, this.#filter));\n if (this.#offset + at !== 0 || bytes.length > FLUSH_LENGTH) return this.#settle(BAD);\n this.#probe = true;\n this.#pending = [];\n this.#pendingBytes = 0;\n return \"incomplete\";\n }\n\n #settle(verdict: \"allowed\" | { readonly refused: string }): \"allowed\" | { readonly refused: string } {\n this.#verdict = verdict;\n this.#pending = [];\n this.#pendingBytes = 0;\n return verdict;\n }\n}\n\n/** Whether `ref` is matched by one of the patterns: exactly, or under a prefix that ends in `/*`. */\nfunction refAllowed(ref: string, patterns: readonly string[]): boolean {\n return patterns.some((pattern) =>\n pattern.endsWith(\"/*\") ? ref.startsWith(pattern.slice(0, -1)) && ref.length > pattern.length - 1 : ref === pattern,\n );\n}\n\n/** Whether every command creates or updates a ref the patterns allow, or why not. */\nfunction commandsVerdict(\n commands: readonly PushCommand[],\n filter: GitRouteFilter,\n): \"allowed\" | { readonly refused: string } {\n for (const command of commands) {\n if (ZERO.test(command.new)) return { refused: \"git_delete_refused\" };\n if (!isValidRefName(command.ref) || !refAllowed(command.ref, filter.pushRefs))\n return { refused: \"git_ref_refused\" };\n }\n return \"allowed\";\n}\n\n/**\n * The route's verdict on the start of a push body: `incomplete` while the command list hasn't reached its flush,\n * `allowed` once every command creates or updates a ref the patterns allow, or the reason it is refused. A body that is\n * exactly one flush packet, the probe git sends before a large push, is `allowed` once it has ended, because it updates\n * no ref; a byte after that flush is refused. `ended` says the body has no more bytes, so a list still incomplete is\n * refused. A list whose lines end past `GIT_MAX_COMMAND_BYTES` is refused, whether or not its flush has arrived.\n */\nexport function pushVerdict(\n bytes: Uint8Array,\n filter: GitRouteFilter,\n ended: boolean,\n): \"incomplete\" | \"allowed\" | { readonly refused: string } {\n const reader = new PushReader(filter);\n const verdict = reader.add(bytes);\n return verdict === \"incomplete\" && ended ? reader.end() : verdict;\n}\n\n/** Whether an `Authorization` header is HTTP Basic whose password is exactly `sentinel`. */\nexport function basicCarries(header: string | undefined, sentinel: string): boolean {\n const match = /^Basic ([A-Za-z0-9+/]+={0,2})$/i.exec(header ?? \"\");\n if (match === null || sentinel === \"\") return false;\n let decoded: string;\n try {\n decoded = atob(match[1] ?? \"\");\n } catch {\n return false;\n }\n const colon = decoded.indexOf(\":\");\n return colon >= 0 && decoded.slice(colon + 1) === sentinel;\n}\n\n/** The `Authorization` value that carries `secret` as the password of `username`. */\nexport function basicHeader(username: string, secret: string): string {\n const bytes = new TextEncoder().encode(`${username}:${secret}`);\n return `Basic ${btoa(String.fromCharCode(...bytes))}`;\n}\n"]}
@@ -0,0 +1,13 @@
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. `compileEgressPolicy()` turns an `EgressPolicy`, which names credentials but never holds them, into the
6
+ * proxy's allowlist and routes, and a `git` route limits git over HTTPS to listed repositories and branches. The proxy
7
+ * is Node-only; the policy compiler, the git checks, the scrubber and the address check are portable.
8
+ */
9
+ export { isAddressLiteral, isPublicAddress } from "./addresses.js";
10
+ export { type CompiledEgressPolicy, type CompileEgressOptions, compileEgressPolicy, type EgressPolicy, type EgressRoute, type GitEgressRoute, type HeaderEgressRoute, } from "./egress-policy.js";
11
+ export { type CredentialRoute, type EgressProxy, type EgressProxyOptions, type EgressRecord, startEgressProxy, } from "./egress-proxy.js";
12
+ export { GIT_MAX_COMMAND_BYTES, GIT_MAX_COMMANDS, type GitRouteFilter, isValidRefName, pushVerdict, } from "./git-route.js";
13
+ export { REDACTED, scrubSecrets } from "./scrub.js";
@@ -0,0 +1,14 @@
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. `compileEgressPolicy()` turns an `EgressPolicy`, which names credentials but never holds them, into the
6
+ * proxy's allowlist and routes, and a `git` route limits git over HTTPS to listed repositories and branches. The proxy
7
+ * is Node-only; the policy compiler, the git checks, the scrubber and the address check are portable.
8
+ */
9
+ export { isAddressLiteral, isPublicAddress } from "./addresses.js";
10
+ export { compileEgressPolicy, } from "./egress-policy.js";
11
+ export { startEgressProxy, } from "./egress-proxy.js";
12
+ export { GIT_MAX_COMMAND_BYTES, GIT_MAX_COMMANDS, isValidRefName, pushVerdict, } from "./git-route.js";
13
+ export { REDACTED, scrubSecrets } from "./scrub.js";
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/credentials/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAGL,mBAAmB,GAKpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAKL,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAEhB,cAAc,EACd,WAAW,GACZ,MAAM,gBAAgB,CAAC;AACxB,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. `compileEgressPolicy()` turns an `EgressPolicy`, which names credentials but never holds them, into the\n * proxy's allowlist and routes, and a `git` route limits git over HTTPS to listed repositories and branches. The proxy\n * is Node-only; the policy compiler, the git checks, the scrubber and the address check are portable.\n */\nexport { isAddressLiteral, isPublicAddress } from \"./addresses.js\";\nexport {\n type CompiledEgressPolicy,\n type CompileEgressOptions,\n compileEgressPolicy,\n type EgressPolicy,\n type EgressRoute,\n type GitEgressRoute,\n type HeaderEgressRoute,\n} from \"./egress-policy.js\";\nexport {\n type CredentialRoute,\n type EgressProxy,\n type EgressProxyOptions,\n type EgressRecord,\n startEgressProxy,\n} from \"./egress-proxy.js\";\nexport {\n GIT_MAX_COMMAND_BYTES,\n GIT_MAX_COMMANDS,\n type GitRouteFilter,\n isValidRefName,\n pushVerdict,\n} from \"./git-route.js\";\nexport { REDACTED, scrubSecrets } from \"./scrub.js\";\n"]}