@capybara-hq/plugin-sdk 0.1.0-rc.38 → 0.1.0-rc.39
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/dist/device-protocol.d.ts +77 -46
- package/dist/device-protocol.js +206 -83
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/network-classes.d.ts +98 -0
- package/dist/network-classes.js +291 -0
- package/dist/sandbox-linux-runtime-source.js +460 -28
- package/dist/sandbox-native-runtime-source.js +143 -3
- package/dist/sandbox-operation.d.ts +36 -4
- package/dist/sandbox-operation.js +21 -4
- package/dist/sandbox-runtime-source.js +2 -2
- package/dist/sandbox-write-denies.d.ts +87 -8
- package/dist/sandbox-write-denies.js +249 -10
- package/dist/sandbox.d.ts +11 -22
- package/package.json +1 -1
|
@@ -5,8 +5,11 @@
|
|
|
5
5
|
* from executing what a restricted command left behind.
|
|
6
6
|
*
|
|
7
7
|
* 1. {@link SANDBOX_MANDATORY_WRITE_DENIES}: component sequences denied wherever they appear (the
|
|
8
|
-
* entry and everything beneath it): shell startup files, git's global files, direnv
|
|
9
|
-
* configuration, editor and agent configuration
|
|
8
|
+
* entry and everything beneath it): shell startup and logout files, git's global files, direnv
|
|
9
|
+
* and npm configuration, editor and agent configuration, and the OS persistence locations
|
|
10
|
+
* (launchd, systemd, environment.d, XDG and KDE autostart, X session files, fish). Entries are
|
|
11
|
+
* written already folded. {@link SANDBOX_SYSTEM_WRITE_DENIES}: absolute system paths denied
|
|
12
|
+
* with everything beneath them (the crontab and at spools), anchored at `/`.
|
|
10
13
|
* 2. Inside a `.git` directory (the first `.git` component of a path) only git's ordinary
|
|
11
14
|
* internals are writable, an allowlist ({@link SANDBOX_GIT_ALLOWED_DIRECTORIES},
|
|
12
15
|
* {@link SANDBOX_GIT_ALLOWED_FILES}, `info/exclude`). Everything else there is denied:
|
|
@@ -16,14 +19,23 @@
|
|
|
16
19
|
* any reading of its name would make it a denied internal.
|
|
17
20
|
* 3. Outside `.git`, a file named `HEAD` is denied: with `objects/` and `refs/` it would make a
|
|
18
21
|
* bare-repository lookalike whose configuration git honours.
|
|
19
|
-
* 4. Moves ({@link isSandboxMoveDenied}):
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
+
* 4. Moves ({@link isSandboxMoveDenied}): neither end may be a denied write; nothing leaves a
|
|
23
|
+
* protected name ({@link SANDBOX_PROTECTED_PATH_NAMES}: `.git` and the single-component
|
|
24
|
+
* entries) except within the same protected directory; a directory is not moved under a
|
|
25
|
+
* protected name from outside it; no non-directory becomes `.git` (a `gitdir:` pointer). For a
|
|
26
|
+
* multi-component entry `[a, b, …]` (or an absolute system path) a destination ending in a
|
|
27
|
+
* proper prefix of it (`…/a`) takes no non-directory (a link there would redirect the entry)
|
|
28
|
+
* and no directory holding the entry's next component (`b`): a prepared directory never moves
|
|
29
|
+
* into place, while ordinary names (`library`, `.config`) stay movable. An ancestor of an
|
|
30
|
+
* anchored path (a system path, or a consumer's resolved target) never moves away.
|
|
22
31
|
*
|
|
23
32
|
* 5. Inside an allowlisted subtree nothing can make a repository: no `.git`, no `HEAD` except
|
|
24
33
|
* where git keeps one (`logs/HEAD`, `refs/remotes/<r>/HEAD`, …), and no `objects`, `commondir`
|
|
25
34
|
* or `gitdir` beside such a `HEAD`.
|
|
26
35
|
*
|
|
36
|
+
* 6. A component starting with {@link SANDBOX_RESERVED_NAME_PREFIX} (the broker's staging and
|
|
37
|
+
* quarantine names) is denied with everything beneath it.
|
|
38
|
+
*
|
|
27
39
|
* Names are compared after Unicode NFKC normalization and full case folding
|
|
28
40
|
* ({@link sandboxFoldName}, identical to Python's `casefold`). Known limitations: a
|
|
29
41
|
* restricted command cannot `git init`, add a submodule or worktree, or create a bare repository;
|
|
@@ -33,6 +45,17 @@
|
|
|
33
45
|
* (its state directories are writable for git's own use) and continuing it runs its `exec` lines.
|
|
34
46
|
* The macOS worker expresses this policy as ordered Seatbelt regex rules
|
|
35
47
|
* (`packages/device/src/exec/mac-write-policy.ts`).
|
|
48
|
+
*
|
|
49
|
+
* Constraints on consumers:
|
|
50
|
+
*
|
|
51
|
+
* - The policy judges the path it is given. A protected home location reached through a symbolic
|
|
52
|
+
* link (`~/.config` or `~/Library` linked elsewhere, as dotfile managers do) is denied only at
|
|
53
|
+
* its resolved target: a device worker resolves the protected home locations at operation start
|
|
54
|
+
* and adds their resolved targets as absolute denies.
|
|
55
|
+
* - The move check needs the entries of a moved directory. A consumer passes them from the source
|
|
56
|
+
* descriptor; the Python `move_denied` otherwise lists the source path, refusing when it cannot.
|
|
57
|
+
* A listing is a snapshot: a concurrent writer could add the next component between the check
|
|
58
|
+
* and the rename, so a consumer that can re-checks the destination after the rename.
|
|
36
59
|
*/
|
|
37
60
|
export const SANDBOX_MANDATORY_WRITE_DENIES = Object.freeze([
|
|
38
61
|
[".gitconfig"],
|
|
@@ -89,7 +112,88 @@ export const SANDBOX_MANDATORY_WRITE_DENIES = Object.freeze([
|
|
|
89
112
|
["simple-git-hooks.cjs"],
|
|
90
113
|
// the conventional core.hooksPath directory a repository's existing config may name
|
|
91
114
|
[".githooks"],
|
|
115
|
+
// every other shell startup and logout file (the kernel review's persistence rules name them)
|
|
116
|
+
[".zshenv"],
|
|
117
|
+
[".zlogin"],
|
|
118
|
+
[".zlogout"],
|
|
119
|
+
[".bash_login"],
|
|
120
|
+
[".bash_logout"],
|
|
121
|
+
[".logout"],
|
|
122
|
+
[".tcshrc"],
|
|
123
|
+
[".cshrc"],
|
|
124
|
+
[".kshrc"],
|
|
125
|
+
[".config", "git", "config"],
|
|
126
|
+
[".config", "fish", "config.fish"],
|
|
127
|
+
[".config", "fish", "conf.d"],
|
|
128
|
+
// persistence locations the OS runs later (approval-only profiles design, "Fixed denies"):
|
|
129
|
+
// launchd agents and daemons, systemd units, drop-ins and session environment, XDG and KDE
|
|
130
|
+
// autostart, the X session files. The crontab spools are SANDBOX_SYSTEM_WRITE_DENIES.
|
|
131
|
+
["library", "launchagents"],
|
|
132
|
+
["library", "launchdaemons"],
|
|
133
|
+
[".config", "systemd"],
|
|
134
|
+
[".local", "share", "systemd"],
|
|
135
|
+
[".config", "environment.d"],
|
|
136
|
+
[".config", "autostart"],
|
|
137
|
+
[".config", "autostart-scripts"],
|
|
138
|
+
[".config", "plasma-workspace", "env"],
|
|
139
|
+
[".xprofile"],
|
|
140
|
+
[".xsessionrc"],
|
|
141
|
+
// PATH-shim persistence: programs placed here shadow system ones in the owner's later shells
|
|
142
|
+
// (`~/bin` is home-anchored: SANDBOX_HOME_WRITE_DENIES)
|
|
143
|
+
[".local", "bin"],
|
|
144
|
+
[".cargo", "bin"],
|
|
92
145
|
].map((entry) => Object.freeze(entry)));
|
|
146
|
+
/**
|
|
147
|
+
* Locations denied only directly under the device owner's home, with everything beneath them, never
|
|
148
|
+
* elsewhere: `~/bin`, a directory many shells put on `PATH`, where a planted program would shadow a
|
|
149
|
+
* system one in the owner's later unsandboxed shell (a project's own `bin/` stays writable).
|
|
150
|
+
* Consumers anchor each entry at the home they protect: the device workers add it, and the target
|
|
151
|
+
* of a link it is, as absolute denies; the kernel never proposes it as a write directory
|
|
152
|
+
* ({@link isSandboxHomeWriteDenied}). `~/.local/bin` and `~/.cargo/bin` are
|
|
153
|
+
* {@link SANDBOX_MANDATORY_WRITE_DENIES} entries.
|
|
154
|
+
*/
|
|
155
|
+
export const SANDBOX_HOME_WRITE_DENIES = Object.freeze([
|
|
156
|
+
Object.freeze(["bin"]),
|
|
157
|
+
]);
|
|
158
|
+
/**
|
|
159
|
+
* System runtime and socket directories (compared folded, anchored at `/`): other programs keep
|
|
160
|
+
* their UNIX sockets and device nodes there (`/run/user/<uid>/bus`, `/var/run/docker.sock`,
|
|
161
|
+
* `/dev`, `/proc`), so a restricted write root never is one, lies inside one or contains one
|
|
162
|
+
* ({@link sandboxRuntimeDirectoryOf}).
|
|
163
|
+
*/
|
|
164
|
+
export const SANDBOX_RUNTIME_DIRECTORIES = Object.freeze([
|
|
165
|
+
"/run",
|
|
166
|
+
"/var/run",
|
|
167
|
+
"/private/var/run",
|
|
168
|
+
"/dev",
|
|
169
|
+
"/proc",
|
|
170
|
+
"/sys",
|
|
171
|
+
]);
|
|
172
|
+
/** The shared temporary directories: never a write root themselves (sockets sit directly in them). */
|
|
173
|
+
const TEMP_DIRECTORIES = ["/tmp", "/private/tmp"];
|
|
174
|
+
/** Socket directories other programs create directly in a temporary directory (folded names). */
|
|
175
|
+
const TEMP_SOCKET_DIRECTORY = /^(?:\.x11-unix|\.ice-unix|\.xim-unix|\.font-unix|\.test-unix|tmux-.*|ssh-.*|com\.apple\.launchd\..*|dbus-.*|systemd-private-.*|zellij-.*|emacs[0-9]+|screen.*|vscode-.*|nvim.*)$/;
|
|
176
|
+
/**
|
|
177
|
+
* Absolute system paths denied with everything beneath them, compared folded and anchored at `/`:
|
|
178
|
+
* the crontab and at spools of Linux (`/var/spool/cron` in its `crontabs` and `tabs` layouts,
|
|
179
|
+
* `/var/spool/at`) and macOS (`/private/var/at`, also spelled `/var/at`; `/usr/lib/cron/tabs` is a
|
|
180
|
+
* link resolving there). Never protected move names: a project's own `at/` or `spool/` stays
|
|
181
|
+
* ordinary.
|
|
182
|
+
*/
|
|
183
|
+
export const SANDBOX_SYSTEM_WRITE_DENIES = Object.freeze([
|
|
184
|
+
"/var/spool/cron",
|
|
185
|
+
"/var/spool/at",
|
|
186
|
+
"/private/var/at/tabs",
|
|
187
|
+
"/private/var/at/jobs",
|
|
188
|
+
"/var/at",
|
|
189
|
+
]);
|
|
190
|
+
/**
|
|
191
|
+
* The name prefix the Linux broker reserves for its own staging (a directory checked before it
|
|
192
|
+
* moves into a guarded place) and quarantine names. Any path with a component starting with it
|
|
193
|
+
* (compared folded) is denied to every sandboxed write, so nothing sandboxed can create, write
|
|
194
|
+
* into, or move into or out of such a directory.
|
|
195
|
+
*/
|
|
196
|
+
export const SANDBOX_RESERVED_NAME_PREFIX = ".capybara-staging-";
|
|
93
197
|
/** Directories inside a gitdir whose whole subtree is writable (objects, refs, operation state). */
|
|
94
198
|
export const SANDBOX_GIT_ALLOWED_DIRECTORIES = Object.freeze([
|
|
95
199
|
"objects",
|
|
@@ -148,11 +252,26 @@ export const SANDBOX_GIT_DENIED_INTERNALS = Object.freeze([
|
|
|
148
252
|
"hooks",
|
|
149
253
|
"info/attributes",
|
|
150
254
|
]);
|
|
151
|
-
/**
|
|
255
|
+
/**
|
|
256
|
+
* Names nothing leaves, and no directory is moved under, from outside: `.git` and the
|
|
257
|
+
* single-component entries. A multi-component entry is guarded by its prefix rule instead (rule 4),
|
|
258
|
+
* so its first component (`library`, `.config`) stays an ordinary name.
|
|
259
|
+
*/
|
|
152
260
|
export const SANDBOX_PROTECTED_PATH_NAMES = Object.freeze([
|
|
153
261
|
".git",
|
|
154
|
-
...new Set(SANDBOX_MANDATORY_WRITE_DENIES.map((entry) => entry[0])),
|
|
262
|
+
...new Set(SANDBOX_MANDATORY_WRITE_DENIES.filter((entry) => entry.length === 1).map((entry) => entry[0])),
|
|
155
263
|
]);
|
|
264
|
+
/** The multi-component entries and the anchored system paths, as folded name sequences. */
|
|
265
|
+
const PREFIX_GUARDED = [
|
|
266
|
+
...SANDBOX_MANDATORY_WRITE_DENIES.filter((entry) => entry.length > 1).map((names) => ({
|
|
267
|
+
names,
|
|
268
|
+
anchored: false,
|
|
269
|
+
})),
|
|
270
|
+
...SANDBOX_SYSTEM_WRITE_DENIES.map((path) => ({
|
|
271
|
+
names: path.split("/").filter((p) => p !== ""),
|
|
272
|
+
anchored: true,
|
|
273
|
+
})),
|
|
274
|
+
];
|
|
156
275
|
/**
|
|
157
276
|
* Python's `str.casefold` where it differs from `toLowerCase` (full case folding, Unicode 15.1),
|
|
158
277
|
* so both implementations fold identically: `ß`→`ss`, `ſ`→`s`, final sigma, Cherokee, ….
|
|
@@ -518,9 +637,57 @@ function gitInternalAllowed(rel) {
|
|
|
518
637
|
}
|
|
519
638
|
return (head === "info" && rel.length === 2 && ["exclude", "exclude.lock"].includes(rel[1]));
|
|
520
639
|
}
|
|
640
|
+
/**
|
|
641
|
+
* The system runtime or socket directory a restricted write root `root` (absolute, normalized) is,
|
|
642
|
+
* lies inside or contains, or null: {@link SANDBOX_RUNTIME_DIRECTORIES} with everything beneath
|
|
643
|
+
* them; `/tmp` and `/private/tmp` themselves (a subdirectory is fine unless it is a known socket
|
|
644
|
+
* directory such as `/tmp/.X11-unix`, `/tmp/tmux-<uid>` or `/tmp/ssh-*`, or lies inside one); and
|
|
645
|
+
* every ancestor of one (`/var`, `/private`). The kernel's candidate builder and admission and the
|
|
646
|
+
* device's root check refuse such a root: a socket there may belong to a process outside the
|
|
647
|
+
* sandbox (the Linux broker also refuses every pathname UNIX connect to a socket the operation did
|
|
648
|
+
* not bind itself).
|
|
649
|
+
*/
|
|
650
|
+
export function sandboxRuntimeDirectoryOf(root) {
|
|
651
|
+
const names = parts(root);
|
|
652
|
+
const within = (anchor) => anchor.length <= names.length && anchor.every((name, j) => names[j] === name);
|
|
653
|
+
const above = (anchor) => names.length < anchor.length && names.every((name, j) => anchor[j] === name);
|
|
654
|
+
for (const directory of SANDBOX_RUNTIME_DIRECTORIES) {
|
|
655
|
+
const anchor = parts(directory);
|
|
656
|
+
if (within(anchor) || above(anchor))
|
|
657
|
+
return directory;
|
|
658
|
+
}
|
|
659
|
+
for (const directory of TEMP_DIRECTORIES) {
|
|
660
|
+
const anchor = parts(directory);
|
|
661
|
+
if (above(anchor) || (within(anchor) && names.length === anchor.length))
|
|
662
|
+
return directory;
|
|
663
|
+
const next = names[anchor.length];
|
|
664
|
+
if (within(anchor) && next !== undefined && TEMP_SOCKET_DIRECTORY.test(next))
|
|
665
|
+
return `${directory}/${next}`;
|
|
666
|
+
}
|
|
667
|
+
return null;
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Whether `path` (absolute, normalized) is a {@link SANDBOX_HOME_WRITE_DENIES} location under
|
|
671
|
+
* `home`, or beneath one (names compared folded).
|
|
672
|
+
*/
|
|
673
|
+
export function isSandboxHomeWriteDenied(path, home) {
|
|
674
|
+
const names = parts(path);
|
|
675
|
+
const base = parts(home);
|
|
676
|
+
return SANDBOX_HOME_WRITE_DENIES.some((entry) => {
|
|
677
|
+
const anchor = [...base, ...entry.map(fold)];
|
|
678
|
+
return anchor.length <= names.length && anchor.every((name, j) => names[j] === name);
|
|
679
|
+
});
|
|
680
|
+
}
|
|
521
681
|
/** Whether restricted execution may never write `path` (an absolute, normalized path). */
|
|
522
682
|
export function isSandboxWriteDenied(path) {
|
|
523
683
|
const names = parts(path);
|
|
684
|
+
if (names.some((name) => name.startsWith(SANDBOX_RESERVED_NAME_PREFIX)))
|
|
685
|
+
return true;
|
|
686
|
+
for (const system of SANDBOX_SYSTEM_WRITE_DENIES) {
|
|
687
|
+
const anchored = parts(system);
|
|
688
|
+
if (anchored.every((name, j) => names[j] === name))
|
|
689
|
+
return true;
|
|
690
|
+
}
|
|
524
691
|
for (const entry of SANDBOX_MANDATORY_WRITE_DENIES)
|
|
525
692
|
for (let i = 0; i + entry.length <= names.length; i++)
|
|
526
693
|
if (entry.every((name, j) => names[i + j] === name))
|
|
@@ -530,10 +697,44 @@ export function isSandboxWriteDenied(path) {
|
|
|
530
697
|
return !gitInternalAllowed(names.slice(git + 1));
|
|
531
698
|
return names[names.length - 1] === "head";
|
|
532
699
|
}
|
|
533
|
-
/**
|
|
534
|
-
|
|
700
|
+
/**
|
|
701
|
+
* The next components a moved entry must not bring to `to`: for each guarded sequence whose proper
|
|
702
|
+
* prefix `to` ends in (anchored: equals), the component that follows. Empty when `to` is no prefix.
|
|
703
|
+
*/
|
|
704
|
+
function prefixNext(to) {
|
|
705
|
+
const next = [];
|
|
706
|
+
for (const { names, anchored } of PREFIX_GUARDED)
|
|
707
|
+
for (let k = 1; k < names.length; k++) {
|
|
708
|
+
if (anchored && to.length !== k)
|
|
709
|
+
continue;
|
|
710
|
+
if (to.length < k)
|
|
711
|
+
continue;
|
|
712
|
+
if (names.slice(0, k).every((name, j) => to[to.length - k + j] === name))
|
|
713
|
+
next.push(names[k]);
|
|
714
|
+
}
|
|
715
|
+
return next;
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Whether a restricted rename or link of `source` to `destination` is refused (rule 4).
|
|
719
|
+
* `sourceEntries` are the names directly in a moved directory; the check needs them only when the
|
|
720
|
+
* destination ends in a proper prefix of a guarded entry, and without them it refuses.
|
|
721
|
+
*/
|
|
722
|
+
export function isSandboxMoveDenied(source, destination, sourceIsDirectory, sourceEntries) {
|
|
723
|
+
if (isSandboxWriteDenied(source) || isSandboxWriteDenied(destination))
|
|
724
|
+
return true;
|
|
535
725
|
const from = parts(source);
|
|
536
726
|
const to = parts(destination);
|
|
727
|
+
// an anchored deny's ancestor never moves away: a link resolved into it would dangle
|
|
728
|
+
for (const { names, anchored } of PREFIX_GUARDED)
|
|
729
|
+
if (anchored && from.length < names.length && from.every((name, k) => names[k] === name))
|
|
730
|
+
return true;
|
|
731
|
+
const next = prefixNext(to);
|
|
732
|
+
if (next.length > 0) {
|
|
733
|
+
if (!sourceIsDirectory || sourceEntries === undefined)
|
|
734
|
+
return true;
|
|
735
|
+
if (sourceEntries.some((name) => next.includes(fold(name))))
|
|
736
|
+
return true;
|
|
737
|
+
}
|
|
537
738
|
const protectedAt = (names) => names.findIndex((n) => SANDBOX_PROTECTED_PATH_NAMES.includes(n));
|
|
538
739
|
const i = protectedAt(from);
|
|
539
740
|
const samePrefix = (n) => n >= 0 && to.length > n + 1 && from.slice(0, n + 1).every((name, k) => to[k] === name);
|
|
@@ -551,10 +752,13 @@ export function isSandboxMoveDenied(source, destination, sourceIsDirectory) {
|
|
|
551
752
|
export const SANDBOX_WRITE_POLICY_PYTHON = `
|
|
552
753
|
import unicodedata as _unicodedata
|
|
553
754
|
WRITE_DENIES = [[_unicodedata.normalize("NFKC", n).casefold() for n in e] for e in ${JSON.stringify(SANDBOX_MANDATORY_WRITE_DENIES)}]
|
|
755
|
+
SYSTEM_WRITE_DENIES = [[_unicodedata.normalize("NFKC", n).casefold() for n in p.split("/") if n] for p in ${JSON.stringify(SANDBOX_SYSTEM_WRITE_DENIES)}]
|
|
756
|
+
PREFIX_GUARDED = [(e, False) for e in WRITE_DENIES if len(e) > 1] + [(e, True) for e in SYSTEM_WRITE_DENIES]
|
|
554
757
|
GIT_ALLOWED_DIRECTORIES = set(${JSON.stringify(SANDBOX_GIT_ALLOWED_DIRECTORIES)})
|
|
555
758
|
GIT_ALLOWED_FILES = set(${JSON.stringify(SANDBOX_GIT_ALLOWED_FILES)})
|
|
556
759
|
GIT_DANGER = set(${JSON.stringify([...GIT_DANGER])})
|
|
557
760
|
PROTECTED_PATH_NAMES = set(${JSON.stringify(SANDBOX_PROTECTED_PATH_NAMES)})
|
|
761
|
+
RESERVED_NAME_PREFIX = ${JSON.stringify(SANDBOX_RESERVED_NAME_PREFIX)}
|
|
558
762
|
|
|
559
763
|
|
|
560
764
|
def _fold_parts(path):
|
|
@@ -603,6 +807,11 @@ def _git_internal_allowed(rel):
|
|
|
603
807
|
|
|
604
808
|
def write_denied(path):
|
|
605
809
|
names = _fold_parts(path)
|
|
810
|
+
if any(n.startswith(RESERVED_NAME_PREFIX) for n in names):
|
|
811
|
+
return True
|
|
812
|
+
for system in SYSTEM_WRITE_DENIES:
|
|
813
|
+
if names[:len(system)] == system:
|
|
814
|
+
return True
|
|
606
815
|
for entry in WRITE_DENIES:
|
|
607
816
|
for i in range(len(names) - len(entry) + 1):
|
|
608
817
|
if names[i:i + len(entry)] == entry:
|
|
@@ -612,8 +821,38 @@ def write_denied(path):
|
|
|
612
821
|
return bool(names) and names[-1] == "head"
|
|
613
822
|
|
|
614
823
|
|
|
615
|
-
def
|
|
824
|
+
def _prefix_next(dst):
|
|
825
|
+
nxt = []
|
|
826
|
+
for names, anchored in PREFIX_GUARDED:
|
|
827
|
+
for k in range(1, len(names)):
|
|
828
|
+
if (anchored and len(dst) != k) or len(dst) < k:
|
|
829
|
+
continue
|
|
830
|
+
if dst[len(dst) - k:] == names[:k]:
|
|
831
|
+
nxt.append(names[k])
|
|
832
|
+
return nxt
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
def move_denied(source, destination, is_dir, entries=None):
|
|
836
|
+
if write_denied(source) or write_denied(destination):
|
|
837
|
+
return True
|
|
616
838
|
src, dst = _fold_parts(source), _fold_parts(destination)
|
|
839
|
+
# an anchored deny's ancestor never moves away: a link resolved into it would dangle
|
|
840
|
+
for names, anchored in PREFIX_GUARDED:
|
|
841
|
+
if anchored and len(src) < len(names) and names[:len(src)] == src:
|
|
842
|
+
return True
|
|
843
|
+
nxt = _prefix_next(dst)
|
|
844
|
+
if nxt:
|
|
845
|
+
if not is_dir:
|
|
846
|
+
return True
|
|
847
|
+
if entries is None:
|
|
848
|
+
# no entries given: list the source path itself, refusing what cannot be listed
|
|
849
|
+
try:
|
|
850
|
+
import os as _os
|
|
851
|
+
entries = _os.listdir(source)
|
|
852
|
+
except OSError:
|
|
853
|
+
return True
|
|
854
|
+
if any(_unicodedata.normalize("NFKC", n).casefold() in nxt for n in entries):
|
|
855
|
+
return True
|
|
617
856
|
|
|
618
857
|
def protected_at(names):
|
|
619
858
|
return next((k for k, n in enumerate(names) if n in PROTECTED_PATH_NAMES), -1)
|
package/dist/sandbox.d.ts
CHANGED
|
@@ -14,24 +14,16 @@ export declare const SANDBOX_EXTENSION_POINT = "sandbox@2";
|
|
|
14
14
|
/** The roots inside the sandbox the model may access. */
|
|
15
15
|
export declare const SANDBOX_ROOTS: readonly ["/workspace", "/skills", "/tmp"];
|
|
16
16
|
/**
|
|
17
|
-
* Sandbox resource and network limits
|
|
18
|
-
*
|
|
17
|
+
* Sandbox resource and network limits: what lifecycle create and update carry (resources and the
|
|
18
|
+
* outer network only; each operation's scope says how it runs). A provider that ignores `network`
|
|
19
|
+
* still runs: it then behaves as an allowlisted sandbox (the safe direction).
|
|
19
20
|
*/
|
|
20
21
|
export interface SandboxLimits {
|
|
21
22
|
cpu: number;
|
|
22
23
|
memoryMb: number;
|
|
23
24
|
diskMb: number;
|
|
24
25
|
/**
|
|
25
|
-
*
|
|
26
|
-
* `sandbox`: the OS sandbox with the network limited by {@link SandboxLimits.network}.
|
|
27
|
-
* For operation-capable providers this encodes the independent device ceiling: auto allows
|
|
28
|
-
* Full access when separately authorized, sandbox permits restricted operations only.
|
|
29
|
-
* It never selects a conversation profile or changes per operation. Legacy consumers retain
|
|
30
|
-
* the current mode behavior until coordinated protocol activation.
|
|
31
|
-
*/
|
|
32
|
-
mode: "auto" | "sandbox";
|
|
33
|
-
/**
|
|
34
|
-
* The network the instance (cloud) must enforce, or the allowlist a local device's sandbox mode
|
|
26
|
+
* The network the instance (cloud) must enforce, or the allowlist a local device's sandbox
|
|
35
27
|
* intersects with its own list (`open-public` is for cloud instances only). Each entry of
|
|
36
28
|
* `hosts` passes {@link validateAllowHost}.
|
|
37
29
|
*/
|
|
@@ -317,17 +309,15 @@ export interface SandboxProvider {
|
|
|
317
309
|
* unit (locale-independent), at most `limit` of them; `truncated` is true when the directory has
|
|
318
310
|
* more. Entries only: never file contents, never a recursive walk. A `name` is never `.` or `..`;
|
|
319
311
|
* `isDir` follows symbolic links (stat semantics: a link to a directory is `true`, a dangling link
|
|
320
|
-
* `false`, and so is a link whose target the
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
* directory that cannot be read.
|
|
312
|
+
* `false`, and so is a link whose target the device cannot reach). Returns null only when the
|
|
313
|
+
* path does not exist and the device could reach it; a path it cannot reach throws (a policy
|
|
314
|
+
* refusal), as does a path that is a file or a directory that cannot be read.
|
|
324
315
|
*
|
|
325
316
|
* Optional: a provider without it (or without {@link SandboxProvider.scan}) offers no projects,
|
|
326
317
|
* and its conversations stay in free mode.
|
|
327
318
|
*/
|
|
328
319
|
list?(h: SandboxHandle, path: string, opts: {
|
|
329
320
|
limit: number;
|
|
330
|
-
limits: Pick<SandboxLimits, "mode">;
|
|
331
321
|
signal: AbortSignal;
|
|
332
322
|
}): Promise<{
|
|
333
323
|
entries: {
|
|
@@ -337,8 +327,7 @@ export interface SandboxProvider {
|
|
|
337
327
|
truncated: boolean;
|
|
338
328
|
} | null>;
|
|
339
329
|
/**
|
|
340
|
-
* Looks for project-like directories, read
|
|
341
|
-
* {@link SandboxProvider.list}). Every provider traverses the same way:
|
|
330
|
+
* Looks for project-like directories, read as for {@link SandboxProvider.list}. Every provider traverses the same way:
|
|
342
331
|
*
|
|
343
332
|
* - Candidates are `base` itself and the directories at most {@link MAX_DEVICE_SCAN_DEPTH}
|
|
344
333
|
* levels below it that hold a `.git` entry (directory or file) or an `AGENTS.md` file.
|
|
@@ -346,7 +335,7 @@ export interface SandboxProvider {
|
|
|
346
335
|
* starting with `.`); a candidate does not stop the descent (a monorepo's sub-projects are
|
|
347
336
|
* candidates too). It never enters a directory named in {@link DEVICE_SCAN_SKIPPED_DIRS}, at
|
|
348
337
|
* any depth, nor one named in {@link DEVICE_SCAN_SKIPPED_BASE_DIRS} directly under `base`;
|
|
349
|
-
* every provider skips exactly these. Paths under `base` the
|
|
338
|
+
* every provider skips exactly these. Paths under `base` the device cannot reach are skipped,
|
|
350
339
|
* never an error.
|
|
351
340
|
* - A directory whose basename does not satisfy {@link isDeviceProjectName} is not returned as
|
|
352
341
|
* a candidate (never with a changed name), but it is still traversed.
|
|
@@ -359,10 +348,10 @@ export interface SandboxProvider {
|
|
|
359
348
|
* {@link MAX_DEVICE_SCAN_RESULTS}.
|
|
360
349
|
*
|
|
361
350
|
* Directory entries only, never file contents. A `base` that does not exist answers `[]`; a
|
|
362
|
-
* `base` that is a file, cannot be read, or lies outside the
|
|
351
|
+
* `base` that is a file, cannot be read, or lies outside what the device reaches throws.
|
|
352
|
+
* Optional, like `list`.
|
|
363
353
|
*/
|
|
364
354
|
scan?(h: SandboxHandle, base: string, opts: {
|
|
365
|
-
limits: Pick<SandboxLimits, "mode">;
|
|
366
355
|
signal: AbortSignal;
|
|
367
356
|
}): Promise<{
|
|
368
357
|
path: string;
|