@sysid/sandbox-runtime-improved 0.0.56-sysid.1 → 0.0.64-sysid.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/README.md +106 -4
  2. package/dist/cli.js +12 -18
  3. package/dist/cli.js.map +1 -1
  4. package/dist/index.d.ts +5 -5
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +2 -2
  7. package/dist/index.js.map +1 -1
  8. package/dist/sandbox/credential-mask-files.d.ts +157 -0
  9. package/dist/sandbox/credential-mask-files.d.ts.map +1 -0
  10. package/dist/sandbox/credential-mask-files.js +298 -0
  11. package/dist/sandbox/credential-mask-files.js.map +1 -0
  12. package/dist/sandbox/credential-sentinel.d.ts +72 -0
  13. package/dist/sandbox/credential-sentinel.d.ts.map +1 -0
  14. package/dist/sandbox/credential-sentinel.js +130 -0
  15. package/dist/sandbox/credential-sentinel.js.map +1 -0
  16. package/dist/sandbox/domain-pattern.d.ts +36 -0
  17. package/dist/sandbox/domain-pattern.d.ts.map +1 -0
  18. package/dist/sandbox/domain-pattern.js +60 -0
  19. package/dist/sandbox/domain-pattern.js.map +1 -0
  20. package/dist/sandbox/http-proxy.d.ts +33 -2
  21. package/dist/sandbox/http-proxy.d.ts.map +1 -1
  22. package/dist/sandbox/http-proxy.js +30 -2
  23. package/dist/sandbox/http-proxy.js.map +1 -1
  24. package/dist/sandbox/linux-sandbox-utils.d.ts +20 -0
  25. package/dist/sandbox/linux-sandbox-utils.d.ts.map +1 -1
  26. package/dist/sandbox/linux-sandbox-utils.js +134 -65
  27. package/dist/sandbox/linux-sandbox-utils.js.map +1 -1
  28. package/dist/sandbox/linux-violation-monitor.d.ts +48 -0
  29. package/dist/sandbox/linux-violation-monitor.d.ts.map +1 -0
  30. package/dist/sandbox/linux-violation-monitor.js +156 -0
  31. package/dist/sandbox/linux-violation-monitor.js.map +1 -0
  32. package/dist/sandbox/listen-in-range.d.ts +12 -0
  33. package/dist/sandbox/listen-in-range.d.ts.map +1 -0
  34. package/dist/sandbox/listen-in-range.js +43 -0
  35. package/dist/sandbox/listen-in-range.js.map +1 -0
  36. package/dist/sandbox/macos-sandbox-utils.d.ts +11 -0
  37. package/dist/sandbox/macos-sandbox-utils.d.ts.map +1 -1
  38. package/dist/sandbox/macos-sandbox-utils.js +72 -17
  39. package/dist/sandbox/macos-sandbox-utils.js.map +1 -1
  40. package/dist/sandbox/mitm-ca.d.ts +69 -2
  41. package/dist/sandbox/mitm-ca.d.ts.map +1 -1
  42. package/dist/sandbox/mitm-ca.js +188 -16
  43. package/dist/sandbox/mitm-ca.js.map +1 -1
  44. package/dist/sandbox/mitm-leaf.d.ts +1 -1
  45. package/dist/sandbox/mitm-leaf.d.ts.map +1 -1
  46. package/dist/sandbox/mitm-leaf.js +26 -19
  47. package/dist/sandbox/mitm-leaf.js.map +1 -1
  48. package/dist/sandbox/mux-proxy.d.ts +59 -0
  49. package/dist/sandbox/mux-proxy.d.ts.map +1 -0
  50. package/dist/sandbox/mux-proxy.js +159 -0
  51. package/dist/sandbox/mux-proxy.js.map +1 -0
  52. package/dist/sandbox/request-filter.d.ts +11 -1
  53. package/dist/sandbox/request-filter.d.ts.map +1 -1
  54. package/dist/sandbox/request-filter.js.map +1 -1
  55. package/dist/sandbox/sandbox-config.d.ts +461 -41
  56. package/dist/sandbox/sandbox-config.d.ts.map +1 -1
  57. package/dist/sandbox/sandbox-config.js +342 -26
  58. package/dist/sandbox/sandbox-config.js.map +1 -1
  59. package/dist/sandbox/sandbox-manager.d.ts +5 -1
  60. package/dist/sandbox/sandbox-manager.d.ts.map +1 -1
  61. package/dist/sandbox/sandbox-manager.js +697 -211
  62. package/dist/sandbox/sandbox-manager.js.map +1 -1
  63. package/dist/sandbox/sandbox-schemas.d.ts +15 -0
  64. package/dist/sandbox/sandbox-schemas.d.ts.map +1 -1
  65. package/dist/sandbox/sandbox-utils.d.ts +55 -6
  66. package/dist/sandbox/sandbox-utils.d.ts.map +1 -1
  67. package/dist/sandbox/sandbox-utils.js +143 -30
  68. package/dist/sandbox/sandbox-utils.js.map +1 -1
  69. package/dist/sandbox/socks-proxy.d.ts +11 -5
  70. package/dist/sandbox/socks-proxy.d.ts.map +1 -1
  71. package/dist/sandbox/socks-proxy.js +13 -81
  72. package/dist/sandbox/socks-proxy.js.map +1 -1
  73. package/dist/sandbox/tls-terminate-proxy.d.ts +2 -2
  74. package/dist/sandbox/tls-terminate-proxy.d.ts.map +1 -1
  75. package/dist/sandbox/tls-terminate-proxy.js +31 -5
  76. package/dist/sandbox/tls-terminate-proxy.js.map +1 -1
  77. package/dist/sandbox/windows-sandbox-utils.d.ts +508 -116
  78. package/dist/sandbox/windows-sandbox-utils.d.ts.map +1 -1
  79. package/dist/sandbox/windows-sandbox-utils.js +721 -209
  80. package/dist/sandbox/windows-sandbox-utils.js.map +1 -1
  81. package/dist/utils/shell-quote.d.ts +27 -0
  82. package/dist/utils/shell-quote.d.ts.map +1 -0
  83. package/dist/utils/shell-quote.js +47 -0
  84. package/dist/utils/shell-quote.js.map +1 -0
  85. package/package.json +7 -6
  86. package/vendor/seccomp/arm64/apply-seccomp +0 -0
  87. package/vendor/seccomp/build.ts +8 -30
  88. package/vendor/seccomp/x64/apply-seccomp +0 -0
  89. package/vendor/srt-win/build.ts +21 -0
  90. package/dist/vendor/seccomp/Dockerfile.build +0 -6
  91. package/dist/vendor/seccomp/arm64/apply-seccomp +0 -0
  92. package/dist/vendor/seccomp/build.ts +0 -91
  93. package/dist/vendor/seccomp/x64/apply-seccomp +0 -0
  94. package/dist/vendor/seccomp-src/apply-seccomp.c +0 -280
  95. package/dist/vendor/seccomp-src/seccomp-unix-block.c +0 -148
  96. package/dist/vendor/srt-win/Cargo.lock +0 -361
  97. package/dist/vendor/srt-win/Cargo.toml +0 -46
  98. package/dist/vendor/srt-win/ci/cleanup.ps1 +0 -49
  99. package/dist/vendor/srt-win/ci/smoke-exec.ps1 +0 -446
  100. package/dist/vendor/srt-win/ci/smoke.ps1 +0 -307
  101. package/dist/vendor/srt-win/src/job.rs +0 -102
  102. package/dist/vendor/srt-win/src/launch.rs +0 -732
  103. package/dist/vendor/srt-win/src/lib.rs +0 -20
  104. package/dist/vendor/srt-win/src/main.rs +0 -669
  105. package/dist/vendor/srt-win/src/self_protect.rs +0 -169
  106. package/dist/vendor/srt-win/src/sid.rs +0 -296
  107. package/dist/vendor/srt-win/src/token.rs +0 -341
  108. package/dist/vendor/srt-win/src/util.rs +0 -42
  109. package/dist/vendor/srt-win/src/wfp.rs +0 -992
  110. package/dist/vendor/srt-win/src/winsta.rs +0 -209
  111. package/dist/vendor/srt-win/tests/sd_access_check_matrix.rs +0 -259
  112. package/vendor/seccomp-src/apply-seccomp.c +0 -280
  113. package/vendor/seccomp-src/seccomp-unix-block.c +0 -148
  114. package/vendor/srt-win/Cargo.lock +0 -361
  115. package/vendor/srt-win/Cargo.toml +0 -46
  116. package/vendor/srt-win/ci/cleanup.ps1 +0 -49
  117. package/vendor/srt-win/ci/smoke-exec.ps1 +0 -446
  118. package/vendor/srt-win/ci/smoke.ps1 +0 -307
  119. package/vendor/srt-win/src/job.rs +0 -102
  120. package/vendor/srt-win/src/launch.rs +0 -732
  121. package/vendor/srt-win/src/lib.rs +0 -20
  122. package/vendor/srt-win/src/main.rs +0 -669
  123. package/vendor/srt-win/src/self_protect.rs +0 -169
  124. package/vendor/srt-win/src/sid.rs +0 -296
  125. package/vendor/srt-win/src/token.rs +0 -341
  126. package/vendor/srt-win/src/util.rs +0 -42
  127. package/vendor/srt-win/src/wfp.rs +0 -992
  128. package/vendor/srt-win/src/winsta.rs +0 -209
  129. package/vendor/srt-win/tests/sd_access_check_matrix.rs +0 -259
@@ -1,71 +1,254 @@
1
+ export { containsGlobCharsWin, stripExtendedPathPrefix, } from './sandbox-utils.js';
1
2
  import type { SandboxDependencyCheck } from './linux-sandbox-utils.js';
3
+ import type { SrtWinConfig } from './sandbox-config.js';
2
4
  /**
3
5
  * Windows sandbox backend.
4
6
  *
5
7
  * Network isolation is enforced by `srt-win.exe` — a Rust helper that
6
- * manages a local discriminator group, a machine-wide WFP filter set
7
- * keyed on that group's SID, and an `exec` subcommand that spawns the
8
- * target under a restricted token (group flipped deny-only) inside a
9
- * hardened job. The sandboxed child reaches the host only via the JS
10
- * http/socks proxies, which `srt-win exec` points at via env vars.
8
+ * provisions a dedicated `srt-sandbox` local user account, installs a
9
+ * machine-wide WFP filter set keyed on that account's SID, and
10
+ * provides an `exec` subcommand that spawns the target via a two-hop
11
+ * launch (broker `CreateProcessWithLogonW(runner)` runner
12
+ * restricted-token child) under `srt-sandbox`. The sandboxed child
13
+ * reaches the host only via the JS mux proxy, which the caller
14
+ * passes in via `--env`.
15
+ *
16
+ * The separate-user account structurally closes the surrogate-spawn
17
+ * class (schtasks, `PROC_THREAD_ATTRIBUTE_PARENT_PROCESS`, BITS,
18
+ * RunAs="Interactive User" COM): the child's token carries a
19
+ * different user SID, so it cannot reach real-user processes, tasks
20
+ * register under `srt-sandbox`, and the user-SID WFP filter fences
21
+ * `srt-sandbox` egress regardless of how the child was spawned.
11
22
  *
12
23
  * This module is a thin wrapper around the `srt-win` CLI; all status
13
- * comes from live enumeration (group via `LookupAccountNameW` +
14
- * token-membership check; WFP via providerData-tag enumeration under
15
- * the configured sublayer). There is no marker file.
24
+ * comes from live enumeration. There is no marker file.
16
25
  *
17
- * Filesystem restrictions are NOT enforced on Windows yet.
26
+ * Filesystem rules (`denyRead`/`denyWrite`/`allowRead`/`allowWrite`)
27
+ * are enforced via additive explicit ACEs for `<sb-SID>` — see
28
+ * {@link grantWindowsAcl} / {@link stampWindowsAcl}.
18
29
  */
19
- export declare const DEFAULT_WINDOWS_GROUP_NAME = "sandbox-runtime-net";
20
30
  export declare const DEFAULT_WINDOWS_PROXY_PORT_RANGE: readonly [number, number];
21
- /** Identifies the discriminator group either by name or by SID. */
22
- export interface WindowsGroupRef {
23
- /** Local or domain group name. Default: `sandbox-runtime-net`. */
24
- groupName?: string;
25
- /**
26
- * Group SID in `S-1-…` form. Takes precedence over `groupName` —
27
- * use for domain groups or where name resolution is unreliable.
28
- */
29
- groupSid?: string;
30
- }
31
- export type WindowsGroupStatus = 'absent' | 'created-not-on-token' | 'ready';
32
- export interface WindowsGroupStatusResult {
33
- state: WindowsGroupStatus;
34
- sid?: string;
35
- warning?: string;
36
- error?: string;
37
- }
38
- export type WindowsWfpStatus = 'absent' | 'installed';
31
+ /**
32
+ * `cannot-read` is the graceful-degrade state when BFE enumeration
33
+ * is access-denied (it is admin-gated). The non-elevated readiness
34
+ * check is {@link verifyWindowsWfpEgress}, not this enum.
35
+ */
36
+ export type WindowsWfpStatus = 'absent' | 'installed' | 'cannot-read';
39
37
  export interface WindowsWfpStatusResult {
40
38
  state: WindowsWfpStatus;
39
+ /** Live filter count from BFE enum; `0` on `cannot-read`. */
41
40
  filters: number;
42
- /** `[low, high]` from the `permit-loopback` filter's tag, when present. */
41
+ /** `[low, high]` for the loopback PERMIT, when known. */
43
42
  portRange?: [number, number];
43
+ /** Sandbox-user SID read from the first user-keyed filter tag. */
44
+ userSid?: string;
45
+ /**
46
+ * Populated only on `cannot-read` (BFE enumeration is admin-gated;
47
+ * a non-elevated caller can't read it). The non-elevated readiness
48
+ * check is {@link verifyWindowsWfpEgress}, not this enum.
49
+ */
50
+ hint?: string;
51
+ }
52
+ /**
53
+ * Result of `srt-win wfp verify` on success (exit 0, `blocked`) —
54
+ * see {@link verifyWindowsWfpEgress}. Any other outcome throws, so
55
+ * the tri-state is unobservable on the return path.
56
+ */
57
+ export interface WindowsWfpVerifyResult {
58
+ target: string;
59
+ /** Runner's stderr (carries the `BLOCKED (…)` diagnostic line). */
60
+ stderr: string;
61
+ }
62
+ /**
63
+ * State of the `srt-sandbox` local account that `srt-win install`
64
+ * provisions. The sandboxed child runs **as** this account.
65
+ */
66
+ export interface WindowsSandboxUserStatus {
67
+ /** The `srt-sandbox` local account exists. */
68
+ provisioned: boolean;
69
+ /** `S-1-5-21-…` of `srt-sandbox`, when provisioned. */
70
+ sid?: string;
71
+ /** The `sandbox-runtime-users` local group exists. */
72
+ groupExists: boolean;
73
+ /** `S-1-5-21-…` of `sandbox-runtime-users`, when it exists. */
74
+ groupSid?: string;
75
+ inBuiltinUsers: boolean;
76
+ inSandboxGroup: boolean;
77
+ hiddenFromLogon: boolean;
78
+ /**
79
+ * The credential row is present in `state.db` and readable by
80
+ * THIS process. False when not yet written, or when called from
81
+ * inside the sandbox (the state-DB directory carries an explicit
82
+ * DENY for `sandbox-runtime-users` — machine-scope DPAPI alone
83
+ * is not a confidentiality boundary).
84
+ */
85
+ credPresent: boolean;
86
+ /** Setup marker schema version, when the marker row exists. */
87
+ markerVersion?: number;
88
+ /**
89
+ * The calling (real) user's SID — the broker's identity, surfaced
90
+ * for diagnostics. The DENY-ACE trustee is `srt-sandbox`'s SID
91
+ * ({@link sid}), not this. Always present.
92
+ */
93
+ realUserSid: string;
94
+ /**
95
+ * SHA-1 thumbprint of the install-time CA, when one was
96
+ * installed via `srt-win user trust-ca`. Uppercase hex.
97
+ */
98
+ caCertThumb?: string;
99
+ /** PEM-encoded install-time CA certificate, when present. */
100
+ caCertPem?: string;
44
101
  }
102
+ /**
103
+ * Inner shell to run `command` under, inside the sandbox. The
104
+ * discriminant picks both the executable and the flag shape (`/c`
105
+ * vs `-Command` vs `-c`); see {@link wrapCommandWithSandboxWindows}.
106
+ *
107
+ * For `kind: 'bash'`, `path` is the absolute Git Bash executable
108
+ * (no fixed install location). It MUST originate from trusted host
109
+ * configuration (user settings / install detection), NEVER from
110
+ * workspace or repository content — the inner shell runs INSIDE the
111
+ * sandbox so an unexpected path is not a sandbox-escape vector, but
112
+ * it would still be an arbitrary-exec footgun if sourced from
113
+ * untrusted input.
114
+ */
115
+ export type WindowsBinShell = {
116
+ kind: 'cmd';
117
+ } | {
118
+ kind: 'powershell';
119
+ } | {
120
+ kind: 'pwsh';
121
+ } | {
122
+ kind: 'bash';
123
+ path: string;
124
+ };
125
+ /**
126
+ * Adapter from the cross-platform `binShell?: string` surface
127
+ * ({@link SandboxManager.wrapWithSandboxArgv}) to the Windows
128
+ * discriminated union. Throws on any value outside the recognised
129
+ * set — there is no silent fallback to cmd.exe.
130
+ *
131
+ * Uses `path.win32` explicitly so the function (and its unit test)
132
+ * is platform-independent.
133
+ */
134
+ export declare function parseWindowsBinShell(raw?: string): WindowsBinShell;
45
135
  export interface WindowsSandboxParams {
46
136
  command: string;
47
- group: WindowsGroupRef;
48
- /** JS HTTP proxy port — fed to `generateProxyEnvVars` for the returned env. */
137
+ /**
138
+ * JS HTTP proxy port — fed to `generateProxyEnvVars` for the env
139
+ * overlay. With the in-process proxy this is the mux front-end
140
+ * port (same as `socksProxyPort`).
141
+ */
49
142
  httpProxyPort?: number;
50
- /** JS SOCKS proxy port — fed to `generateProxyEnvVars` for the returned env. */
143
+ /**
144
+ * JS SOCKS proxy port — fed to `generateProxyEnvVars` for the env
145
+ * overlay. With the in-process proxy this is the mux front-end
146
+ * port (same as `httpProxyPort`).
147
+ */
51
148
  socksProxyPort?: number;
52
149
  /** Per-session proxy auth token; embedded in proxy env URLs. */
53
150
  proxyAuthToken?: string;
54
151
  /**
55
- * Inner shell. `cmd` (default), `powershell`, or `pwsh`. The child's
56
- * post-`/c` content is **passthrough** `&` chains, `"…"` quotes
57
- * exactly as written. The security boundary is at the OUTER spawn
58
- * (this argv is spawned with `shell:false`); the inner cmd.exe runs
59
- * INSIDE the sandbox so its metachars are the user's tool.
152
+ * `mode: 'mask'` credential env vars sentinel values the
153
+ * sandboxed child should see in place of the real credentials.
154
+ * Threaded through the `--env` overlay so the runner forwards
155
+ * them into the child's fresh profile env (the broker's own
156
+ * environment never reaches the child, so an `env -u`-style
157
+ * scrub is structurally moot — there is no `unsetEnvVars`).
158
+ * Applied BEFORE the proxy assignments so the sandbox's own
159
+ * proxy plumbing survives even if a caller masks one of those
160
+ * names — same precedence as macOS/Linux.
60
161
  */
61
- binShell?: string;
162
+ setEnvVars?: Readonly<Record<string, string>>;
163
+ /**
164
+ * Per-exec read-deny paths, applied via an additive
165
+ * `(D;OICI;FA;;;<sb-SID>)` ACE under the `srt-win exec`
166
+ * process's own PID and released after the child exits. Same
167
+ * disk-first chokepoint as the session-level
168
+ * {@link stampWindowsAcl}; same fail-closed semantics (exec
169
+ * fails if any path cannot be stamped).
170
+ *
171
+ * Normalized concrete paths — globs expanded by the caller via
172
+ * {@link expandWindowsFsPaths}, the same as session-level.
173
+ * `srt-win exec`'s `canonicalize_ace_targets` hard-fails on a
174
+ * glob (it never expands), so a `*`/`?` reaching this field is
175
+ * a caller bug.
176
+ */
177
+ denyRead?: readonly string[];
178
+ /** Per-exec write-deny paths — see {@link denyRead}. */
179
+ denyWrite?: readonly string[];
180
+ /**
181
+ * Working directory the child starts in. Fed to
182
+ * {@link buildGitConfigEnv} as a `safe.directory` entry so git
183
+ * inside the sandbox accepts the real-user-owned working tree.
184
+ * Default: `process.cwd()`.
185
+ *
186
+ * `srt-win exec` has no `--cwd` flag — the child's working
187
+ * directory is whatever the caller passes as the spawn `{cwd:}`
188
+ * option (broker `current_dir()` → runner `lpCurrentDirectory` →
189
+ * child inherits). This field must match that spawn option so
190
+ * `safe.directory` covers where git actually runs.
191
+ */
192
+ cwd?: string;
193
+ /**
194
+ * Session-level write-granted paths (the resolved
195
+ * `filesystem.allowWrite` set). Each becomes a `safe.directory`
196
+ * entry — see {@link buildGitConfigEnv}.
197
+ */
198
+ allowWrite?: readonly string[];
199
+ /**
200
+ * Path to the TLS-termination trust bundle (the MITM CA + system
201
+ * roots) — fed to {@link generateProxyEnvVars} so the child's
202
+ * `NODE_EXTRA_CA_CERTS` / `CURL_CA_BUNDLE` / `SSL_CERT_FILE` /
203
+ * etc. point at it. Backslashes are normalised to forward slashes
204
+ * before emission so the value survives msys2 env conversion AND
205
+ * is accepted by native tools.
206
+ *
207
+ * The env-var layer covers OpenSSL-backed clients (msys2 curl,
208
+ * openssl-backed git, node, python, cargo). Schannel/.NET clients
209
+ * that read the Windows certificate store exclusively (System32
210
+ * `curl.exe`, `Invoke-WebRequest`, Go-built tools) trust via the
211
+ * separate `srt-win user trust-ca` / {@link windowsTrustCa}
212
+ * install-time write into the sandbox user's `CurrentUser\Root`.
213
+ *
214
+ * The caller is responsible for the sandbox user having read
215
+ * access to this path — `sandbox-manager.ts`'s `initialize()`
216
+ * pushes it into the session's `acl grant` read-set alongside the
217
+ * working-tree grants.
218
+ */
219
+ caCertPath?: string;
220
+ /**
221
+ * Resolved `srt-win` spawn descriptor — from
222
+ * {@link resolveSrtWin}. Omit to resolve the packaged vendor
223
+ * binary at call time.
224
+ */
225
+ srtWin?: SrtWinSpawn;
226
+ /**
227
+ * Inner shell. Defaults to `{ kind: 'cmd' }`. The child's post-`/c`
228
+ * (or `-Command` / `-c`) content is **passthrough** — `&` chains,
229
+ * `"…"`/`'…'` quotes exactly as written. The security boundary is at
230
+ * the OUTER spawn (this argv is spawned with `shell:false`); the
231
+ * inner shell runs INSIDE the sandbox so its metachars are the
232
+ * user's tool. See {@link parseWindowsBinShell} for the
233
+ * cross-platform string adapter.
234
+ */
235
+ binShell?: WindowsBinShell;
62
236
  }
63
237
  /**
64
- * Locate `srt-win.exe`. Resolution order:
65
- * 1. `SRT_WIN_PATH` env var (CI sets this to the freshly-built binary).
66
- * 2. `<repo>/vendor/srt-win/target/release/srt-win.exe` (local cargo build).
67
- * 3. `<repo>/dist/vendor/srt-win/target/release/srt-win.exe`
68
- * (post-`npm run build` shape, when running from compiled output).
238
+ * Locate the packaged `srt-win.exe`. Resolution order:
239
+ * 1. `<root>/vendor/srt-win/{arch}/srt-win.exe` (prebuilt published npm
240
+ * package, or after `npm run build:srt-win` locally).
241
+ * 2. `<root>/vendor/srt-win-src/target/release/srt-win.exe` (local
242
+ * `cargo build --release` fallback for development).
243
+ *
244
+ * `<root>` is {@link repoRoot} — `__dirname/../..`, which resolves to the
245
+ * repo root from `src/sandbox/` and `dist/sandbox/` alike, and to the
246
+ * package root when installed under `node_modules`.
247
+ *
248
+ * Callers that ship their own binary (or a multicall binary that
249
+ * routes on `argv[1] == `{@link SRT_WIN_DISPATCH_ARG1}) pass
250
+ * `windows.srtWin` instead of relying on this lookup — see
251
+ * {@link resolveSrtWin}.
69
252
  *
70
253
  * Resolution via the optional `@anthropic-ai/sandbox-runtime-win32-*`
71
254
  * platform packages is added separately.
@@ -74,25 +257,128 @@ export interface WindowsSandboxParams {
74
257
  */
75
258
  export declare function getSrtWinPath(): string;
76
259
  /**
77
- * Query the discriminator group's state in SAM and in the current
78
- * process's `TokenGroups`. `ready` means the group exists AND is
79
- * enabled in the caller's token (i.e. the logout/login dance has
80
- * happened). `created-not-on-token` means the install step ran but
81
- * a fresh logon is needed before {@link initialize} can succeed.
260
+ * `argv[1]` sentinel a multicall embedder's dispatcher matches
261
+ * against to route into `srt_win::run_from_args`. Mirrors the Rust
262
+ * `srt_win::SRT_WIN_DISPATCH_ARG1`; the two MUST stay in sync.
263
+ * `run_from_args` strips it before clap, so the standalone binary
264
+ * accepts it harmlessly.
265
+ */
266
+ export declare const SRT_WIN_DISPATCH_ARG1 = "--srt-win";
267
+ /**
268
+ * Resolved `srt-win` spawn descriptor — the executable to load plus
269
+ * the leading arguments that carry the dispatch sentinel. Threaded
270
+ * to every spawn site so {@link resolveSrtWin} runs once (at
271
+ * `initialize()`) instead of re-`stat`ing on every helper call.
82
272
  */
83
- export declare function getWindowsGroupStatus(ref: WindowsGroupRef): WindowsGroupStatusResult;
273
+ export type SrtWinSpawn = Readonly<{
274
+ exe: string;
275
+ prependArgs: readonly string[];
276
+ }>;
84
277
  /**
85
- * Query the WFP filter set under the given sublayer. `installed` means
86
- * srt-win-tagged `permit-group` AND `block` filters are both present
87
- * under that sublayer. Detection is **tag-based** (providerData JSON);
88
- * filters installed by other tooling without the tag are not counted.
278
+ * Resolve the `srt-win` spawn target from config. When `cfg.path` is
279
+ * set it is used verbatim (no fallback to the packaged binary — an
280
+ * explicit override is a directive, not a hint) and
281
+ * {@link SRT_WIN_DISPATCH_ARG1} is prepended so a multicall
282
+ * dispatcher routes on `argv[1]`. When unset, falls back to
283
+ * {@link getSrtWinPath} with no sentinel (the packaged binary
284
+ * doesn't need it; `run_from_args` would strip it anyway).
285
+ */
286
+ export declare function resolveSrtWin(cfg?: SrtWinConfig): SrtWinSpawn;
287
+ /**
288
+ * Query the WFP filter set under the given sublayer via live BFE
289
+ * enumeration. `installed` means at least one srt-win-tagged
290
+ * `block-user` filter is present. Detection is **tag-based**
291
+ * (providerData JSON); filters installed by other tooling without the
292
+ * tag are not counted.
293
+ *
294
+ * BFE enumeration is admin-gated — a non-elevated caller gets
295
+ * `state:"cannot-read"` with a `hint` (not an error). The
296
+ * non-elevated readiness check is {@link verifyWindowsWfpEgress}.
89
297
  */
90
298
  export declare function getWindowsWfpStatus(opts?: {
91
299
  sublayerGuid?: string;
300
+ srtWin?: SrtWinSpawn;
92
301
  }): WindowsWfpStatusResult;
93
- export interface WindowsInstallOptions extends WindowsGroupRef {
94
- /** Add this user (instead of the current user) to the group. */
95
- userSid?: string;
302
+ /**
303
+ * Behavioral proof that the WFP egress fence is active for the
304
+ * sandbox user. Binds a local listener on an ephemeral loopback port
305
+ * outside the WFP loopback-permit range, then spawns `srt-win
306
+ * runner` as the sandbox user (via `CreateProcessWithLogonW`) to
307
+ * attempt a direct TCP connect to it. The WFP block-user filter
308
+ * fires at `ALE_AUTH_CONNECT` — before any packet leaves — so an
309
+ * active fence yields WSAEACCES immediately and a missing fence lets
310
+ * the connect through (the kernel completes the handshake against
311
+ * the listening socket's backlog; no event-loop tick required, so
312
+ * the synchronous `runSrtWin` is safe). Does not require elevation
313
+ * and does not depend on any external host.
314
+ *
315
+ * `initialize()` calls this once per session, so a stale install
316
+ * (sandbox user provisioned but filters since removed) fails closed
317
+ * at session start instead of running every exec with full egress.
318
+ *
319
+ * @param opts.target overrides the probe target (skips the local
320
+ * listener bind).
321
+ * @param opts.proxyPortRange the WFP loopback-permit range the
322
+ * listener must avoid. Default
323
+ * {@link DEFAULT_WINDOWS_PROXY_PORT_RANGE}.
324
+ * @throws on any outcome other than `blocked` (exit 0).
325
+ */
326
+ export declare function verifyWindowsWfpEgress(opts?: {
327
+ target?: string;
328
+ proxyPortRange?: readonly [number, number];
329
+ srtWin?: SrtWinSpawn;
330
+ }): Promise<WindowsWfpVerifyResult>;
331
+ /**
332
+ * Query the sandbox user account's provisioning state. Each field
333
+ * is independently observed so a half-provisioned install (e.g.
334
+ * user exists but credential file missing) is distinguishable.
335
+ * Does not require elevation.
336
+ */
337
+ export declare function getWindowsSandboxUserStatus(opts?: {
338
+ srtWin?: SrtWinSpawn;
339
+ }): WindowsSandboxUserStatus;
340
+ /**
341
+ * Read back the persistent MITM CA the sandbox was installed with
342
+ * (via `srt-win user trust-ca` / {@link windowsTrustCa}).
343
+ * Returns `null` when no CA was installed. The PEM is what `srt-win
344
+ * user status` reconstructs from the DER stored in `state.db`.
345
+ *
346
+ * On Windows, `tlsTerminate` requires this CA to be present in the
347
+ * sandbox user's `CurrentUser\Root` (schannel-level trust is an
348
+ * install-time concern, not per-session); the host calls this from
349
+ * `initialize()` to fail early with an actionable message when it
350
+ * isn't.
351
+ *
352
+ * @param status pass an already-fetched
353
+ * {@link getWindowsSandboxUserStatus} result to avoid a second
354
+ * `srt-win user status` spawn.
355
+ */
356
+ export declare function getWindowsSandboxCaCert(status?: WindowsSandboxUserStatus, opts?: {
357
+ srtWin?: SrtWinSpawn;
358
+ }): {
359
+ pem: string;
360
+ thumb: string;
361
+ } | null;
362
+ /**
363
+ * Install (or replace) the MITM CA in the **sandbox user's**
364
+ * `CurrentUser\Root` and record it in `state.db` (so
365
+ * {@link getWindowsSandboxCaCert} surfaces its thumbprint + PEM).
366
+ * Thin wrapper around `srt-win user trust-ca <path>`. Does NOT
367
+ * require elevation. Persistent until {@link uninstallWindowsSandbox}
368
+ * deletes the sandbox user's profile.
369
+ *
370
+ * The CA has a separate lifecycle from {@link installWindowsSandbox}
371
+ * — install provisions the account/filters and never touches the CA;
372
+ * call this AFTER install when `tlsTerminate` will be used.
373
+ *
374
+ * @throws when the sandbox user is not provisioned, the file is not a
375
+ * parseable X.509 certificate, or the registry write into the
376
+ * sandbox user's hive fails.
377
+ */
378
+ export declare function windowsTrustCa(caCertPath: string, opts?: {
379
+ srtWin?: SrtWinSpawn;
380
+ }): void;
381
+ export interface WindowsInstallOptions {
96
382
  /** WFP sublayer GUID. Omit for srt-win's compile-time default. */
97
383
  sublayerGuid?: string;
98
384
  /**
@@ -101,19 +387,27 @@ export interface WindowsInstallOptions extends WindowsGroupRef {
101
387
  * Default {@link DEFAULT_WINDOWS_PROXY_PORT_RANGE}.
102
388
  */
103
389
  proxyPortRange?: readonly [number, number];
390
+ /**
391
+ * Name for the sandbox user account (created if absent, adopted
392
+ * if it already exists as a local user). Default `srt-sandbox`.
393
+ */
394
+ sandboxUser?: string;
104
395
  /**
105
396
  * Replace an existing install whose configuration differs
106
- * (different group SID or port range under the same sublayer).
107
- * Without this, install refuses with "already installed with
108
- * different config" rather than silently overwriting.
397
+ * (different port range or sandbox-user name under the same
398
+ * sublayer). Without this, install refuses with "already
399
+ * installed with different config" rather than silently
400
+ * overwriting.
109
401
  */
110
402
  force?: boolean;
403
+ /** Resolved `srt-win` spawn descriptor — from {@link resolveSrtWin}. */
404
+ srtWin?: SrtWinSpawn;
111
405
  }
112
406
  export interface WindowsInstallResult {
113
- /** Post-install group state. */
114
- group: WindowsGroupStatusResult;
115
407
  /** Post-install WFP state. */
116
408
  wfp: WindowsWfpStatusResult;
409
+ /** Post-install sandbox-user state. */
410
+ user: WindowsSandboxUserStatus;
117
411
  /**
118
412
  * `true` if the user dismissed the UAC prompt. Not an error —
119
413
  * the install simply didn't happen. Re-run when the user is
@@ -122,73 +416,169 @@ export interface WindowsInstallResult {
122
416
  cancelled?: true;
123
417
  }
124
418
  /**
125
- * One-shot install: creates the discriminator group, adds the
126
- * current user (or `userSid`), and installs the machine-wide WFP
127
- * filter set — all in a single self-elevating process (one UAC
128
- * prompt). Idempotent.
419
+ * One-shot install: provisions the `srt-sandbox` user account and
420
+ * installs the user-SID-keyed WFP filter set all in a single
421
+ * self-elevating process (one UAC prompt). Idempotent; re-running
422
+ * rotates the sandbox user's password.
129
423
  *
130
- * Network for the calling user is **not disrupted** before the
131
- * required logout: while the group is absent from the token, WFP
132
- * filter-0 (PERMIT non-members) matches and traffic flows normally.
133
- * After log-out/log-in, the group is enabled in the token and
134
- * filter-1 (PERMIT group-enabled) takes over for the broker; only
135
- * `srt-win exec` children (group flipped deny-only) fall through to
136
- * the loopback/BLOCK filters.
424
+ * Network for the calling user is **not disrupted**: the filters key
425
+ * on the `srt-sandbox` user's SID, so the broker, services, and
426
+ * every other principal fall through to default-permit. No logout
427
+ * is required.
137
428
  *
138
- * Returns the post-call group + WFP state. If the user cancels the
139
- * UAC prompt this returns `{cancelled: true, …}` rather than
140
- * throwing — cancellation is a user choice, not an error.
429
+ * Returns the post-call WFP + sandbox-user state. If the user
430
+ * cancels the UAC prompt this returns `{cancelled: true, …}` rather
431
+ * than throwing — cancellation is a user choice, not an error.
141
432
  *
142
- * @throws on group/WFP creation failure, or if filters already
143
- * exist under `sublayerGuid` with different configuration and
144
- * `force` is not set.
433
+ * @throws on user/WFP creation failure, or if filters already exist
434
+ * under `sublayerGuid` with a different port range and `force` is
435
+ * not set.
145
436
  */
146
437
  export declare function installWindowsSandbox(opts?: WindowsInstallOptions): WindowsInstallResult;
147
438
  /**
148
- * Remove the WFP filter set under `sublayerGuid` (one UAC prompt).
149
- * Idempotent.
150
- *
151
- * **Does NOT delete the discriminator group** — group membership is
152
- * persistent user state and removing it would force every user to
153
- * re-do the logout dance on the next install. Call
154
- * {@link deleteWindowsGroup} explicitly if you want full teardown.
439
+ * Remove the WFP filter set under `sublayerGuid` and the
440
+ * `srt-sandbox` account, its credential file, and the setup marker
441
+ * (one UAC prompt). Idempotent.
155
442
  *
156
443
  * @returns `{cancelled: true}` if the user dismissed UAC.
157
444
  */
158
445
  export declare function uninstallWindowsSandbox(opts?: {
159
446
  sublayerGuid?: string;
447
+ keepUser?: boolean;
448
+ srtWin?: SrtWinSpawn;
160
449
  }): {
161
450
  cancelled?: true;
162
451
  };
163
452
  /**
164
- * Delete the discriminator group. Separate from
165
- * {@link uninstallWindowsSandbox} so that uninstall→reinstall
166
- * doesn't force a fresh logout for every member. **Requires
167
- * elevation.** Idempotent (no-op if the group doesn't exist).
453
+ * Resolve any Windows filesystem-config path list — `allowRead`/
454
+ * `allowWrite` grants and `denyRead`/`denyWrite` stamps — to
455
+ * concrete existing paths via the single platform-aware
456
+ * {@link normalizePathForSandbox} chokepoint (Linux/macOS parity:
457
+ * point-in-time expansion at session initialize, not per-exec).
458
+ * Glob patterns are expanded; non-glob paths are normalized and
459
+ * returned 1:1. Missing paths are dropped (statSync probe).
460
+ * Directory targets are accepted — the additive sandbox-user ACE
461
+ * carries `(OI)(CI)` so it covers the subtree.
168
462
  */
169
- export declare function deleteWindowsGroup(ref: WindowsGroupRef): void;
463
+ export declare function expandWindowsFsPaths(patterns: readonly string[]): string[];
464
+ export interface WindowsAclStampOptions {
465
+ /** Paths the sandboxed child must not read. */
466
+ denyRead: readonly string[];
467
+ /** Paths the sandboxed child must not write (read stays allowed). */
468
+ denyWrite: readonly string[];
469
+ /** SID of the dedicated sandbox user — {@link WindowsSandboxUserStatus.sid}. */
470
+ sandboxUserSid: string;
471
+ /** Long-lived host PID the holds are tied to. Default: this process. */
472
+ holderPid?: number;
473
+ /** Resolved `srt-win` spawn descriptor — from {@link resolveSrtWin}. */
474
+ srtWin?: SrtWinSpawn;
475
+ }
170
476
  /**
171
- * Granular primitive: create the discriminator group and add the
172
- * current user (or `userSid`). Most callers should use
173
- * {@link installWindowsSandbox} instead; this exists for
174
- * enterprise/CI flows that manage group and WFP separately.
175
- * **Requires elevation.** Idempotent.
477
+ * Apply the file-deny ACE set for one host session: an additive
478
+ * `(D;OICI;mask;;;<sb-SID>)` on the target plus a
479
+ * `(D;OICI;FILE_DELETE_CHILD;;;<sb-SID>)` on the parent no
480
+ * PROTECTED rewrite, no SD snapshot. Idempotent and refcounted via
481
+ * srt-win's `working_aces` table.
482
+ *
483
+ * Inputs are passed verbatim to `srt-win` (which canonicalizes and
484
+ * rejects globs). Callers that accept globs should pre-expand via
485
+ * {@link expandWindowsFsPaths}.
486
+ *
487
+ * @throws on exit ≠ 0 — including exit 2 (one or more inputs
488
+ * skipped). srt-win stamps the resolvable inputs before exiting
489
+ * 2, so on throw the caller should call {@link restoreWindowsAcl}
490
+ * to release whatever WAS stamped.
176
491
  */
177
- export declare function createWindowsGroup(ref: WindowsGroupRef & {
178
- userSid?: string;
179
- }): void;
492
+ export declare function stampWindowsAcl(opts: WindowsAclStampOptions): void;
180
493
  /**
181
- * Granular primitive: install the machine-wide WFP filter set
182
- * under `sublayerGuid` keyed on the group SID. Most callers should
183
- * use {@link installWindowsSandbox} instead; this exists for
184
- * enterprise/CI flows that manage group and WFP separately.
185
- * **Requires elevation.** Idempotent re-running replaces any
186
- * existing srt-win-tagged filters under that sublayer.
494
+ * Per-path outcome from `srt-win acl restore --json` /
495
+ * `revoke --json`. The status set is intentionally loose: the
496
+ * pre-/post- same-user-removal `srt-win` builds emit different
497
+ * vocabularies for `restore` (`restored`/`leftChanged`/… vs
498
+ * `revoked`/`stillHeld`/…). Callers (`reset()`) only log these,
499
+ * so the union is whatever the binary on PATH says.
187
500
  */
188
- export declare function createWindowsWfp(ref: WindowsGroupRef & {
189
- sublayerGuid?: string;
190
- proxyPortRange?: readonly [number, number];
191
- }): void;
501
+ export interface WindowsAclAceOutcome {
502
+ path: string;
503
+ status: string;
504
+ }
505
+ /**
506
+ * Release this holder's deny ACEs and remove the sandbox-user ACE
507
+ * on any path whose refcount falls to zero. Best-effort (does not
508
+ * throw on per-path anomalies); returns per-path outcomes for the
509
+ * caller to surface. Returns `undefined` only when `srt-win`
510
+ * itself failed (no JSON to parse).
511
+ */
512
+ export declare function restoreWindowsAcl(opts: {
513
+ sandboxUserSid: string;
514
+ holderPid?: number;
515
+ srtWin?: SrtWinSpawn;
516
+ }): WindowsAclAceOutcome[] | undefined;
517
+ export interface WindowsAclGrantOptions {
518
+ /** Paths to grant `MODIFY_NO_FDC` on (the working tree, `allowWrite`). */
519
+ write: readonly string[];
520
+ /** Paths to grant `FILE_GENERIC_READ|EXECUTE` on (`allowRead`). */
521
+ read: readonly string[];
522
+ /** SID of the dedicated sandbox user — {@link WindowsSandboxUserStatus.sid}. */
523
+ sandboxUserSid: string;
524
+ /** Long-lived host PID the holds are tied to. Default: this process. */
525
+ holderPid?: number;
526
+ /** Resolved `srt-win` spawn descriptor — from {@link resolveSrtWin}. */
527
+ srtWin?: SrtWinSpawn;
528
+ }
529
+ /**
530
+ * Apply per-session additive `(OI)(CI)` ALLOW ACEs for the sandbox
531
+ * user on each path. The sandbox user has no inherent rights on
532
+ * real-user-owned files; this is what makes the working tree (and
533
+ * explicit `allowRead`/`allowWrite` paths) reachable from the
534
+ * child. Idempotent and refcounted via srt-win's `working_aces`
535
+ * table.
536
+ *
537
+ * @throws on exit ≠ 0. On throw the caller should call
538
+ * {@link revokeWindowsAcl} to release whatever WAS granted.
539
+ */
540
+ export declare function grantWindowsAcl(opts: WindowsAclGrantOptions): void;
541
+ /**
542
+ * Release this holder's grants and remove the sandbox-user ACE on
543
+ * any path whose refcount falls to zero. Best-effort (does not
544
+ * throw); logs anomalies.
545
+ */
546
+ export declare function revokeWindowsAcl(opts: {
547
+ sandboxUserSid: string;
548
+ holderPid?: number;
549
+ srtWin?: SrtWinSpawn;
550
+ }): WindowsAclAceOutcome[] | undefined;
551
+ /**
552
+ * Build the `GIT_CONFIG_COUNT` / `GIT_CONFIG_KEY_<n>` /
553
+ * `GIT_CONFIG_VALUE_<n>` env-var set for the sandboxed child.
554
+ *
555
+ * Emits:
556
+ * - `safe.directory=<dir>` for each entry in `safeDirs` (or one
557
+ * `safe.directory=*` when the list is long) — the working tree
558
+ * is owned by the real user, so git running as `srt-sandbox`
559
+ * refuses with "detected dubious ownership" without it.
560
+ * - `http.schannelUseSSLCAInfo=true` and
561
+ * `http.schannelCheckRevoke=false` when `schannelCa` — makes
562
+ * git's default (schannel) backend honor `GIT_SSL_CAINFO`
563
+ * without `-c http.sslBackend=openssl`. Revocation is disabled
564
+ * because CryptoAPI CRL/OCSP fetches ignore proxy env and would
565
+ * be WFP-fenced.
566
+ *
567
+ * Composes with an existing `GIT_CONFIG_COUNT` in `baseEnv` by
568
+ * continuing its numbering; the returned `GIT_CONFIG_COUNT` is the
569
+ * new total. Under the two-hop launch the broker's own environment
570
+ * never reaches the child, so `baseEnv` is the caller-supplied
571
+ * overlay ({@link WindowsSandboxParams.setEnvVars}), not
572
+ * `process.env`.
573
+ *
574
+ * Paths are emitted with forward slashes so the value survives
575
+ * msys2's env conversion untouched and native git accepts it.
576
+ */
577
+ export declare function buildGitConfigEnv(opts: {
578
+ safeDirs: readonly string[];
579
+ schannelCa: boolean;
580
+ baseEnv?: Readonly<Record<string, string | undefined>>;
581
+ }): Record<string, string>;
192
582
  /**
193
583
  * Build the spawn descriptor for running `command` inside the Windows
194
584
  * sandbox: an `argv` array plus the `env` to spawn it with.
@@ -196,15 +586,16 @@ export declare function createWindowsWfp(ref: WindowsGroupRef & {
196
586
  * Caller MUST spawn the result with `{shell: false}` — that is the
197
587
  * security boundary that keeps untrusted bytes off the host's shell
198
588
  * (the inner `cmd.exe /c` runs INSIDE the sandbox; see
199
- * `vendor/srt-win/src/launch.rs` `build_cmdline` for the passthrough
589
+ * `vendor/srt-win-src/src/launch.rs` `build_cmdline` for the passthrough
200
590
  * rationale) — AND with the returned `env`.
201
591
  *
202
592
  * Proxy configuration is single-sourced by {@link generateProxyEnvVars}
203
593
  * (the same canonical builder used on macOS/Linux). `srt-win exec`
204
594
  * takes no `--http-proxy` / `--socks-proxy` flags and synthesizes no
205
- * proxy env; it forwards its own environment to the sandboxed child
206
- * verbatim. So the full proxy set is merged over the broker's
207
- * environment here and the child inherits it through the spawn.
595
+ * proxy env. The two-hop runner starts with the SANDBOX user's
596
+ * profile env (`USERPROFILE`/`TEMP` isolated) and overlays exactly
597
+ * what we pass as `--env` built here from the broker's `PATH` plus
598
+ * the generated proxy set.
208
599
  */
209
600
  export declare function wrapCommandWithSandboxWindows(p: WindowsSandboxParams): {
210
601
  argv: string[];
@@ -212,13 +603,14 @@ export declare function wrapCommandWithSandboxWindows(p: WindowsSandboxParams):
212
603
  };
213
604
  /**
214
605
  * Install instructions, surfaced verbatim in error messages.
215
- * Tailored to the observed group state: if the install already
216
- * ran (`created-not-on-token`), only the logout is missing.
217
606
  */
218
- export declare function windowsInstallInstructions(ref: WindowsGroupRef, sublayerGuid: string | undefined, groupState: WindowsGroupStatus): string;
607
+ export declare function windowsInstallInstructions(sublayerGuid: string | undefined): string;
219
608
  /**
220
609
  * Check the Windows backend is ready to sandbox. Errors block
221
610
  * `initialize()`; warnings are informational.
222
611
  */
223
- export declare function checkWindowsDependencies(ref: WindowsGroupRef, sublayerGuid?: string): SandboxDependencyCheck;
612
+ export declare function checkWindowsDependencies(opts?: {
613
+ sublayerGuid?: string;
614
+ srtWin?: SrtWinSpawn;
615
+ }): SandboxDependencyCheck;
224
616
  //# sourceMappingURL=windows-sandbox-utils.d.ts.map