@sysid/sandbox-runtime-improved 0.0.51-sysid.1 → 0.0.54-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.
- package/README.md +5 -2
- package/dist/cli.js +91 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/sandbox/http-proxy.d.ts.map +1 -1
- package/dist/sandbox/http-proxy.js +31 -6
- package/dist/sandbox/http-proxy.js.map +1 -1
- package/dist/sandbox/linux-sandbox-utils.d.ts.map +1 -1
- package/dist/sandbox/linux-sandbox-utils.js +17 -11
- package/dist/sandbox/linux-sandbox-utils.js.map +1 -1
- package/dist/sandbox/macos-sandbox-utils.d.ts +1 -0
- package/dist/sandbox/macos-sandbox-utils.d.ts.map +1 -1
- package/dist/sandbox/macos-sandbox-utils.js +16 -2
- package/dist/sandbox/macos-sandbox-utils.js.map +1 -1
- package/dist/sandbox/mitm-leaf.d.ts.map +1 -1
- package/dist/sandbox/mitm-leaf.js +18 -5
- package/dist/sandbox/mitm-leaf.js.map +1 -1
- package/dist/sandbox/sandbox-config.d.ts +53 -0
- package/dist/sandbox/sandbox-config.d.ts.map +1 -1
- package/dist/sandbox/sandbox-config.js +46 -0
- package/dist/sandbox/sandbox-config.js.map +1 -1
- package/dist/sandbox/sandbox-manager.d.ts +4 -0
- package/dist/sandbox/sandbox-manager.d.ts.map +1 -1
- package/dist/sandbox/sandbox-manager.js +172 -40
- package/dist/sandbox/sandbox-manager.js.map +1 -1
- package/dist/sandbox/sandbox-utils.d.ts.map +1 -1
- package/dist/sandbox/sandbox-utils.js +12 -3
- package/dist/sandbox/sandbox-utils.js.map +1 -1
- package/dist/sandbox/tls-terminate-proxy.d.ts +29 -0
- package/dist/sandbox/tls-terminate-proxy.d.ts.map +1 -1
- package/dist/sandbox/tls-terminate-proxy.js +71 -7
- package/dist/sandbox/tls-terminate-proxy.js.map +1 -1
- package/dist/sandbox/windows-sandbox-utils.d.ts +222 -0
- package/dist/sandbox/windows-sandbox-utils.d.ts.map +1 -0
- package/dist/sandbox/windows-sandbox-utils.js +433 -0
- package/dist/sandbox/windows-sandbox-utils.js.map +1 -0
- package/dist/vendor/srt-win/Cargo.lock +361 -0
- package/dist/vendor/srt-win/Cargo.toml +46 -0
- package/dist/vendor/srt-win/ci/cleanup.ps1 +49 -0
- package/dist/vendor/srt-win/ci/smoke-exec.ps1 +446 -0
- package/dist/vendor/srt-win/ci/smoke.ps1 +307 -0
- package/dist/vendor/srt-win/src/job.rs +102 -0
- package/dist/vendor/srt-win/src/launch.rs +732 -0
- package/dist/vendor/srt-win/src/lib.rs +20 -0
- package/dist/vendor/srt-win/src/main.rs +669 -0
- package/dist/vendor/srt-win/src/self_protect.rs +169 -0
- package/dist/vendor/srt-win/src/sid.rs +296 -0
- package/dist/vendor/srt-win/src/token.rs +341 -0
- package/dist/vendor/srt-win/src/util.rs +42 -0
- package/dist/vendor/srt-win/src/wfp.rs +992 -0
- package/dist/vendor/srt-win/src/winsta.rs +209 -0
- package/dist/vendor/srt-win/tests/sd_access_check_matrix.rs +259 -0
- package/package.json +2 -2
- package/vendor/srt-win/Cargo.lock +361 -0
- package/vendor/srt-win/Cargo.toml +46 -0
- package/vendor/srt-win/ci/cleanup.ps1 +49 -0
- package/vendor/srt-win/ci/smoke-exec.ps1 +446 -0
- package/vendor/srt-win/ci/smoke.ps1 +307 -0
- package/vendor/srt-win/src/job.rs +102 -0
- package/vendor/srt-win/src/launch.rs +732 -0
- package/vendor/srt-win/src/lib.rs +20 -0
- package/vendor/srt-win/src/main.rs +669 -0
- package/vendor/srt-win/src/self_protect.rs +169 -0
- package/vendor/srt-win/src/sid.rs +296 -0
- package/vendor/srt-win/src/token.rs +341 -0
- package/vendor/srt-win/src/util.rs +42 -0
- package/vendor/srt-win/src/wfp.rs +992 -0
- package/vendor/srt-win/src/winsta.rs +209 -0
- package/vendor/srt-win/tests/sd_access_check_matrix.rs +259 -0
|
@@ -17,6 +17,57 @@ import { logForDebugging } from '../utils/debug.js';
|
|
|
17
17
|
import { decideAndRespond, } from './request-filter.js';
|
|
18
18
|
import { mintLeafCert, secureContextFor } from './mitm-leaf.js';
|
|
19
19
|
import { stripHopByHop } from './parent-proxy.js';
|
|
20
|
+
/**
|
|
21
|
+
* True if `buf` starts with a TLS Handshake record header.
|
|
22
|
+
*
|
|
23
|
+
* Three bytes: content type 0x16 (Handshake) + legacy_record_version
|
|
24
|
+
* 0x03,0x00–0x03. RFC 8446 §5.1 froze the record-layer version (TLS 1.3+
|
|
25
|
+
* negotiate via the supported_versions extension, the wire header stays
|
|
26
|
+
* ≤0x0303), so this holds for current and future TLS. Same predicate as
|
|
27
|
+
* mitmproxy `starts_like_tls_record`; nginx `ssl_preread` routes on byte 0
|
|
28
|
+
* alone and HAProxy `req.ssl_hello_type` reads 9 bytes to also extract the
|
|
29
|
+
* handshake type — 3 is the established middle ground for "is this TLS".
|
|
30
|
+
*
|
|
31
|
+
* Routing heuristic, not a security check: a non-TLS stream that happens to
|
|
32
|
+
* start 16 03 0x is handed to the TLS server, which then rejects it properly.
|
|
33
|
+
*/
|
|
34
|
+
export function looksLikeClientHello(buf) {
|
|
35
|
+
return (buf.length >= 3 && buf[0] === 0x16 && buf[1] === 0x03 && buf[2] <= 0x03);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Wait for the client's first post-CONNECT bytes and report whether they look
|
|
39
|
+
* like a TLS ClientHello. The caller must already have written the
|
|
40
|
+
* `200 Connection Established` line — clients don't send until they see it.
|
|
41
|
+
*
|
|
42
|
+
* Any bytes consumed here are returned in `.head` so the caller can forward
|
|
43
|
+
* them to whichever downstream (terminate or opaque tunnel) it picks. The
|
|
44
|
+
* socket is left paused so further bytes buffer until the downstream
|
|
45
|
+
* `pipe()` resumes it.
|
|
46
|
+
*/
|
|
47
|
+
export function peekForClientHello(socket, head) {
|
|
48
|
+
if (head.length >= 3) {
|
|
49
|
+
return Promise.resolve({ isTLS: looksLikeClientHello(head), head });
|
|
50
|
+
}
|
|
51
|
+
return new Promise(resolve => {
|
|
52
|
+
let buf = head;
|
|
53
|
+
const done = () => {
|
|
54
|
+
socket.removeListener('data', onData);
|
|
55
|
+
socket.removeListener('close', done);
|
|
56
|
+
resolve({ isTLS: looksLikeClientHello(buf), head: buf });
|
|
57
|
+
};
|
|
58
|
+
const onData = (chunk) => {
|
|
59
|
+
// Pause synchronously so anything after this chunk buffers for the
|
|
60
|
+
// downstream pipe() rather than being dropped in flowing mode.
|
|
61
|
+
socket.pause();
|
|
62
|
+
buf = buf.length ? Buffer.concat([buf, chunk]) : chunk;
|
|
63
|
+
if (buf.length >= 3)
|
|
64
|
+
return done();
|
|
65
|
+
socket.resume();
|
|
66
|
+
};
|
|
67
|
+
socket.on('data', onData);
|
|
68
|
+
socket.once('close', done);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
20
71
|
/**
|
|
21
72
|
* Terminate the client's TLS on `socket`, parse the decrypted HTTP/1.1
|
|
22
73
|
* stream, and forward each request to `target` over a fresh upstream TLS
|
|
@@ -85,9 +136,8 @@ export function terminateAndForward(ca, filterRequest, socket, head, target) {
|
|
|
85
136
|
cleanup();
|
|
86
137
|
});
|
|
87
138
|
loop.once('connect', () => {
|
|
88
|
-
|
|
89
|
-
//
|
|
90
|
-
// start of its ClientHello — forward them first.
|
|
139
|
+
// The caller wrote `200 Connection Established` before sniffing for the
|
|
140
|
+
// ClientHello; `head` holds whatever the sniff consumed.
|
|
91
141
|
if (head.length)
|
|
92
142
|
loop.write(head);
|
|
93
143
|
socket.pipe(loop);
|
|
@@ -107,10 +157,24 @@ async function forwardUpstream(filterRequest, req, res, target) {
|
|
|
107
157
|
if (filterRequest) {
|
|
108
158
|
const ac = new AbortController();
|
|
109
159
|
res.once('close', () => ac.abort());
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
160
|
+
// Build the URL passed to filterRequest from the CONNECT target,
|
|
161
|
+
// NOT from `req.headers.host`. The Host header is supplied by the
|
|
162
|
+
// sandboxed client and can be spoofed: a sandboxed process can
|
|
163
|
+
// CONNECT to allowlisted host A and then send a decrypted request
|
|
164
|
+
// with `Host: B` (where B is some other allowlisted host). If we
|
|
165
|
+
// built the filterRequest URL from req.headers.host the callback
|
|
166
|
+
// would see "host=B" while the request is actually delivered to A.
|
|
167
|
+
// A consumer using filterRequest for per-host method gating (e.g.
|
|
168
|
+
// "POST allowed only to inference endpoints") would be bypassed —
|
|
169
|
+
// the agent could spoof Host: api.example.com on a CONNECT to a
|
|
170
|
+
// different allowlisted host, get the POST allowed, and have it
|
|
171
|
+
// delivered to the CONNECT target instead.
|
|
172
|
+
//
|
|
173
|
+
// Always derive the URL from the verified CONNECT target so
|
|
174
|
+
// filterRequest sees the actual upstream destination.
|
|
175
|
+
const host = target.port === 443
|
|
176
|
+
? target.hostname
|
|
177
|
+
: `${target.hostname}:${target.port}`;
|
|
114
178
|
const out = await decideAndRespond(filterRequest, req, res, `https://${host}${req.url ?? '/'}`, ac.signal);
|
|
115
179
|
if (out === null)
|
|
116
180
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tls-terminate-proxy.js","sourceRoot":"","sources":["../../src/sandbox/tls-terminate-proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,YAAY,IAAI,iBAAiB,EACjC,OAAO,IAAI,YAAY,GACxB,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEnD,OAAO,EACL,gB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AAA;QACxB,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,OAAO,EAAE,CAAA;QACf,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;IACzC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;AACrB,CAAC;AAED,IAAI,OAAO,GAAG,CAAC,CAAA;AACf,SAAS,eAAe;IACtB,+CAA+C;IAC/C,OAAO,IAAI,CACT,MAAM,EAAE,EACR,UAAU,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,CACzD,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import type { SandboxDependencyCheck } from './linux-sandbox-utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Windows sandbox backend.
|
|
4
|
+
*
|
|
5
|
+
* 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.
|
|
11
|
+
*
|
|
12
|
+
* 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.
|
|
16
|
+
*
|
|
17
|
+
* Filesystem restrictions are NOT enforced on Windows yet.
|
|
18
|
+
*/
|
|
19
|
+
export declare const DEFAULT_WINDOWS_GROUP_NAME = "sandbox-runtime-net";
|
|
20
|
+
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';
|
|
39
|
+
export interface WindowsWfpStatusResult {
|
|
40
|
+
state: WindowsWfpStatus;
|
|
41
|
+
filters: number;
|
|
42
|
+
/** `[low, high]` from the `permit-loopback` filter's tag, when present. */
|
|
43
|
+
portRange?: [number, number];
|
|
44
|
+
}
|
|
45
|
+
export interface WindowsSandboxParams {
|
|
46
|
+
command: string;
|
|
47
|
+
group: WindowsGroupRef;
|
|
48
|
+
/** JS HTTP proxy port — fed to `generateProxyEnvVars` for the returned env. */
|
|
49
|
+
httpProxyPort?: number;
|
|
50
|
+
/** JS SOCKS proxy port — fed to `generateProxyEnvVars` for the returned env. */
|
|
51
|
+
socksProxyPort?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Inner shell. `cmd` (default), `powershell`, or `pwsh`. The child's
|
|
54
|
+
* post-`/c` content is **passthrough** — `&` chains, `"…"` quotes
|
|
55
|
+
* exactly as written. The security boundary is at the OUTER spawn
|
|
56
|
+
* (this argv is spawned with `shell:false`); the inner cmd.exe runs
|
|
57
|
+
* INSIDE the sandbox so its metachars are the user's tool.
|
|
58
|
+
*/
|
|
59
|
+
binShell?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Locate `srt-win.exe`. Resolution order:
|
|
63
|
+
* 1. `SRT_WIN_PATH` env var (CI sets this to the freshly-built binary).
|
|
64
|
+
* 2. `<repo>/vendor/srt-win/target/release/srt-win.exe` (local cargo build).
|
|
65
|
+
* 3. `<repo>/dist/vendor/srt-win/target/release/srt-win.exe`
|
|
66
|
+
* (post-`npm run build` shape, when running from compiled output).
|
|
67
|
+
*
|
|
68
|
+
* Resolution via the optional `@anthropic-ai/sandbox-runtime-win32-*`
|
|
69
|
+
* platform packages is added separately.
|
|
70
|
+
*
|
|
71
|
+
* @throws if none exist.
|
|
72
|
+
*/
|
|
73
|
+
export declare function getSrtWinPath(): string;
|
|
74
|
+
/**
|
|
75
|
+
* Query the discriminator group's state in SAM and in the current
|
|
76
|
+
* process's `TokenGroups`. `ready` means the group exists AND is
|
|
77
|
+
* enabled in the caller's token (i.e. the logout/login dance has
|
|
78
|
+
* happened). `created-not-on-token` means the install step ran but
|
|
79
|
+
* a fresh logon is needed before {@link initialize} can succeed.
|
|
80
|
+
*/
|
|
81
|
+
export declare function getWindowsGroupStatus(ref: WindowsGroupRef): WindowsGroupStatusResult;
|
|
82
|
+
/**
|
|
83
|
+
* Query the WFP filter set under the given sublayer. `installed` means
|
|
84
|
+
* srt-win-tagged `permit-group` AND `block` filters are both present
|
|
85
|
+
* under that sublayer. Detection is **tag-based** (providerData JSON);
|
|
86
|
+
* filters installed by other tooling without the tag are not counted.
|
|
87
|
+
*/
|
|
88
|
+
export declare function getWindowsWfpStatus(opts?: {
|
|
89
|
+
sublayerGuid?: string;
|
|
90
|
+
}): WindowsWfpStatusResult;
|
|
91
|
+
export interface WindowsInstallOptions extends WindowsGroupRef {
|
|
92
|
+
/** Add this user (instead of the current user) to the group. */
|
|
93
|
+
userSid?: string;
|
|
94
|
+
/** WFP sublayer GUID. Omit for srt-win's compile-time default. */
|
|
95
|
+
sublayerGuid?: string;
|
|
96
|
+
/**
|
|
97
|
+
* Loopback PERMIT port range. Must match what
|
|
98
|
+
* `SandboxRuntimeConfig.windows.proxyPortRange` will be set to.
|
|
99
|
+
* Default {@link DEFAULT_WINDOWS_PROXY_PORT_RANGE}.
|
|
100
|
+
*/
|
|
101
|
+
proxyPortRange?: readonly [number, number];
|
|
102
|
+
/**
|
|
103
|
+
* Replace an existing install whose configuration differs
|
|
104
|
+
* (different group SID or port range under the same sublayer).
|
|
105
|
+
* Without this, install refuses with "already installed with
|
|
106
|
+
* different config" rather than silently overwriting.
|
|
107
|
+
*/
|
|
108
|
+
force?: boolean;
|
|
109
|
+
}
|
|
110
|
+
export interface WindowsInstallResult {
|
|
111
|
+
/** Post-install group state. */
|
|
112
|
+
group: WindowsGroupStatusResult;
|
|
113
|
+
/** Post-install WFP state. */
|
|
114
|
+
wfp: WindowsWfpStatusResult;
|
|
115
|
+
/**
|
|
116
|
+
* `true` if the user dismissed the UAC prompt. Not an error —
|
|
117
|
+
* the install simply didn't happen. Re-run when the user is
|
|
118
|
+
* ready to grant elevation.
|
|
119
|
+
*/
|
|
120
|
+
cancelled?: true;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* One-shot install: creates the discriminator group, adds the
|
|
124
|
+
* current user (or `userSid`), and installs the machine-wide WFP
|
|
125
|
+
* filter set — all in a single self-elevating process (one UAC
|
|
126
|
+
* prompt). Idempotent.
|
|
127
|
+
*
|
|
128
|
+
* Network for the calling user is **not disrupted** before the
|
|
129
|
+
* required logout: while the group is absent from the token, WFP
|
|
130
|
+
* filter-0 (PERMIT non-members) matches and traffic flows normally.
|
|
131
|
+
* After log-out/log-in, the group is enabled in the token and
|
|
132
|
+
* filter-1 (PERMIT group-enabled) takes over for the broker; only
|
|
133
|
+
* `srt-win exec` children (group flipped deny-only) fall through to
|
|
134
|
+
* the loopback/BLOCK filters.
|
|
135
|
+
*
|
|
136
|
+
* Returns the post-call group + WFP state. If the user cancels the
|
|
137
|
+
* UAC prompt this returns `{cancelled: true, …}` rather than
|
|
138
|
+
* throwing — cancellation is a user choice, not an error.
|
|
139
|
+
*
|
|
140
|
+
* @throws on group/WFP creation failure, or if filters already
|
|
141
|
+
* exist under `sublayerGuid` with different configuration and
|
|
142
|
+
* `force` is not set.
|
|
143
|
+
*/
|
|
144
|
+
export declare function installWindowsSandbox(opts?: WindowsInstallOptions): WindowsInstallResult;
|
|
145
|
+
/**
|
|
146
|
+
* Remove the WFP filter set under `sublayerGuid` (one UAC prompt).
|
|
147
|
+
* Idempotent.
|
|
148
|
+
*
|
|
149
|
+
* **Does NOT delete the discriminator group** — group membership is
|
|
150
|
+
* persistent user state and removing it would force every user to
|
|
151
|
+
* re-do the logout dance on the next install. Call
|
|
152
|
+
* {@link deleteWindowsGroup} explicitly if you want full teardown.
|
|
153
|
+
*
|
|
154
|
+
* @returns `{cancelled: true}` if the user dismissed UAC.
|
|
155
|
+
*/
|
|
156
|
+
export declare function uninstallWindowsSandbox(opts?: {
|
|
157
|
+
sublayerGuid?: string;
|
|
158
|
+
}): {
|
|
159
|
+
cancelled?: true;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Delete the discriminator group. Separate from
|
|
163
|
+
* {@link uninstallWindowsSandbox} so that uninstall→reinstall
|
|
164
|
+
* doesn't force a fresh logout for every member. **Requires
|
|
165
|
+
* elevation.** Idempotent (no-op if the group doesn't exist).
|
|
166
|
+
*/
|
|
167
|
+
export declare function deleteWindowsGroup(ref: WindowsGroupRef): void;
|
|
168
|
+
/**
|
|
169
|
+
* Granular primitive: create the discriminator group and add the
|
|
170
|
+
* current user (or `userSid`). Most callers should use
|
|
171
|
+
* {@link installWindowsSandbox} instead; this exists for
|
|
172
|
+
* enterprise/CI flows that manage group and WFP separately.
|
|
173
|
+
* **Requires elevation.** Idempotent.
|
|
174
|
+
*/
|
|
175
|
+
export declare function createWindowsGroup(ref: WindowsGroupRef & {
|
|
176
|
+
userSid?: string;
|
|
177
|
+
}): void;
|
|
178
|
+
/**
|
|
179
|
+
* Granular primitive: install the machine-wide WFP filter set
|
|
180
|
+
* under `sublayerGuid` keyed on the group SID. Most callers should
|
|
181
|
+
* use {@link installWindowsSandbox} instead; this exists for
|
|
182
|
+
* enterprise/CI flows that manage group and WFP separately.
|
|
183
|
+
* **Requires elevation.** Idempotent — re-running replaces any
|
|
184
|
+
* existing srt-win-tagged filters under that sublayer.
|
|
185
|
+
*/
|
|
186
|
+
export declare function createWindowsWfp(ref: WindowsGroupRef & {
|
|
187
|
+
sublayerGuid?: string;
|
|
188
|
+
proxyPortRange?: readonly [number, number];
|
|
189
|
+
}): void;
|
|
190
|
+
/**
|
|
191
|
+
* Build the spawn descriptor for running `command` inside the Windows
|
|
192
|
+
* sandbox: an `argv` array plus the `env` to spawn it with.
|
|
193
|
+
*
|
|
194
|
+
* Caller MUST spawn the result with `{shell: false}` — that is the
|
|
195
|
+
* security boundary that keeps untrusted bytes off the host's shell
|
|
196
|
+
* (the inner `cmd.exe /c` runs INSIDE the sandbox; see
|
|
197
|
+
* `vendor/srt-win/src/launch.rs` `build_cmdline` for the passthrough
|
|
198
|
+
* rationale) — AND with the returned `env`.
|
|
199
|
+
*
|
|
200
|
+
* Proxy configuration is single-sourced by {@link generateProxyEnvVars}
|
|
201
|
+
* (the same canonical builder used on macOS/Linux). `srt-win exec`
|
|
202
|
+
* takes no `--http-proxy` / `--socks-proxy` flags and synthesizes no
|
|
203
|
+
* proxy env; it forwards its own environment to the sandboxed child
|
|
204
|
+
* verbatim. So the full proxy set is merged over the broker's
|
|
205
|
+
* environment here and the child inherits it through the spawn.
|
|
206
|
+
*/
|
|
207
|
+
export declare function wrapCommandWithSandboxWindows(p: WindowsSandboxParams): {
|
|
208
|
+
argv: string[];
|
|
209
|
+
env: NodeJS.ProcessEnv;
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Install instructions, surfaced verbatim in error messages.
|
|
213
|
+
* Tailored to the observed group state: if the install already
|
|
214
|
+
* ran (`created-not-on-token`), only the logout is missing.
|
|
215
|
+
*/
|
|
216
|
+
export declare function windowsInstallInstructions(ref: WindowsGroupRef, sublayerGuid: string | undefined, groupState: WindowsGroupStatus): string;
|
|
217
|
+
/**
|
|
218
|
+
* Check the Windows backend is ready to sandbox. Errors block
|
|
219
|
+
* `initialize()`; warnings are informational.
|
|
220
|
+
*/
|
|
221
|
+
export declare function checkWindowsDependencies(ref: WindowsGroupRef, sublayerGuid?: string): SandboxDependencyCheck;
|
|
222
|
+
//# sourceMappingURL=windows-sandbox-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"windows-sandbox-utils.d.ts","sourceRoot":"","sources":["../../src/sandbox/windows-sandbox-utils.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AAEtE;;;;;;;;;;;;;;;;GAgBG;AAMH,eAAO,MAAM,0BAA0B,wBAAwB,CAAA;AAC/D,eAAO,MAAM,gCAAgC,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAEtE,CAAA;AAED,mEAAmE;AACnE,MAAM,WAAW,eAAe;IAC9B,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,sBAAsB,GAAG,OAAO,CAAA;AAE5E,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,kBAAkB,CAAA;IACzB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,WAAW,CAAA;AAErD,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,gBAAgB,CAAA;IACvB,OAAO,EAAE,MAAM,CAAA;IACf,2EAA2E;IAC3E,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM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