@bramvanoploo/sandbox-runtime 0.0.0-stage → 0.5.0
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/LICENSE +201 -0
- package/README.md +93 -2
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +285 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/sandbox/credential-decode.d.ts +87 -0
- package/dist/sandbox/credential-decode.d.ts.map +1 -0
- package/dist/sandbox/credential-decode.js +143 -0
- package/dist/sandbox/credential-decode.js.map +1 -0
- package/dist/sandbox/credential-extract.d.ts +67 -0
- package/dist/sandbox/credential-extract.d.ts.map +1 -0
- package/dist/sandbox/credential-extract.js +122 -0
- package/dist/sandbox/credential-extract.js.map +1 -0
- package/dist/sandbox/credential-mask-env.d.ts +33 -0
- package/dist/sandbox/credential-mask-env.d.ts.map +1 -0
- package/dist/sandbox/credential-mask-env.js +155 -0
- package/dist/sandbox/credential-mask-env.js.map +1 -0
- package/dist/sandbox/credential-mask-files.d.ts +120 -0
- package/dist/sandbox/credential-mask-files.d.ts.map +1 -0
- package/dist/sandbox/credential-mask-files.js +285 -0
- package/dist/sandbox/credential-mask-files.js.map +1 -0
- package/dist/sandbox/credential-sentinel.d.ts +88 -0
- package/dist/sandbox/credential-sentinel.d.ts.map +1 -0
- package/dist/sandbox/credential-sentinel.js +177 -0
- package/dist/sandbox/credential-sentinel.js.map +1 -0
- package/dist/sandbox/domain-pattern.d.ts +36 -0
- package/dist/sandbox/domain-pattern.d.ts.map +1 -0
- package/dist/sandbox/domain-pattern.js +60 -0
- package/dist/sandbox/domain-pattern.js.map +1 -0
- package/dist/sandbox/generate-seccomp-filter.d.ts +20 -0
- package/dist/sandbox/generate-seccomp-filter.d.ts.map +1 -0
- package/dist/sandbox/generate-seccomp-filter.js +168 -0
- package/dist/sandbox/generate-seccomp-filter.js.map +1 -0
- package/dist/sandbox/http-proxy.d.ts +85 -0
- package/dist/sandbox/http-proxy.d.ts.map +1 -0
- package/dist/sandbox/http-proxy.js +379 -0
- package/dist/sandbox/http-proxy.js.map +1 -0
- package/dist/sandbox/linux-sandbox-utils.d.ts +162 -0
- package/dist/sandbox/linux-sandbox-utils.d.ts.map +1 -0
- package/dist/sandbox/linux-sandbox-utils.js +1179 -0
- package/dist/sandbox/linux-sandbox-utils.js.map +1 -0
- package/dist/sandbox/linux-violation-monitor.d.ts +48 -0
- package/dist/sandbox/linux-violation-monitor.d.ts.map +1 -0
- package/dist/sandbox/linux-violation-monitor.js +168 -0
- package/dist/sandbox/linux-violation-monitor.js.map +1 -0
- package/dist/sandbox/listen-in-range.d.ts +12 -0
- package/dist/sandbox/listen-in-range.d.ts.map +1 -0
- package/dist/sandbox/listen-in-range.js +43 -0
- package/dist/sandbox/listen-in-range.js.map +1 -0
- package/dist/sandbox/macos-sandbox-utils.d.ts +57 -0
- package/dist/sandbox/macos-sandbox-utils.d.ts.map +1 -0
- package/dist/sandbox/macos-sandbox-utils.js +810 -0
- package/dist/sandbox/macos-sandbox-utils.js.map +1 -0
- package/dist/sandbox/mitm-ca.d.ts +112 -0
- package/dist/sandbox/mitm-ca.d.ts.map +1 -0
- package/dist/sandbox/mitm-ca.js +380 -0
- package/dist/sandbox/mitm-ca.js.map +1 -0
- package/dist/sandbox/mitm-leaf.d.ts +28 -0
- package/dist/sandbox/mitm-leaf.d.ts.map +1 -0
- package/dist/sandbox/mitm-leaf.js +132 -0
- package/dist/sandbox/mitm-leaf.js.map +1 -0
- package/dist/sandbox/mux-proxy.d.ts +59 -0
- package/dist/sandbox/mux-proxy.d.ts.map +1 -0
- package/dist/sandbox/mux-proxy.js +161 -0
- package/dist/sandbox/mux-proxy.js.map +1 -0
- package/dist/sandbox/parent-proxy.d.ts +118 -0
- package/dist/sandbox/parent-proxy.d.ts.map +1 -0
- package/dist/sandbox/parent-proxy.js +469 -0
- package/dist/sandbox/parent-proxy.js.map +1 -0
- package/dist/sandbox/request-filter.d.ts +56 -0
- package/dist/sandbox/request-filter.d.ts.map +1 -0
- package/dist/sandbox/request-filter.js +109 -0
- package/dist/sandbox/request-filter.js.map +1 -0
- package/dist/sandbox/sandbox-config.d.ts +1347 -0
- package/dist/sandbox/sandbox-config.d.ts.map +1 -0
- package/dist/sandbox/sandbox-config.js +917 -0
- package/dist/sandbox/sandbox-config.js.map +1 -0
- package/dist/sandbox/sandbox-manager.d.ts +48 -0
- package/dist/sandbox/sandbox-manager.d.ts.map +1 -0
- package/dist/sandbox/sandbox-manager.js +1498 -0
- package/dist/sandbox/sandbox-manager.js.map +1 -0
- package/dist/sandbox/sandbox-schemas.d.ts +90 -0
- package/dist/sandbox/sandbox-schemas.d.ts.map +1 -0
- package/dist/sandbox/sandbox-schemas.js +3 -0
- package/dist/sandbox/sandbox-schemas.js.map +1 -0
- package/dist/sandbox/sandbox-temp-dir.d.ts +9 -0
- package/dist/sandbox/sandbox-temp-dir.d.ts.map +1 -0
- package/dist/sandbox/sandbox-temp-dir.js +73 -0
- package/dist/sandbox/sandbox-temp-dir.js.map +1 -0
- package/dist/sandbox/sandbox-utils.d.ts +121 -0
- package/dist/sandbox/sandbox-utils.d.ts.map +1 -0
- package/dist/sandbox/sandbox-utils.js +642 -0
- package/dist/sandbox/sandbox-utils.js.map +1 -0
- package/dist/sandbox/sandbox-violation-store.d.ts +19 -0
- package/dist/sandbox/sandbox-violation-store.d.ts.map +1 -0
- package/dist/sandbox/sandbox-violation-store.js +57 -0
- package/dist/sandbox/sandbox-violation-store.js.map +1 -0
- package/dist/sandbox/socks-proxy.d.ts +38 -0
- package/dist/sandbox/socks-proxy.d.ts.map +1 -0
- package/dist/sandbox/socks-proxy.js +123 -0
- package/dist/sandbox/socks-proxy.js.map +1 -0
- package/dist/sandbox/tls-terminate-proxy.d.ts +63 -0
- package/dist/sandbox/tls-terminate-proxy.d.ts.map +1 -0
- package/dist/sandbox/tls-terminate-proxy.js +332 -0
- package/dist/sandbox/tls-terminate-proxy.js.map +1 -0
- package/dist/sandbox/windows-sandbox-utils.d.ts +625 -0
- package/dist/sandbox/windows-sandbox-utils.d.ts.map +1 -0
- package/dist/sandbox/windows-sandbox-utils.js +982 -0
- package/dist/sandbox/windows-sandbox-utils.js.map +1 -0
- package/dist/utils/config-loader.d.ts +24 -0
- package/dist/utils/config-loader.d.ts.map +1 -0
- package/dist/utils/config-loader.js +65 -0
- package/dist/utils/config-loader.js.map +1 -0
- package/dist/utils/debug.d.ts +7 -0
- package/dist/utils/debug.d.ts.map +1 -0
- package/dist/utils/debug.js +25 -0
- package/dist/utils/debug.js.map +1 -0
- package/dist/utils/platform.d.ts +15 -0
- package/dist/utils/platform.d.ts.map +1 -0
- package/dist/utils/platform.js +52 -0
- package/dist/utils/platform.js.map +1 -0
- package/dist/utils/shell-quote.d.ts +27 -0
- package/dist/utils/shell-quote.d.ts.map +1 -0
- package/dist/utils/shell-quote.js +47 -0
- package/dist/utils/shell-quote.js.map +1 -0
- package/dist/utils/which.d.ts +9 -0
- package/dist/utils/which.d.ts.map +1 -0
- package/dist/utils/which.js +28 -0
- package/dist/utils/which.js.map +1 -0
- package/package.json +85 -4
- package/vendor/seccomp/x64/apply-seccomp +0 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-session sentinel registry for credential masking.
|
|
3
|
+
*
|
|
4
|
+
* A masked credential's real value is replaced inside the sandbox with a
|
|
5
|
+
* sentinel of the form `fake_value_<uuid4>`. The sandboxed process sees only
|
|
6
|
+
* the sentinel; the host-side proxy substitutes sentinel→real on egress to
|
|
7
|
+
* allowlisted destinations. The map lives only in process memory — it is
|
|
8
|
+
* never written to disk and never logged.
|
|
9
|
+
*/
|
|
10
|
+
import { randomUUID } from 'node:crypto';
|
|
11
|
+
export const SENTINEL_PREFIX = 'fake_value_';
|
|
12
|
+
/**
|
|
13
|
+
* Sentinel↔real-value map for one sandbox session, keyed by credential name.
|
|
14
|
+
*
|
|
15
|
+
* Each credential carries its own `injectHosts` list, and substitution is
|
|
16
|
+
* gated per sentinel: a sentinel is swapped to its real value only when the
|
|
17
|
+
* destination matches THAT credential's hosts. This prevents laundering
|
|
18
|
+
* credential A through credential B's allowlisted host by sending A's
|
|
19
|
+
* sentinel there — the proxy leaves A's sentinel intact on B's host.
|
|
20
|
+
*
|
|
21
|
+
* Keying on name (not value) means two env vars holding the same secret get
|
|
22
|
+
* distinct sentinels, so each can have an independent host list.
|
|
23
|
+
*/
|
|
24
|
+
export class SentinelRegistry {
|
|
25
|
+
constructor() {
|
|
26
|
+
this.byName = new Map();
|
|
27
|
+
this.bySentinel = new Map();
|
|
28
|
+
// True while every registered sentinel starts with SENTINEL_PREFIX, which
|
|
29
|
+
// keeps the substring fast path in substituteInString() valid. A
|
|
30
|
+
// caller-minted sentinel (e.g. a JWT-shaped fake) clears it.
|
|
31
|
+
this.allSentinelsPrefixed = true;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Return the sentinel for the credential named `name`, minting a fresh one
|
|
35
|
+
* on first use. The sentinel is `fake_value_<uuid4>`: long enough that an
|
|
36
|
+
* accidental collision with legitimate header content is negligible, and
|
|
37
|
+
* free of shell/URL metacharacters so it survives `--setenv` and
|
|
38
|
+
* `env NAME=value` unquoted.
|
|
39
|
+
*
|
|
40
|
+
* Idempotent on `name`: a repeat call returns the same sentinel and updates
|
|
41
|
+
* `realValue`/`injectHosts` in place so `updateConfig()` can change either
|
|
42
|
+
* without invalidating sentinels the sandboxed process has already read.
|
|
43
|
+
*/
|
|
44
|
+
register(name, realValue, injectHosts) {
|
|
45
|
+
return this.registerWithSentinel(name, SENTINEL_PREFIX + randomUUID(), realValue, injectHosts);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Like {@link register}, but with a caller-minted sentinel instead of the
|
|
49
|
+
* default `fake_value_<uuid4>` — used when the fake must keep the real
|
|
50
|
+
* value's shape (e.g. a structurally valid JWT for `decode: "jwt"`), so
|
|
51
|
+
* client-side parsers inside the sandbox don't choke on it.
|
|
52
|
+
*
|
|
53
|
+
* Same idempotency contract as {@link register}: if `name` is already
|
|
54
|
+
* registered, the EXISTING sentinel is returned (and `sentinel` discarded)
|
|
55
|
+
* so a re-register never invalidates a fake the sandboxed process has
|
|
56
|
+
* already read. The caller must mint sentinels with enough entropy that
|
|
57
|
+
* collisions with real content are negligible (embed a uuid4).
|
|
58
|
+
*/
|
|
59
|
+
registerWithSentinel(name, sentinel, realValue, injectHosts) {
|
|
60
|
+
const existing = this.byName.get(name);
|
|
61
|
+
if (existing !== undefined) {
|
|
62
|
+
existing.realValue = realValue;
|
|
63
|
+
existing.injectHosts = injectHosts;
|
|
64
|
+
return existing.sentinel;
|
|
65
|
+
}
|
|
66
|
+
if (!sentinel.startsWith(SENTINEL_PREFIX)) {
|
|
67
|
+
this.allSentinelsPrefixed = false;
|
|
68
|
+
}
|
|
69
|
+
const entry = { name, sentinel, realValue, injectHosts };
|
|
70
|
+
this.byName.set(name, entry);
|
|
71
|
+
this.bySentinel.set(sentinel, entry);
|
|
72
|
+
return sentinel;
|
|
73
|
+
}
|
|
74
|
+
/** Real value for `sentinel`, or undefined if not registered. */
|
|
75
|
+
lookupReal(sentinel) {
|
|
76
|
+
return this.bySentinel.get(sentinel)?.realValue;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Names of the registered credentials whose `injectHosts` cover
|
|
80
|
+
* `destHost`. Diagnostic helper: the proxy uses it to warn when a host is
|
|
81
|
+
* exempted from TLS termination (so substitution can never run there) but
|
|
82
|
+
* a masked credential is configured for injection at it.
|
|
83
|
+
*/
|
|
84
|
+
namesInjectableAt(destHost, matches) {
|
|
85
|
+
const names = [];
|
|
86
|
+
for (const e of this.byName.values()) {
|
|
87
|
+
if (e.injectHosts.some(p => matches(destHost, p)))
|
|
88
|
+
names.push(e.name);
|
|
89
|
+
}
|
|
90
|
+
return names;
|
|
91
|
+
}
|
|
92
|
+
/** Iterate registered `[sentinel, realValue]` pairs. */
|
|
93
|
+
*entries() {
|
|
94
|
+
for (const e of this.bySentinel.values())
|
|
95
|
+
yield [e.sentinel, e.realValue];
|
|
96
|
+
}
|
|
97
|
+
/** Number of registered sentinels. */
|
|
98
|
+
get size() {
|
|
99
|
+
return this.bySentinel.size;
|
|
100
|
+
}
|
|
101
|
+
/** Drop entries whose credential name does not satisfy `keep`. */
|
|
102
|
+
prune(keep) {
|
|
103
|
+
let changed = false;
|
|
104
|
+
for (const [name, entry] of this.byName) {
|
|
105
|
+
if (!keep(name)) {
|
|
106
|
+
this.byName.delete(name);
|
|
107
|
+
this.bySentinel.delete(entry.sentinel);
|
|
108
|
+
changed = true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (changed) {
|
|
112
|
+
this.allSentinelsPrefixed = true;
|
|
113
|
+
for (const s of this.bySentinel.keys()) {
|
|
114
|
+
if (!s.startsWith(SENTINEL_PREFIX)) {
|
|
115
|
+
this.allSentinelsPrefixed = false;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** Drop every mapping. Called on session teardown. */
|
|
122
|
+
clear() {
|
|
123
|
+
this.byName.clear();
|
|
124
|
+
this.bySentinel.clear();
|
|
125
|
+
this.allSentinelsPrefixed = true;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Replace registered sentinels found in `headers` with their real values,
|
|
129
|
+
* in place. Each sentinel substitutes only when `destHost` matches one of
|
|
130
|
+
* THAT credential's `injectHosts` patterns (via `matches`); a sentinel
|
|
131
|
+
* whose host list does not cover `destHost` is left as the useless fake.
|
|
132
|
+
*
|
|
133
|
+
* Scans all header values rather than a fixed set — a sentinel showing up
|
|
134
|
+
* anywhere is the substitution trigger, regardless of header name
|
|
135
|
+
* (Authorization, X-Api-Key, Private-Token, ...).
|
|
136
|
+
*
|
|
137
|
+
* The caller remains responsible for transport gating (TLS-terminated path
|
|
138
|
+
* unless `allowPlaintextInject`).
|
|
139
|
+
*/
|
|
140
|
+
substituteInHeaders(headers, destHost, matches) {
|
|
141
|
+
if (this.bySentinel.size === 0)
|
|
142
|
+
return;
|
|
143
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
144
|
+
if (value === undefined)
|
|
145
|
+
continue;
|
|
146
|
+
if (Array.isArray(value)) {
|
|
147
|
+
for (let i = 0; i < value.length; i++) {
|
|
148
|
+
value[i] = this.substituteInString(value[i], destHost, matches);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
headers[name] = this.substituteInString(value, destHost, matches);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
substituteInString(s, destHost, matches) {
|
|
157
|
+
// Fast path: while every sentinel carries the fixed prefix, a header
|
|
158
|
+
// value that doesn't contain it cannot contain any sentinel. Disabled
|
|
159
|
+
// once a caller-minted sentinel (arbitrary shape) is registered.
|
|
160
|
+
if (this.allSentinelsPrefixed && !s.includes(SENTINEL_PREFIX))
|
|
161
|
+
return s;
|
|
162
|
+
let out = s;
|
|
163
|
+
for (const e of this.bySentinel.values()) {
|
|
164
|
+
if (!out.includes(e.sentinel))
|
|
165
|
+
continue;
|
|
166
|
+
if (!e.injectHosts.some(p => matches(destHost, p)))
|
|
167
|
+
continue;
|
|
168
|
+
// HTTP headers forbid CR/LF; refuse to inject a value containing them
|
|
169
|
+
// so a malformed secret cannot throw ERR_INVALID_CHAR or smuggle headers.
|
|
170
|
+
if (/[\r\n]/.test(e.realValue))
|
|
171
|
+
continue;
|
|
172
|
+
out = out.split(e.sentinel).join(e.realValue);
|
|
173
|
+
}
|
|
174
|
+
return out;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=credential-sentinel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential-sentinel.js","sourceRo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AG,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAA;YACnE,CAAC;QACH,CAAC;IACH,CAAC;IAEO,kBAAkB,CACxB,CAAS,EACT,QAAgB,EAChB,OAAoB;QAEpB,qEAAqE;QACrE,sEAAsE;QACtE,iEAAiE;QACjE,IAAI,IAAI,CAAC,oBAAoB,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC;YAAE,OAAO,CAAC,CAAA;QACvE,IAAI,GAAG,GAAG,CAAC,CAAA;QACX,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC;YACzC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;gBAAE,SAAQ;YACvC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;gBAAE,SAAQ;YAC5D,sEAAsE;YACtE,0EAA0E;YAC1E,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;gBAAE,SAAQ;YACxC,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;QAC/C,CAAC;QACD,OAAO,GAAG,CAAA;IACZ,CAAC;CACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domain-pattern matching shared between runtime host filtering
|
|
3
|
+
* (sandbox-manager) and config-time validation (sandbox-config).
|
|
4
|
+
* Lives in its own module so the schema can import it without pulling
|
|
5
|
+
* in sandbox-manager (which imports the schema — circular).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Match a hostname against a domain pattern.
|
|
9
|
+
*
|
|
10
|
+
* Patterns:
|
|
11
|
+
* - `*` matches everything (deny-all; the schema only accepts this in
|
|
12
|
+
* deniedDomains).
|
|
13
|
+
* - `*.example.com` matches any strict subdomain of example.com.
|
|
14
|
+
* - anything else matches exactly (case-insensitive).
|
|
15
|
+
*
|
|
16
|
+
* Wildcard suffix matching is refused for IP literals so an IPv6 zone-ID
|
|
17
|
+
* payload like `::ffff:1.2.3.4%x.allowed.com` cannot pass `.endsWith()`
|
|
18
|
+
* while the OS connects to the bare IP. isValidHost already rejects `%`,
|
|
19
|
+
* but we refuse here too for defence in depth.
|
|
20
|
+
*/
|
|
21
|
+
export declare function matchesDomainPattern(hostname: string, pattern: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Decide whether a per-credential `injectHosts` entry is reachable via
|
|
24
|
+
* `network.allowedDomains` — i.e. every concrete host that could match
|
|
25
|
+
* `injectHost` is allowed by at least one entry in `allowedDomains`.
|
|
26
|
+
*
|
|
27
|
+
* For an exact `injectHost` (`api.github.com`) this is just
|
|
28
|
+
* `matchesDomainPattern` against each allowed pattern.
|
|
29
|
+
*
|
|
30
|
+
* For a wildcard `injectHost` (`*.X`), an exact allowedDomain can never
|
|
31
|
+
* cover it (it admits only one host), so coverage requires an allowed
|
|
32
|
+
* wildcard `*.Y` whose base is `X` or an ancestor of `X` — e.g.
|
|
33
|
+
* `*.api.github.com` is covered by `*.github.com`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function isInjectHostCoveredByAllowedDomains(injectHost: string, allowedDomains: readonly string[]): boolean;
|
|
36
|
+
//# sourceMappingURL=domain-pattern.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain-pattern.d.ts","sourceRoot":"","sources":["../../src/sandbox/domain-pattern.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd,OAAO,CAST;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mCAAmC,CACjD,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,SAAS,MAAM,EAAE,GAChC,OAAO,CAUT"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domain-pattern matching shared between runtime host filtering
|
|
3
|
+
* (sandbox-manager) and config-time validation (sandbox-config).
|
|
4
|
+
* Lives in its own module so the schema can import it without pulling
|
|
5
|
+
* in sandbox-manager (which imports the schema — circular).
|
|
6
|
+
*/
|
|
7
|
+
import { isIP } from 'node:net';
|
|
8
|
+
import { stripBrackets } from './parent-proxy.js';
|
|
9
|
+
/**
|
|
10
|
+
* Match a hostname against a domain pattern.
|
|
11
|
+
*
|
|
12
|
+
* Patterns:
|
|
13
|
+
* - `*` matches everything (deny-all; the schema only accepts this in
|
|
14
|
+
* deniedDomains).
|
|
15
|
+
* - `*.example.com` matches any strict subdomain of example.com.
|
|
16
|
+
* - anything else matches exactly (case-insensitive).
|
|
17
|
+
*
|
|
18
|
+
* Wildcard suffix matching is refused for IP literals so an IPv6 zone-ID
|
|
19
|
+
* payload like `::ffff:1.2.3.4%x.allowed.com` cannot pass `.endsWith()`
|
|
20
|
+
* while the OS connects to the bare IP. isValidHost already rejects `%`,
|
|
21
|
+
* but we refuse here too for defence in depth.
|
|
22
|
+
*/
|
|
23
|
+
export function matchesDomainPattern(hostname, pattern) {
|
|
24
|
+
const h = hostname.toLowerCase();
|
|
25
|
+
if (pattern === '*')
|
|
26
|
+
return true;
|
|
27
|
+
if (pattern.startsWith('*.')) {
|
|
28
|
+
if (isIP(stripBrackets(h)))
|
|
29
|
+
return false;
|
|
30
|
+
const baseDomain = pattern.substring(2).toLowerCase();
|
|
31
|
+
return h.endsWith('.' + baseDomain);
|
|
32
|
+
}
|
|
33
|
+
return h === pattern.toLowerCase();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Decide whether a per-credential `injectHosts` entry is reachable via
|
|
37
|
+
* `network.allowedDomains` — i.e. every concrete host that could match
|
|
38
|
+
* `injectHost` is allowed by at least one entry in `allowedDomains`.
|
|
39
|
+
*
|
|
40
|
+
* For an exact `injectHost` (`api.github.com`) this is just
|
|
41
|
+
* `matchesDomainPattern` against each allowed pattern.
|
|
42
|
+
*
|
|
43
|
+
* For a wildcard `injectHost` (`*.X`), an exact allowedDomain can never
|
|
44
|
+
* cover it (it admits only one host), so coverage requires an allowed
|
|
45
|
+
* wildcard `*.Y` whose base is `X` or an ancestor of `X` — e.g.
|
|
46
|
+
* `*.api.github.com` is covered by `*.github.com`.
|
|
47
|
+
*/
|
|
48
|
+
export function isInjectHostCoveredByAllowedDomains(injectHost, allowedDomains) {
|
|
49
|
+
if (!injectHost.startsWith('*.')) {
|
|
50
|
+
return allowedDomains.some(p => matchesDomainPattern(injectHost, p));
|
|
51
|
+
}
|
|
52
|
+
const injectBase = injectHost.slice(2).toLowerCase();
|
|
53
|
+
return allowedDomains.some(p => {
|
|
54
|
+
if (!p.startsWith('*.'))
|
|
55
|
+
return false;
|
|
56
|
+
const allowedBase = p.slice(2).toLowerCase();
|
|
57
|
+
return injectBase === allowedBase || injectBase.endsWith('.' + allowedBase);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=domain-pattern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain-pattern.js","sourceRoot":"","sources":["../../src/sandbox/domain-pattern.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,oBAAoB,CAClC,QAAgB,EAChB,OAAe;IAEf,MAAM,CAAC,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAA;IAChC,IAAI,OAAO,KAAK,GAAG;QAAE,OAAO,IAAI,CAAA;IAChC,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7B,IAAI,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAA;QACxC,MAAM,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;QACrD,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,GAAG,UAAU,CAAC,CAAA;IACrC,CAAC;IACD,OAAO,CAAC,KAAK,OAAO,CAAC,WAAW,EAAE,CAAA;AACpC,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,mCAAmC,CACjD,UAAkB,EAClB,cAAiC;IAEjC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACjC,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,oBAAoB,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAA;IACtE,CAAC;IACD,MAAM,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;IACpD,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;QAC7B,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAA;QACrC,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;QAC5C,OAAO,UAAU,KAAK,WAAW,IAAI,UAAU,CAAC,QAAQ,CAAC,GAAG,GAAG,WAAW,CAAC,CAAA;IAC7E,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the path to the apply-seccomp binary from the vendor directory
|
|
3
|
+
* Returns the path if it exists, null otherwise
|
|
4
|
+
*
|
|
5
|
+
* Pre-built apply-seccomp binaries are organized by architecture:
|
|
6
|
+
* - vendor/seccomp/{x64,arm64}/apply-seccomp
|
|
7
|
+
*
|
|
8
|
+
* Tries multiple paths for resilience:
|
|
9
|
+
* 0. Explicit path provided via parameter (checked first if provided)
|
|
10
|
+
* 1. vendor/seccomp/{arch}/apply-seccomp (bundled - when bundled into consuming packages)
|
|
11
|
+
* 2. ../../vendor/seccomp/{arch}/apply-seccomp (package root - standard npm installs)
|
|
12
|
+
* 3. ../vendor/seccomp/{arch}/apply-seccomp (dist/vendor - for bundlers)
|
|
13
|
+
* 4. Global npm install (if seccompBinaryPath not provided) - for native builds
|
|
14
|
+
*
|
|
15
|
+
* @param seccompBinaryPath - Optional explicit path to the apply-seccomp binary. If provided
|
|
16
|
+
* and exists, it will be used. If not provided, falls back to searching local paths and
|
|
17
|
+
* then global npm install (for native builds where vendor directory isn't bundled).
|
|
18
|
+
*/
|
|
19
|
+
export declare function getApplySeccompBinaryPath(seccompBinaryPath?: string): string | null;
|
|
20
|
+
//# sourceMappingURL=generate-seccomp-filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-seccomp-filter.d.ts","sourceRoot":"","sources":["../../src/sandbox/generate-seccomp-filter.ts"],"names":[],"mappings":"AA6IA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,yBAAyB,CACvC,iBAAiB,CAAC,EAAE,MAAM,GACzB,MAAM,GAAG,IAAI,CASf"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { join, dirname } from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import * as fs from 'node:fs';
|
|
4
|
+
import { execSync } from 'node:child_process';
|
|
5
|
+
import { homedir } from 'node:os';
|
|
6
|
+
import { logForDebugging } from '../utils/debug.js';
|
|
7
|
+
// Cache for path lookups (key: explicit path or empty string, value: resolved path or null)
|
|
8
|
+
const applySeccompPathCache = new Map();
|
|
9
|
+
// Cache for global npm paths (computed once per process)
|
|
10
|
+
let cachedGlobalNpmPaths = null;
|
|
11
|
+
/**
|
|
12
|
+
* Get paths to check for globally installed @anthropic-ai/sandbox-runtime package.
|
|
13
|
+
* This is used as a fallback when the binaries aren't bundled (e.g., native builds).
|
|
14
|
+
*/
|
|
15
|
+
function getGlobalNpmPaths() {
|
|
16
|
+
if (cachedGlobalNpmPaths)
|
|
17
|
+
return cachedGlobalNpmPaths;
|
|
18
|
+
const paths = [];
|
|
19
|
+
// Try to get the actual global npm root
|
|
20
|
+
try {
|
|
21
|
+
const npmRoot = execSync('npm root -g', {
|
|
22
|
+
encoding: 'utf8',
|
|
23
|
+
timeout: 5000,
|
|
24
|
+
stdio: ['pipe', 'pipe', 'ignore'],
|
|
25
|
+
}).trim();
|
|
26
|
+
if (npmRoot) {
|
|
27
|
+
paths.push(join(npmRoot, '@anthropic-ai', 'sandbox-runtime'));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// npm not available or failed
|
|
32
|
+
}
|
|
33
|
+
// Common global npm locations as fallbacks
|
|
34
|
+
const home = homedir();
|
|
35
|
+
paths.push(
|
|
36
|
+
// npm global (Linux/macOS)
|
|
37
|
+
join('/usr', 'lib', 'node_modules', '@anthropic-ai', 'sandbox-runtime'), join('/usr', 'local', 'lib', 'node_modules', '@anthropic-ai', 'sandbox-runtime'),
|
|
38
|
+
// npm global with prefix (common on macOS with homebrew)
|
|
39
|
+
join('/opt', 'homebrew', 'lib', 'node_modules', '@anthropic-ai', 'sandbox-runtime'),
|
|
40
|
+
// User-local npm global
|
|
41
|
+
join(home, '.npm', 'lib', 'node_modules', '@anthropic-ai', 'sandbox-runtime'), join(home, '.npm-global', 'lib', 'node_modules', '@anthropic-ai', 'sandbox-runtime'));
|
|
42
|
+
cachedGlobalNpmPaths = paths;
|
|
43
|
+
return paths;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Map Node.js process.arch to our vendor directory architecture names
|
|
47
|
+
* Returns null for unsupported architectures
|
|
48
|
+
*/
|
|
49
|
+
function getVendorArchitecture() {
|
|
50
|
+
const arch = process.arch;
|
|
51
|
+
switch (arch) {
|
|
52
|
+
case 'x64':
|
|
53
|
+
case 'x86_64':
|
|
54
|
+
return 'x64';
|
|
55
|
+
case 'arm64':
|
|
56
|
+
case 'aarch64':
|
|
57
|
+
return 'arm64';
|
|
58
|
+
case 'ia32':
|
|
59
|
+
case 'x86':
|
|
60
|
+
// TODO: Add support for 32-bit x86 (ia32)
|
|
61
|
+
// Currently blocked because the seccomp filter does not block the socketcall() syscall,
|
|
62
|
+
// which is used on 32-bit x86 for all socket operations (socket, socketpair, bind, connect, etc.).
|
|
63
|
+
// On 32-bit x86, the direct socket() syscall doesn't exist - instead, all socket operations
|
|
64
|
+
// are multiplexed through socketcall(SYS_SOCKET, ...), socketcall(SYS_SOCKETPAIR, ...), etc.
|
|
65
|
+
//
|
|
66
|
+
// To properly support 32-bit x86, we need to:
|
|
67
|
+
// 1. Build a separate i386 BPF filter (BPF bytecode is architecture-specific)
|
|
68
|
+
// 2. Modify vendor/seccomp-src/seccomp-unix-block.c to conditionally add rules that block:
|
|
69
|
+
// - socketcall(SYS_SOCKET, [AF_UNIX, ...])
|
|
70
|
+
// - socketcall(SYS_SOCKETPAIR, [AF_UNIX, ...])
|
|
71
|
+
// 3. This requires complex BPF logic to inspect socketcall's sub-function argument
|
|
72
|
+
//
|
|
73
|
+
// Until then, 32-bit x86 is not supported to avoid a security bypass.
|
|
74
|
+
logForDebugging(`[SeccompFilter] 32-bit x86 (ia32) is not currently supported due to missing socketcall() syscall blocking. ` +
|
|
75
|
+
`The current seccomp filter only blocks socket(AF_UNIX, ...), but on 32-bit x86, socketcall() can be used to bypass this.`, { level: 'error' });
|
|
76
|
+
return null;
|
|
77
|
+
default:
|
|
78
|
+
logForDebugging(`[SeccompFilter] Unsupported architecture: ${arch}. Only x64 and arm64 are supported.`);
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get local paths to check for seccomp files (bundled or package installs).
|
|
84
|
+
*/
|
|
85
|
+
function getLocalSeccompPaths(filename) {
|
|
86
|
+
const arch = getVendorArchitecture();
|
|
87
|
+
if (!arch)
|
|
88
|
+
return [];
|
|
89
|
+
const baseDir = dirname(fileURLToPath(import.meta.url));
|
|
90
|
+
const relativePath = join('vendor', 'seccomp', arch, filename);
|
|
91
|
+
return [
|
|
92
|
+
join(baseDir, relativePath), // bundled: same directory as bundle (e.g., when bundled into claude-cli)
|
|
93
|
+
join(baseDir, '..', '..', relativePath), // package root: vendor/seccomp/...
|
|
94
|
+
join(baseDir, '..', relativePath), // dist: dist/vendor/seccomp/...
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get the path to the apply-seccomp binary from the vendor directory
|
|
99
|
+
* Returns the path if it exists, null otherwise
|
|
100
|
+
*
|
|
101
|
+
* Pre-built apply-seccomp binaries are organized by architecture:
|
|
102
|
+
* - vendor/seccomp/{x64,arm64}/apply-seccomp
|
|
103
|
+
*
|
|
104
|
+
* Tries multiple paths for resilience:
|
|
105
|
+
* 0. Explicit path provided via parameter (checked first if provided)
|
|
106
|
+
* 1. vendor/seccomp/{arch}/apply-seccomp (bundled - when bundled into consuming packages)
|
|
107
|
+
* 2. ../../vendor/seccomp/{arch}/apply-seccomp (package root - standard npm installs)
|
|
108
|
+
* 3. ../vendor/seccomp/{arch}/apply-seccomp (dist/vendor - for bundlers)
|
|
109
|
+
* 4. Global npm install (if seccompBinaryPath not provided) - for native builds
|
|
110
|
+
*
|
|
111
|
+
* @param seccompBinaryPath - Optional explicit path to the apply-seccomp binary. If provided
|
|
112
|
+
* and exists, it will be used. If not provided, falls back to searching local paths and
|
|
113
|
+
* then global npm install (for native builds where vendor directory isn't bundled).
|
|
114
|
+
*/
|
|
115
|
+
export function getApplySeccompBinaryPath(seccompBinaryPath) {
|
|
116
|
+
const cacheKey = seccompBinaryPath ?? '';
|
|
117
|
+
if (applySeccompPathCache.has(cacheKey)) {
|
|
118
|
+
return applySeccompPathCache.get(cacheKey);
|
|
119
|
+
}
|
|
120
|
+
const result = findApplySeccompPath(seccompBinaryPath);
|
|
121
|
+
applySeccompPathCache.set(cacheKey, result);
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
function isExecutableFile(p) {
|
|
125
|
+
try {
|
|
126
|
+
if (!fs.statSync(p).isFile())
|
|
127
|
+
return false;
|
|
128
|
+
fs.accessSync(p, fs.constants.X_OK);
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function findApplySeccompPath(seccompBinaryPath) {
|
|
136
|
+
// Check explicit path first (highest priority)
|
|
137
|
+
if (seccompBinaryPath) {
|
|
138
|
+
if (isExecutableFile(seccompBinaryPath)) {
|
|
139
|
+
logForDebugging(`[SeccompFilter] Using apply-seccomp binary from explicit path: ${seccompBinaryPath}`);
|
|
140
|
+
return seccompBinaryPath;
|
|
141
|
+
}
|
|
142
|
+
logForDebugging(`[SeccompFilter] Explicit path provided but not an executable file: ${seccompBinaryPath}`);
|
|
143
|
+
}
|
|
144
|
+
const arch = getVendorArchitecture();
|
|
145
|
+
if (!arch) {
|
|
146
|
+
logForDebugging(`[SeccompFilter] Cannot find apply-seccomp binary: unsupported architecture ${process.arch}`);
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
logForDebugging(`[SeccompFilter] Looking for apply-seccomp binary for architecture: ${arch}`);
|
|
150
|
+
// Check local paths first (bundled or package install)
|
|
151
|
+
for (const binaryPath of getLocalSeccompPaths('apply-seccomp')) {
|
|
152
|
+
if (isExecutableFile(binaryPath)) {
|
|
153
|
+
logForDebugging(`[SeccompFilter] Found apply-seccomp binary: ${binaryPath} (${arch})`);
|
|
154
|
+
return binaryPath;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// Fallback: check global npm install (for native builds without bundled vendor)
|
|
158
|
+
for (const globalBase of getGlobalNpmPaths()) {
|
|
159
|
+
const binaryPath = join(globalBase, 'vendor', 'seccomp', arch, 'apply-seccomp');
|
|
160
|
+
if (isExecutableFile(binaryPath)) {
|
|
161
|
+
logForDebugging(`[SeccompFilter] Found apply-seccomp binary in global install: ${binaryPath} (${arch})`);
|
|
162
|
+
return binaryPath;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
logForDebugging(`[SeccompFilter] apply-seccomp binary not found in any expected location (${arch})`);
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=generate-seccomp-filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-seccomp-filter.js","sourceRoot":"","sources":["../../src/sandbox/generate-seccomp-filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEnD,4FAA4F;AAC5F,MAAM,qBAAqB,GAAG,IAAI,GAAG,EAAyB,CAAA;AAE9D,yDAAyD;AACzD,IAAI,oBAAoB,GAAoB,IAAI,CAAA;AAEhD;;;GAGG;AACH,SAAS,iBAAiB;IACxB,IAAI,oBAAoB;QAAE,OAAO,oBAAoB,CAAA;IAErD,MAAM,KAAK,GAAa,EAAE,CAAA;IAE1B,wCAAwC;IACxC,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,EAAE;YACtC,QAAQ,EAAE,MAAM;YAChB,OAAO,EAAE,IAAI;YACb,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC;SAClC,CA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AAG,IAAI,CACrB,UAAU,EACV,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,eAAe,CAChB,CAAA;QACD,IAAI,gBAAgB,CAAC,UAAU,CAAC,EAAE,CAAC;YACjC,eAAe,CACb,iEAAiE,UAAU,KAAK,IAAI,GAAG,CACxF,CAAA;YACD,OAAO,UAAU,CAAA;QACnB,CAAC;IACH,CAAC;IAED,eAAe,CACb,4EAA4E,IAAI,GAAG,CACpF,CAAA;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { Socket } from 'node:net';
|
|
2
|
+
import type { Duplex } from 'node:stream';
|
|
3
|
+
import type { Server } from 'node:http';
|
|
4
|
+
import { type MitmCA } from './mitm-ca.js';
|
|
5
|
+
import { type FilterRequestCallback, type MutateForwardedHeaders } from './request-filter.js';
|
|
6
|
+
import type { ResolvedParentProxy } from './parent-proxy.js';
|
|
7
|
+
export interface HttpProxyServerOptions {
|
|
8
|
+
filter(port: number, host: string, socket: Socket | Duplex): Promise<boolean> | boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Optional function to get the MITM proxy socket path for a given host.
|
|
11
|
+
* If returns a socket path, the request will be routed through that MITM proxy.
|
|
12
|
+
* If returns undefined, the request will be handled directly.
|
|
13
|
+
*/
|
|
14
|
+
getMitmSocketPath?(host: string): string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* If present, CONNECT requests are TLS-terminated in-process and the
|
|
17
|
+
* decrypted HTTP forwarded upstream over real TLS, instead of opening an
|
|
18
|
+
* opaque byte tunnel. Mutually exclusive with getMitmSocketPath at the
|
|
19
|
+
* config layer (sandbox-manager rejects both being set).
|
|
20
|
+
*/
|
|
21
|
+
mitmCA?: MitmCA;
|
|
22
|
+
/**
|
|
23
|
+
* Per-host opt-out of TLS termination; consulted only when `mitmCA` is
|
|
24
|
+
* set. Return false to leave that CONNECT as an opaque byte tunnel
|
|
25
|
+
* (still hostname-allowlisted via `filter`, but not content-inspected —
|
|
26
|
+
* the same posture as the non-tlsTerminate path), so the sandboxed
|
|
27
|
+
* client performs its own TLS handshake end-to-end with the upstream.
|
|
28
|
+
*
|
|
29
|
+
* Use for upstreams the proxy must not re-originate: mTLS services
|
|
30
|
+
* (only the in-sandbox client holds the client certificate) and
|
|
31
|
+
* certificate-pinning clients that reject the MITM CA. Note that
|
|
32
|
+
* `filterRequest` and `mutateHeaders` never see the HTTPS traffic to
|
|
33
|
+
* these hosts; plain-HTTP proxy requests to them are unaffected (those
|
|
34
|
+
* are readable without termination and keep the normal request pipeline).
|
|
35
|
+
*
|
|
36
|
+
* Absent, or returning true, means today's behaviour: terminate.
|
|
37
|
+
*/
|
|
38
|
+
shouldTerminateTLS?(hostname: string, port: number): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Per-request filter; runs on plain-HTTP proxy requests and on terminated
|
|
41
|
+
* HTTPS requests. See request-filter.ts.
|
|
42
|
+
*/
|
|
43
|
+
filterRequest?: FilterRequestCallback;
|
|
44
|
+
/**
|
|
45
|
+
* Dynamic lookup for `filterRequest`, allowing `updateConfig()` to swap
|
|
46
|
+
* the callback on a live proxy. Takes precedence over `filterRequest`.
|
|
47
|
+
*/
|
|
48
|
+
getFilterRequest?: () => FilterRequestCallback | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Mutate forwarded headers on the TLS-terminated path, after the allow
|
|
51
|
+
* decision and before the upstream request is built. The upstream leg is
|
|
52
|
+
* always cert-verified (rejectUnauthorized defaults to true), so the TLS
|
|
53
|
+
* handshake fails before any mutated header bytes reach an unverified
|
|
54
|
+
* server. See {@link MutateForwardedHeaders}.
|
|
55
|
+
*/
|
|
56
|
+
mutateHeaders?: MutateForwardedHeaders;
|
|
57
|
+
getMutateHeaders?: () => MutateForwardedHeaders | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Mutate forwarded headers on the plain-HTTP path. Separate from
|
|
60
|
+
* `mutateHeaders` so callers can wire the TLS path only — credential
|
|
61
|
+
* injection over plaintext is opt-in.
|
|
62
|
+
*/
|
|
63
|
+
mutateHeadersPlaintext?: MutateForwardedHeaders;
|
|
64
|
+
getMutateHeadersPlaintext?: () => MutateForwardedHeaders | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Additional trusted CA(s) for the terminating proxy's outbound TLS leg.
|
|
67
|
+
* Unset → system roots + NODE_EXTRA_CA_CERTS. Primarily a test seam.
|
|
68
|
+
*/
|
|
69
|
+
tlsTerminateUpstreamCA?: string | Buffer | Array<string | Buffer>;
|
|
70
|
+
/**
|
|
71
|
+
* Optional upstream HTTP proxy. When present, direct-connect traffic (i.e.
|
|
72
|
+
* not routed via mitmProxy) is tunnelled through this parent instead of
|
|
73
|
+
* connecting directly. NO_PROXY-matched hosts still connect directly.
|
|
74
|
+
*/
|
|
75
|
+
parentProxy?: ResolvedParentProxy;
|
|
76
|
+
/**
|
|
77
|
+
* Per-session bearer token. When set, every CONNECT and absolute-URI
|
|
78
|
+
* request must carry `Proxy-Authorization: Basic base64("srt:<token>")`
|
|
79
|
+
* or it gets a 407. Without this, any host process can dial 127.0.0.1
|
|
80
|
+
* and reach the filter callback.
|
|
81
|
+
*/
|
|
82
|
+
proxyAuthToken?: string;
|
|
83
|
+
}
|
|
84
|
+
export declare function createHttpProxyServer(options: HttpProxyServerOptions): Server;
|
|
85
|
+
//# sourceMappingURL=http-proxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-proxy.d.ts","sourceRoot":"","sources":["../../src/sandbox/http-proxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,MAAM,EAAE,MAAM,UAAU,CAAA;AACnD,OAAO,KAAK,EAAE,MAAM,EAAY,MAAM,aAAa,CAAA;AACnD,OAAO,KAAK,EAAmB,MAAM,EAAE,MAAM,WAAW,CAAA;AAOxD,OAAO,EAAY,KAAK,MAAM,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,sBAAs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