@openclaw/openshell-sandbox 2026.9.6 → 2026.9.8
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/assets/icon.png +0 -0
- package/dist/index.js +75 -229
- package/node_modules/@openclaw/fs-safe/CHANGELOG.md +102 -0
- package/node_modules/@openclaw/fs-safe/README.md +24 -6
- package/node_modules/@openclaw/fs-safe/dist/advanced.d.ts +6 -1
- package/node_modules/@openclaw/fs-safe/dist/advanced.js +3 -1
- package/node_modules/@openclaw/fs-safe/dist/archive-durability.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/archive-merge.js +1 -2
- package/node_modules/@openclaw/fs-safe/dist/archive-plan.d.ts +2 -7
- package/node_modules/@openclaw/fs-safe/dist/archive-read.js +9 -18
- package/node_modules/@openclaw/fs-safe/dist/archive-staging.d.ts +1 -2
- package/node_modules/@openclaw/fs-safe/dist/archive-staging.js +3 -3
- package/node_modules/@openclaw/fs-safe/dist/archive-zip-directory.js +4 -0
- package/node_modules/@openclaw/fs-safe/dist/archive-zip-entry.d.ts +11 -11
- package/node_modules/@openclaw/fs-safe/dist/archive-zip-entry.js +3 -35
- package/node_modules/@openclaw/fs-safe/dist/archive-zip-integrity.d.ts +2 -2
- package/node_modules/@openclaw/fs-safe/dist/archive-zip-integrity.js +2 -12
- package/node_modules/@openclaw/fs-safe/dist/archive-zip-loader.d.ts +7 -3
- package/node_modules/@openclaw/fs-safe/dist/archive-zip-loader.js +13 -10
- package/node_modules/@openclaw/fs-safe/dist/archive-zip-manifest.js +3 -1
- package/node_modules/@openclaw/fs-safe/dist/archive-zip-preflight.d.ts +2 -3
- package/node_modules/@openclaw/fs-safe/dist/archive-zip-preflight.js +16 -8
- package/node_modules/@openclaw/fs-safe/dist/archive.d.ts +6 -3
- package/node_modules/@openclaw/fs-safe/dist/archive.js +22 -19
- package/node_modules/@openclaw/fs-safe/dist/atomic.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/copy-publication.d.ts +1 -3
- package/node_modules/@openclaw/fs-safe/dist/copy-publication.js +2 -6
- package/node_modules/@openclaw/fs-safe/dist/deny-mutation-match.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/deny-mutation-match.js +71 -0
- package/node_modules/@openclaw/fs-safe/dist/deny-mutations.js +4 -3
- package/node_modules/@openclaw/fs-safe/dist/directory-guard.d.ts +0 -1
- package/node_modules/@openclaw/fs-safe/dist/directory-guard.js +0 -3
- package/node_modules/@openclaw/fs-safe/dist/directory-mode-node.d.ts +20 -2
- package/node_modules/@openclaw/fs-safe/dist/directory-mode-node.js +77 -1
- package/node_modules/@openclaw/fs-safe/dist/directory-receipt.js +5 -7
- package/node_modules/@openclaw/fs-safe/dist/effective-uid.js +1 -4
- package/node_modules/@openclaw/fs-safe/dist/errors.d.ts +3 -1
- package/node_modules/@openclaw/fs-safe/dist/errors.js +3 -2
- package/node_modules/@openclaw/fs-safe/dist/file-identity.js +10 -2
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-acquisition.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-admission.js +5 -1
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-held.d.ts +4 -11
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-held.js +1 -4
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-io.d.ts +3 -6
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-io.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-options.d.ts +2 -10
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root.d.ts +2 -4
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync.js +2 -2
- package/node_modules/@openclaw/fs-safe/dist/file-store-boundary.d.ts +3 -7
- package/node_modules/@openclaw/fs-safe/dist/file-store-boundary.js +7 -10
- package/node_modules/@openclaw/fs-safe/dist/file-store-prune.js +7 -6
- package/node_modules/@openclaw/fs-safe/dist/file-store.d.ts +4 -7
- package/node_modules/@openclaw/fs-safe/dist/file-store.js +19 -21
- package/node_modules/@openclaw/fs-safe/dist/guest-native-python.js +23 -31
- package/node_modules/@openclaw/fs-safe/dist/guest.js +21 -12
- package/node_modules/@openclaw/fs-safe/dist/json-document-store.d.ts +4 -9
- package/node_modules/@openclaw/fs-safe/dist/json-durable-queue-ownership.d.ts +1 -5
- package/node_modules/@openclaw/fs-safe/dist/json-durable-queue.d.ts +0 -1
- package/node_modules/@openclaw/fs-safe/dist/json-durable-queue.js +2 -7
- package/node_modules/@openclaw/fs-safe/dist/local-file-access.js +2 -5
- package/node_modules/@openclaw/fs-safe/dist/local-file-descriptor.d.ts +2 -5
- package/node_modules/@openclaw/fs-safe/dist/local-roots.d.ts +2 -7
- package/node_modules/@openclaw/fs-safe/dist/move-path-cleanup.js +4 -4
- package/node_modules/@openclaw/fs-safe/dist/mutation-authority.js +5 -0
- package/node_modules/@openclaw/fs-safe/dist/native-binding.d.ts +51 -14
- package/node_modules/@openclaw/fs-safe/dist/native-pinned-write.js +8 -2
- package/node_modules/@openclaw/fs-safe/dist/native-staged-symlink.d.ts +13 -0
- package/node_modules/@openclaw/fs-safe/dist/native-staged-symlink.js +303 -0
- package/node_modules/@openclaw/fs-safe/dist/owner-dacl-batch-worker.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/owner-dacl-batch-worker.js +54 -0
- package/node_modules/@openclaw/fs-safe/dist/owner-dacl-batch.d.ts +5 -0
- package/node_modules/@openclaw/fs-safe/dist/owner-dacl-batch.js +64 -0
- package/node_modules/@openclaw/fs-safe/dist/owner-dacl.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/owner-dacl.js +3 -0
- package/node_modules/@openclaw/fs-safe/dist/path.js +17 -1
- package/node_modules/@openclaw/fs-safe/dist/permission-exec.d.ts +6 -0
- package/node_modules/@openclaw/fs-safe/dist/permission-exec.js +3 -6
- package/node_modules/@openclaw/fs-safe/dist/permissions-public.d.ts +3 -1
- package/node_modules/@openclaw/fs-safe/dist/permissions-public.js +1 -0
- package/node_modules/@openclaw/fs-safe/dist/permissions-windows.d.ts +3 -6
- package/node_modules/@openclaw/fs-safe/dist/permissions.d.ts +3 -10
- package/node_modules/@openclaw/fs-safe/dist/permissions.js +0 -1
- package/node_modules/@openclaw/fs-safe/dist/pinned-mutation-admission.d.ts +0 -1
- package/node_modules/@openclaw/fs-safe/dist/pinned-mutation-admission.js +4 -2
- package/node_modules/@openclaw/fs-safe/dist/pinned-mutation-shared-route.d.ts +2 -8
- package/node_modules/@openclaw/fs-safe/dist/pinned-open.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/pinned-open.js +2 -3
- package/node_modules/@openclaw/fs-safe/dist/publish-copy-stage.js +4 -0
- package/node_modules/@openclaw/fs-safe/dist/read-opened-file.d.ts +2 -5
- package/node_modules/@openclaw/fs-safe/dist/regular-file.js +3 -3
- package/node_modules/@openclaw/fs-safe/dist/replace-directory.js +5 -17
- package/node_modules/@openclaw/fs-safe/dist/replace-file-buffer.d.ts +4 -0
- package/node_modules/@openclaw/fs-safe/dist/replace-file-buffer.js +36 -0
- package/node_modules/@openclaw/fs-safe/dist/replace-file-copy-fallback.d.ts +4 -10
- package/node_modules/@openclaw/fs-safe/dist/replace-file-copy-fallback.js +66 -38
- package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.d.ts +7 -11
- package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.js +10 -2
- package/node_modules/@openclaw/fs-safe/dist/replace-file-destination.d.ts +21 -0
- package/node_modules/@openclaw/fs-safe/dist/replace-file-destination.js +123 -0
- package/node_modules/@openclaw/fs-safe/dist/replace-file-mutation.d.ts +26 -0
- package/node_modules/@openclaw/fs-safe/dist/replace-file-mutation.js +47 -0
- package/node_modules/@openclaw/fs-safe/dist/replace-file-temp-owner.d.ts +2 -2
- package/node_modules/@openclaw/fs-safe/dist/replace-file-temp-owner.js +16 -4
- package/node_modules/@openclaw/fs-safe/dist/replace-file-types.d.ts +55 -0
- package/node_modules/@openclaw/fs-safe/dist/replace-file-types.js +1 -0
- package/node_modules/@openclaw/fs-safe/dist/replace-file.d.ts +3 -55
- package/node_modules/@openclaw/fs-safe/dist/replace-file.js +31 -11
- package/node_modules/@openclaw/fs-safe/dist/retained-directory-replacement.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/retained-directory-replacement.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/retained-file-types.d.ts +50 -0
- package/node_modules/@openclaw/fs-safe/dist/retained-file-types.js +1 -0
- package/node_modules/@openclaw/fs-safe/dist/retained-file.d.ts +3 -0
- package/node_modules/@openclaw/fs-safe/dist/retained-file.js +121 -0
- package/node_modules/@openclaw/fs-safe/dist/root-context.js +3 -2
- package/node_modules/@openclaw/fs-safe/dist/root-directory-entry.d.ts +9 -0
- package/node_modules/@openclaw/fs-safe/dist/root-directory-entry.js +28 -0
- package/node_modules/@openclaw/fs-safe/dist/root-directory-list.d.ts +9 -1
- package/node_modules/@openclaw/fs-safe/dist/root-directory-list.js +88 -37
- package/node_modules/@openclaw/fs-safe/dist/root-file-final-admission.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/root-file-final-admission.js +1 -6
- package/node_modules/@openclaw/fs-safe/dist/root-file.js +2 -5
- package/node_modules/@openclaw/fs-safe/dist/root-handle-context.d.ts +4 -0
- package/node_modules/@openclaw/fs-safe/dist/root-handle-context.js +12 -0
- package/node_modules/@openclaw/fs-safe/dist/root-impl.d.ts +3 -3
- package/node_modules/@openclaw/fs-safe/dist/root-impl.js +8 -5
- package/node_modules/@openclaw/fs-safe/dist/root-move-noreplace.d.ts +2 -7
- package/node_modules/@openclaw/fs-safe/dist/root-move-noreplace.js +3 -3
- package/node_modules/@openclaw/fs-safe/dist/root-observed-path.d.ts +0 -1
- package/node_modules/@openclaw/fs-safe/dist/root-observed-path.js +0 -3
- package/node_modules/@openclaw/fs-safe/dist/root-path-observation.d.ts +4 -11
- package/node_modules/@openclaw/fs-safe/dist/root-path.js +7 -10
- package/node_modules/@openclaw/fs-safe/dist/root-paths.d.ts +2 -6
- package/node_modules/@openclaw/fs-safe/dist/root-remove-identity.d.ts +1 -3
- package/node_modules/@openclaw/fs-safe/dist/root-walk.d.ts +19 -12
- package/node_modules/@openclaw/fs-safe/dist/root-walk.js +56 -20
- package/node_modules/@openclaw/fs-safe/dist/root-write-admission.js +1 -6
- package/node_modules/@openclaw/fs-safe/dist/root-write-complete-parent.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/root-write-complete-parent.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/safe-path-segment.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/safe-path-segment.js +8 -2
- package/node_modules/@openclaw/fs-safe/dist/secret-file.d.ts +6 -2
- package/node_modules/@openclaw/fs-safe/dist/secret-file.js +12 -16
- package/node_modules/@openclaw/fs-safe/dist/secret-read-policy.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/secure-file-windows.js +5 -14
- package/node_modules/@openclaw/fs-safe/dist/secure-file.js +3 -2
- package/node_modules/@openclaw/fs-safe/dist/secure-temp-dir.js +2 -7
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-acquire.js +4 -4
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-admission-parser.d.ts +1 -2
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-handle.d.ts +2 -8
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-policy.d.ts +2 -7
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.d.ts +2 -2
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.js +11 -12
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-stale-admission.d.ts +1 -5
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock.js +9 -7
- package/node_modules/@openclaw/fs-safe/dist/staged-symlink-types.d.ts +39 -0
- package/node_modules/@openclaw/fs-safe/dist/staged-symlink-types.js +1 -0
- package/node_modules/@openclaw/fs-safe/dist/stat-observation.js +3 -10
- package/node_modules/@openclaw/fs-safe/dist/strict-file-identity.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/strict-file-identity.js +6 -6
- package/node_modules/@openclaw/fs-safe/dist/symlink-parents.js +58 -7
- package/node_modules/@openclaw/fs-safe/dist/temp-target.js +8 -10
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-admission.js +28 -33
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-child-admission.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-child-admission.js +16 -17
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-descriptor.js +1 -2
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-owner.js +4 -9
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-ownership.d.ts +8 -0
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-ownership.js +52 -0
- package/node_modules/@openclaw/fs-safe/dist/test-hooks.d.ts +5 -1
- package/node_modules/@openclaw/fs-safe/dist/text-atomic.d.ts +2 -1
- package/node_modules/@openclaw/fs-safe/dist/text-atomic.js +2 -0
- package/node_modules/@openclaw/fs-safe/dist/trash.js +27 -1
- package/node_modules/@openclaw/fs-safe/dist/walk.d.ts +2 -5
- package/node_modules/@openclaw/fs-safe/dist/watch-alias.d.ts +6 -0
- package/node_modules/@openclaw/fs-safe/dist/watch-alias.js +88 -0
- package/node_modules/@openclaw/fs-safe/dist/watch-hints.d.ts +9 -0
- package/node_modules/@openclaw/fs-safe/dist/watch-hints.js +93 -0
- package/node_modules/@openclaw/fs-safe/dist/watch-native.d.ts +36 -0
- package/node_modules/@openclaw/fs-safe/dist/watch-native.js +73 -0
- package/node_modules/@openclaw/fs-safe/dist/watch-scan.d.ts +28 -0
- package/node_modules/@openclaw/fs-safe/dist/watch-scan.js +300 -0
- package/node_modules/@openclaw/fs-safe/dist/watch-stream.d.ts +8 -0
- package/node_modules/@openclaw/fs-safe/dist/watch-stream.js +32 -0
- package/node_modules/@openclaw/fs-safe/dist/watch-types.d.ts +60 -0
- package/node_modules/@openclaw/fs-safe/dist/watch-types.js +1 -0
- package/node_modules/@openclaw/fs-safe/dist/watch.d.ts +5 -0
- package/node_modules/@openclaw/fs-safe/dist/watch.js +530 -0
- package/node_modules/@openclaw/fs-safe/dist/windows-owner.d.ts +3 -7
- package/node_modules/@openclaw/fs-safe/dist/windows-owner.js +0 -1
- package/node_modules/@openclaw/fs-safe/dist/windows-security-bridge.cs +6 -6
- package/node_modules/@openclaw/fs-safe/dist/windows-security-bridge.ps1 +78 -3
- package/node_modules/@openclaw/fs-safe/dist/windows-security-command.d.ts +8 -0
- package/node_modules/@openclaw/fs-safe/dist/windows-security-command.js +66 -15
- package/node_modules/@openclaw/fs-safe/dist/windows-security-facts.d.ts +4 -0
- package/node_modules/@openclaw/fs-safe/dist/windows-security-facts.js +6 -2
- package/node_modules/@openclaw/fs-safe/docs/advanced.md +4 -2
- package/node_modules/@openclaw/fs-safe/docs/archive.md +16 -0
- package/node_modules/@openclaw/fs-safe/docs/atomic.md +93 -3
- package/node_modules/@openclaw/fs-safe/docs/contributing.md +102 -4
- package/node_modules/@openclaw/fs-safe/docs/copy.md +2 -0
- package/node_modules/@openclaw/fs-safe/docs/durability.md +7 -0
- package/node_modules/@openclaw/fs-safe/docs/file-store.md +5 -0
- package/node_modules/@openclaw/fs-safe/docs/guest.md +7 -1
- package/node_modules/@openclaw/fs-safe/docs/index.md +1 -0
- package/node_modules/@openclaw/fs-safe/docs/install.md +30 -0
- package/node_modules/@openclaw/fs-safe/docs/native-helper.md +20 -4
- package/node_modules/@openclaw/fs-safe/docs/native.md +63 -1
- package/node_modules/@openclaw/fs-safe/docs/permissions.md +66 -0
- package/node_modules/@openclaw/fs-safe/docs/public-api.md +30 -3
- package/node_modules/@openclaw/fs-safe/docs/retained-file.md +115 -0
- package/node_modules/@openclaw/fs-safe/docs/root.md +35 -9
- package/node_modules/@openclaw/fs-safe/docs/secret-file.md +19 -0
- package/node_modules/@openclaw/fs-safe/docs/security-model.md +4 -1
- package/node_modules/@openclaw/fs-safe/docs/sidecar-lock.md +5 -1
- package/node_modules/@openclaw/fs-safe/docs/staged-symlink.md +124 -0
- package/node_modules/@openclaw/fs-safe/docs/store.md +3 -1
- package/node_modules/@openclaw/fs-safe/docs/temp.md +24 -4
- package/node_modules/@openclaw/fs-safe/docs/testing.md +210 -0
- package/node_modules/@openclaw/fs-safe/docs/types.md +6 -0
- package/node_modules/@openclaw/fs-safe/docs/walk.md +34 -1
- package/node_modules/@openclaw/fs-safe/docs/watch.md +251 -0
- package/node_modules/@openclaw/fs-safe/docs/writing.md +21 -0
- package/node_modules/@openclaw/fs-safe/package.json +13 -9
- package/node_modules/@openclaw/fs-safe-darwin-arm64/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-darwin-arm64/package.json +1 -1
- package/node_modules/@openclaw/fs-safe-darwin-x64/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-darwin-x64/package.json +1 -1
- package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/package.json +1 -1
- package/node_modules/@openclaw/fs-safe-linux-arm64-musl/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-linux-arm64-musl/package.json +1 -1
- package/node_modules/@openclaw/fs-safe-linux-x64-gnu/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-linux-x64-gnu/package.json +1 -1
- package/node_modules/@openclaw/fs-safe-linux-x64-musl/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-linux-x64-musl/package.json +1 -1
- package/node_modules/@openclaw/fs-safe-win32-x64-msvc/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-win32-x64-msvc/package.json +1 -1
- package/node_modules/p-limit/index.d.ts +2 -0
- package/node_modules/p-limit/index.js +17 -1
- package/node_modules/p-limit/package.json +1 -1
- package/node_modules/p-limit/readme.md +2 -0
- package/package.json +6 -6
- package/node_modules/@openclaw/fs-safe/dist/directory-mode-owner.d.ts +0 -20
- package/node_modules/@openclaw/fs-safe/dist/directory-mode-owner.js +0 -78
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
Capability-style filesystem roots for Node.js apps that handle untrusted relative paths.
|
|
12
12
|
|
|
13
|
-
Think Go's `os.Root` / `OpenInRoot` or Rust's [`cap-std`](https://github.com/bytecodealliance/cap-std), but for Node. Hand `root()` a trusted directory and you get back a handle whose every method resolves relative paths against it and defends against `..`, symlink swaps, hardlink aliases, and TOCTOU rename races. The exact containment strength is reported per mechanism: Linux
|
|
13
|
+
Think Go's `os.Root` / `OpenInRoot` or Rust's [`cap-std`](https://github.com/bytecodealliance/cap-std), but for Node. Hand `root()` a trusted directory and you get back a handle whose every method resolves relative paths against it and defends against `..`, symlink swaps, hardlink aliases, and TOCTOU rename races. The exact containment strength is reported per mechanism: Linux `openat2` opens are kernel-atomic; guarded Linux fallback, macOS, Windows, and JavaScript paths are best-effort.
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
16
|
import { root } from "@openclaw/fs-safe";
|
|
@@ -45,7 +45,7 @@ The same idea has landed in other languages. Go [added `os.Root` and `OpenInRoot
|
|
|
45
45
|
| `path.resolve().startsWith()` | string check only | – | – | – | – |
|
|
46
46
|
| [`write-file-atomic`](https://www.npmjs.com/package/write-file-atomic) | – | ✓ | – | – | – |
|
|
47
47
|
| Go [`os.Root`](https://go.dev/blog/osroot) / Rust [`cap-std`](https://github.com/bytecodealliance/cap-std) | ✓ | platform | ✓ | ✓ | – |
|
|
48
|
-
| **`@openclaw/fs-safe`** | **✓** | **✓** | **✓** | **Linux atomic; others best-effort** | **✓ (ZIP/TAR/gzip/zstd/bzip2)** |
|
|
48
|
+
| **`@openclaw/fs-safe`** | **✓** | **✓** | **✓** | **Linux openat2 atomic; others best-effort** | **✓ (ZIP/TAR/gzip/zstd/bzip2)** |
|
|
49
49
|
|
|
50
50
|
## Not a sandbox
|
|
51
51
|
|
|
@@ -84,7 +84,9 @@ reports the escape. Use `require` when hostile concurrent mutation is in scope.
|
|
|
84
84
|
|
|
85
85
|
Equivalent env var: `FS_SAFE_NATIVE_MODE=auto|off|require`. The seven bindings
|
|
86
86
|
ship as exact-version optional packages filtered by OS, CPU, and Linux libc, so
|
|
87
|
-
a normal install receives only its matching binary.
|
|
87
|
+
a normal install receives only its matching binary. Linux GNU x64/arm64 bindings
|
|
88
|
+
support [glibc 2.28 or newer](docs/install.md#supported-native-platforms), including
|
|
89
|
+
RHEL 8-family systems. There are no postinstall
|
|
88
90
|
steps, runtime downloads, or consumer Rust builds. On a platform without a
|
|
89
91
|
published binding, or when optional dependencies are omitted, `auto` silently retains lexical and canonical root
|
|
90
92
|
checks, no-follow opens, guarded temp+rename writes, and post-write identity
|
|
@@ -94,8 +96,11 @@ tradeoff, and [native architecture](docs/native.md) for the platform mechanisms
|
|
|
94
96
|
and policy ownership model.
|
|
95
97
|
|
|
96
98
|
Open results report the mechanism's containment class as `"kernel-atomic"` or
|
|
97
|
-
`"best-effort"`. Linux native `openBeneath()` is kernel-atomic
|
|
98
|
-
|
|
99
|
+
`"best-effort"`. Linux native `openBeneath()` is kernel-atomic when `openat2`
|
|
100
|
+
is available. Older kernels and syscall-filtered containers use a guarded
|
|
101
|
+
descriptor-relative walk reporting best-effort; nested no-clobber moves keep
|
|
102
|
+
atomic `renameat2(RENAME_NOREPLACE)`. macOS, Windows, and guarded JavaScript
|
|
103
|
+
results are best-effort. See [Linux compatibility](docs/native.md#linux-without-openat2). See the [security model](docs/security-model.md#containment-guarantees-by-platform) before using that fact in higher-level policy.
|
|
99
104
|
|
|
100
105
|
## Migrating from the Python helper
|
|
101
106
|
|
|
@@ -274,6 +279,7 @@ contract. Low-level helpers that OpenClaw needs to compose higher-level APIs are
|
|
|
274
279
|
| `@openclaw/fs-safe/secure-file` | fd-pinned absolute file reads with owner, mode, ACL, trusted-dir, size, and timeout checks |
|
|
275
280
|
| `@openclaw/fs-safe/file-lock` | async/sync sidecar locks, root-bounded sidecars, ownership verification, and stale policy |
|
|
276
281
|
| `@openclaw/fs-safe/permissions` | POSIX mode and Windows ACL inspection, raw owner/ACE facts, private-directory creation, and remediation helpers |
|
|
282
|
+
| [`@openclaw/fs-safe/watch`](docs/watch.md) | Guarded observation with native event hints, bounded scans, and joined close |
|
|
277
283
|
| `@openclaw/fs-safe/walk` | budget-bounded directory walking with symlink policy, filters, and truncation accounting; not root-bounded |
|
|
278
284
|
| `@openclaw/fs-safe/copy` | directory copying with `clone: "auto"`, `"always"`, or `"never"`; native APFS, Btrfs, ReFS, XFS, and ZFS cloning, portable byte copying, and clone metadata; see [directory copying](docs/copy.md) |
|
|
279
285
|
| `@openclaw/fs-safe/archive` | policy-driven ZIP/TAR extraction, clamp/filter policy, metadata/path-depth limits, gzip/zstd/bzip2 support, and bounded entry reads |
|
|
@@ -342,6 +348,11 @@ original directory on Linux/macOS and requires native support for this operation
|
|
|
342
348
|
It offers atomic replace/no-replace publication, not expected-inode replacement
|
|
343
349
|
or a crash-durability promise; application checks and coordination remain yours.
|
|
344
350
|
|
|
351
|
+
For an already staged POSIX symlink, [`retainSymlinkInDirectory()`](docs/staged-symlink.md)
|
|
352
|
+
admits caller-captured identity and retains that exact inode through no-replace
|
|
353
|
+
publication or explicit recovery. Same-target foreign replacements are not adopted.
|
|
354
|
+
Staging, cooperative locking and crash recovery remain application responsibilities.
|
|
355
|
+
|
|
345
356
|
`replaceFileAtomic()` writes a sibling temp file, applies its exact mode through the still-open descriptor, optionally fsyncs it, and renames it over the destination. It never follows the published destination path to set file permissions. Mode preservation inherits only rwx bits from an existing non-symlink regular file; special bits, ownership, ACLs, and extended attributes are not copied. Pinned-destination hardlink rejection, rename retry / copy fallback on `EPERM`, bounded original-content restoration after a torn fallback, parent-directory fsync, and a `beforeRename` hook for backup or observer flows are all opt-in. `movePathWithCopyFallback()` stages cross-device moves before commit and removes only the copied source entries, so concurrent source additions or replacements are preserved. Its optional synchronous `assertBeforeMutation` hook rechecks caller authority before renames and each source removal; `onDestinationPublished` reports an exact bigint destination identity before later checks or cleanup can fail. See [mutation authority and publication receipts](docs/atomic.md#mutation-authority-and-publication-receipts).
|
|
346
357
|
|
|
347
358
|
```ts
|
|
@@ -358,6 +369,12 @@ await replaceFileAtomic({
|
|
|
358
369
|
|
|
359
370
|
`replaceFileAtomicSync()` covers the synchronous case with the same options shape. Both accept an injectable `fileSystem` for tests. Async adapters use `chmod()` on the `FileHandle` returned by their required `open()` operation; custom sync adapters using `mode` or `preserveExistingMode` provide the optional descriptor-bound `fchmodSync` operation.
|
|
360
371
|
|
|
372
|
+
Both variants accept `assertBeforeMutation` for revocable caller authority and
|
|
373
|
+
`onDestinationState` for observed removal, partial-write, and publication facts.
|
|
374
|
+
The observer receives exact bigint identities from retained descriptors, including
|
|
375
|
+
when later completion fails. These facts do not authorize rollback; the caller
|
|
376
|
+
still owns current authority and content checks. See [atomic write authority](docs/atomic.md#atomic-write-authority-and-destination-state).
|
|
377
|
+
|
|
361
378
|
## External outputs
|
|
362
379
|
|
|
363
380
|
Use `writeExternalFileWithinRoot()` when a browser download, renderer, media
|
|
@@ -549,7 +566,8 @@ Check `scan.truncated` before treating the result as complete, and `scan.failedD
|
|
|
549
566
|
`walkDirectory()` accepts asynchronous `include` and `descend` callbacks through `AsyncWalkDirectoryOptions`, so a marker lookup can prune a directory before its children are read. Decisions remain serial and retain the options object as their `this` receiver; `walkDirectorySync()` and its options remain synchronous. See [Directory walking](docs/walk.md) for callback timing, JavaScript result compatibility, and error handling.
|
|
550
567
|
|
|
551
568
|
For caller-controlled paths, `Root.walk()` is the root-bounded async iterator.
|
|
552
|
-
It supports entry/depth budgets,
|
|
569
|
+
It supports entry/depth budgets, including links without following their targets,
|
|
570
|
+
in-root symlink following, cancellation, and a
|
|
553
571
|
truncation marker (or typed error) when a budget is reached. Its `entryFilter`
|
|
554
572
|
accepts `"include"`, `"skip"`, or `"skip-subtree"`, directly or through a Promise.
|
|
555
573
|
After an awaited decision resolves, the walk rechecks cancellation and the
|
|
@@ -8,6 +8,8 @@ export { resolvePathPrefixSync, type ResolvedPathPrefix } from "./path-prefix.js
|
|
|
8
8
|
export { probePathSuffixAliasesSync, type ProbePathSuffixAliasesOptions } from "./path-suffix-aliases.js";
|
|
9
9
|
export { readDirectoryIdentity, assertDirectoryIdentitySync, type DirectoryIdentity, } from "./directory-guard.js";
|
|
10
10
|
export { stageFileInDirectory, } from "./native-staged-file.js";
|
|
11
|
+
export { retainSymlinkInDirectory } from "./native-staged-symlink.js";
|
|
12
|
+
export type { StagedSymlink, StagedSymlinkExpected, StagedSymlinkReceipt, PublishedSymlinkReceipt, StagedSymlinkPublication, StagedSymlinkRemoval, StagedSymlinkCleanupReceipt, StagedSymlinkFailureDetails, } from "./staged-symlink-types.js";
|
|
11
13
|
export type { StagedFile, StagedFileReceipt, PublishedFileReceipt, StagedFilePublication, StagedFileCleanupReceipt, StagedFileFailureDetails, } from "./staged-file-types.js";
|
|
12
14
|
export { readFileDescriptorBounded, readFileDescriptorBoundedSync, readFileHandleBounded, } from "./bounded-read.js";
|
|
13
15
|
export { readFileWindowFully, readFileWindowFullySync, type ReadFileWindowOptions, } from "./positional-read.js";
|
|
@@ -33,4 +35,7 @@ export { resolveHomeRelativePath } from "./home-dir.js";
|
|
|
33
35
|
export { appendRegularFile, appendRegularFileSync, readRegularFile, readRegularFileSync, resolveRegularFileAppendFlags, statRegularFile, statRegularFileSync, type AppendRegularFileOptions, type RegularFileStatResult, } from "./regular-file.js";
|
|
34
36
|
export { buildRandomTempFilePath, sanitizeTempFileName, type TempFile, tempFile, withTempFile, } from "./temp-target.js";
|
|
35
37
|
export { writeSiblingTempFile, writeViaSiblingTempPath, type WriteSiblingTempFileOptions, type WriteSiblingTempFileResult, } from "./sibling-temp.js";
|
|
36
|
-
export { createIcaclsResetCommand, formatIcaclsResetCommand, formatWindowsAclSummary, inspectWindowsAcl, parseIcaclsOutput, resolveWindowsUserPrincipal, summarizeWindowsAcl, type IcaclsResetCommandOptions, type
|
|
38
|
+
export { createIcaclsResetCommand, formatIcaclsResetCommand, formatWindowsAclSummary, inspectWindowsAcl, parseIcaclsOutput, resolveWindowsUserPrincipal, summarizeWindowsAcl, type IcaclsResetCommandOptions, type PermissionExec, type WindowsAclEntry, type WindowsAclSummary, } from "./permissions-windows.js";
|
|
39
|
+
export type { PermissionCommandFailure } from "./permission-exec.js";
|
|
40
|
+
export { retainFileInDirectory } from "./retained-file.js";
|
|
41
|
+
export type { RetainedFile, RetainedFileAdmission, RetainedFileExpected, RetainedFileIssue, RetainedFileReceipt, RetainedFileResult, RetainFileInDirectoryOptions, } from "./retained-file-types.js";
|
|
@@ -11,6 +11,7 @@ export { resolvePathPrefixSync } from "./path-prefix.js";
|
|
|
11
11
|
export { probePathSuffixAliasesSync } from "./path-suffix-aliases.js";
|
|
12
12
|
export { readDirectoryIdentity, assertDirectoryIdentitySync, } from "./directory-guard.js";
|
|
13
13
|
export { stageFileInDirectory, } from "./native-staged-file.js";
|
|
14
|
+
export { retainSymlinkInDirectory } from "./native-staged-symlink.js";
|
|
14
15
|
export { readFileDescriptorBounded, readFileDescriptorBoundedSync, readFileHandleBounded, } from "./bounded-read.js";
|
|
15
16
|
export { readFileWindowFully, readFileWindowFullySync, } from "./positional-read.js";
|
|
16
17
|
export { writeFileWindowFully } from "./write-file-handle.js";
|
|
@@ -35,4 +36,5 @@ export { resolveHomeRelativePath } from "./home-dir.js";
|
|
|
35
36
|
export { appendRegularFile, appendRegularFileSync, readRegularFile, readRegularFileSync, resolveRegularFileAppendFlags, statRegularFile, statRegularFileSync, } from "./regular-file.js";
|
|
36
37
|
export { buildRandomTempFilePath, sanitizeTempFileName, tempFile, withTempFile, } from "./temp-target.js";
|
|
37
38
|
export { writeSiblingTempFile, writeViaSiblingTempPath, } from "./sibling-temp.js";
|
|
38
|
-
export { createIcaclsResetCommand, formatIcaclsResetCommand, formatWindowsAclSummary, inspectWindowsAcl, parseIcaclsOutput, resolveWindowsUserPrincipal, summarizeWindowsAcl, } from "./permissions.js";
|
|
39
|
+
export { createIcaclsResetCommand, formatIcaclsResetCommand, formatWindowsAclSummary, inspectWindowsAcl, parseIcaclsOutput, resolveWindowsUserPrincipal, summarizeWindowsAcl, } from "./permissions-windows.js";
|
|
40
|
+
export { retainFileInDirectory } from "./retained-file.js";
|
|
@@ -78,7 +78,7 @@ export async function finalizeArchivePublication(params) {
|
|
|
78
78
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
79
79
|
try {
|
|
80
80
|
await assertGuards(file.guards);
|
|
81
|
-
const opened = __addDisposableResource(env_1, await params.targetRoot.open(file.relativePath
|
|
81
|
+
const opened = __addDisposableResource(env_1, await params.targetRoot.open(`./${file.relativePath}`, { hardlinks: "reject", symlinks: "reject" })
|
|
82
82
|
.catch((error) => {
|
|
83
83
|
if (error instanceof FsSafeError && (error.code === "hardlink" || error.code === "path-alias")) {
|
|
84
84
|
throw createArchiveSymlinkTraversalError(file.relativePath);
|
|
@@ -3,7 +3,6 @@ import fs from "node:fs/promises";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { ownExtractionDestinationMutation } from "./archive-deadline.js";
|
|
5
5
|
import { assertDirectoryIdentityGuard, assertResolvedInsideDestination, createDirectoryIdentityGuard, createArchiveSymlinkTraversalError, preparePrivateArchiveOutputPath, withStagedArchiveDestination, } from "./archive-staging.js";
|
|
6
|
-
import {} from "./directory-mode-owner.js";
|
|
7
6
|
import { pinNodeDirectoryForMode } from "./directory-mode-node.js";
|
|
8
7
|
import { assertSyncDirectoryGuard, inspectDirectoryIdentitySync } from "./directory-guard.js";
|
|
9
8
|
import { FsSafeError } from "./errors.js";
|
|
@@ -251,7 +250,7 @@ async function mergeTree(params, publication, durable = true, entryUmask = 0) {
|
|
|
251
250
|
}
|
|
252
251
|
};
|
|
253
252
|
}
|
|
254
|
-
await targetRoot.copyIn(relPath
|
|
253
|
+
await targetRoot.copyIn(`./${relPath}`, sourcePath, options);
|
|
255
254
|
check();
|
|
256
255
|
await assertGuards();
|
|
257
256
|
await assertResolvedInsideDestination({
|
|
@@ -54,14 +54,9 @@ export type TarEntryInfo = {
|
|
|
54
54
|
mode?: number;
|
|
55
55
|
};
|
|
56
56
|
export declare function createTarEntryPlanner(params: ArchivePlanOptions): (entry: TarEntryInfo) => ArchivePlanEntry | null;
|
|
57
|
-
export declare function createTarEntryPreflightChecker(params: {
|
|
57
|
+
export declare function createTarEntryPreflightChecker(params: Omit<ArchivePlanOptions & {
|
|
58
58
|
rootDir: string;
|
|
59
|
-
|
|
60
|
-
limits?: ArchiveExtractLimits;
|
|
61
|
-
escapeLabel?: string;
|
|
62
|
-
entryFilter?: ArchiveEntryFilter;
|
|
63
|
-
onFiltered?: ArchiveFilteredEntryPolicy;
|
|
64
|
-
}): (entry: TarEntryInfo) => boolean;
|
|
59
|
+
}, "entryModes">): (entry: TarEntryInfo) => boolean;
|
|
65
60
|
export type ArchiveLogger = {
|
|
66
61
|
info?: (message: string) => void;
|
|
67
62
|
warn?: (message: string) => void;
|
|
@@ -11,9 +11,8 @@ import { resolveArchiveKind } from "./archive-kind.js";
|
|
|
11
11
|
import { DEFAULT_MAX_ARCHIVE_BYTES_ZIP, ArchiveLimitError, ARCHIVE_LIMIT_ERROR_CODE, } from "./archive-limits.js";
|
|
12
12
|
import { isGzipBuffer } from "./archive-gzip-tail.js";
|
|
13
13
|
import { inspectTar, replayTar } from "./archive-tar-stream.js";
|
|
14
|
-
import { loadAdmittedZipArchive } from "./archive-zip-loader.js";
|
|
14
|
+
import { loadAdmittedZipArchive, assertZipEntryBinding } from "./archive-zip-loader.js";
|
|
15
15
|
import { createZipIntegrityTransform, normalizeZipIntegrityError, } from "./archive-zip-integrity.js";
|
|
16
|
-
import { isZipSymlinkEntry, zipEntryKind } from "./archive-zip-entry.js";
|
|
17
16
|
import { FsSafeError } from "./errors.js";
|
|
18
17
|
import { inspectFileIdentity } from "./strict-file-identity.js";
|
|
19
18
|
import { resolveReadOpenFlags } from "./read-open-flags.js";
|
|
@@ -93,27 +92,19 @@ async function readArchiveInput(archivePath) {
|
|
|
93
92
|
}
|
|
94
93
|
}
|
|
95
94
|
async function readZipEntry(buffer, entryPath, maxBytes, admitted) {
|
|
96
|
-
const archive = await loadAdmittedZipArchive(buffer, admitted);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
// effective entries once, after raw ZIP admission has rejected collisions.
|
|
100
|
-
for (const candidate of Object.values(archive.files)) {
|
|
101
|
-
if (canonicalEntryPath(candidate.name) !== entryPath)
|
|
102
|
-
continue;
|
|
103
|
-
if (entry) {
|
|
104
|
-
throw new ArchiveSecurityError("entry-path", `archive contains duplicate entry path: ${formatErrorDetail(entryPath)}`);
|
|
105
|
-
}
|
|
106
|
-
entry = candidate;
|
|
107
|
-
}
|
|
108
|
-
if (!entry || entry.dir) {
|
|
95
|
+
const { archive, entries } = await loadAdmittedZipArchive(buffer, admitted);
|
|
96
|
+
const record = entries.get(entryPath);
|
|
97
|
+
if (!record || record.entry.dir) {
|
|
109
98
|
throw new Error(`archive entry not found: ${formatErrorDetail(entryPath)}`);
|
|
110
99
|
}
|
|
111
|
-
|
|
100
|
+
assertZipEntryBinding(archive, record, entryPath);
|
|
101
|
+
const { entry, kind } = record;
|
|
102
|
+
if (kind === "symlink") {
|
|
112
103
|
throw new Error(`archive entry is a link: ${formatErrorDetail(entryPath)}`);
|
|
113
104
|
}
|
|
114
|
-
if (
|
|
105
|
+
if (kind !== "file")
|
|
115
106
|
throw new Error(`archive entry is not a file: ${formatErrorDetail(entryPath)}`);
|
|
116
|
-
const integrity = createZipIntegrityTransform(
|
|
107
|
+
const integrity = createZipIntegrityTransform(record);
|
|
117
108
|
const stream = typeof entry.nodeStream === "function"
|
|
118
109
|
? entry.nodeStream()
|
|
119
110
|
: Readable.from(await entry.async("nodebuffer"));
|
|
@@ -3,7 +3,6 @@ import { type AsyncDirectoryGuard } from "./directory-guard.js";
|
|
|
3
3
|
import { type ExtractionDeadline } from "./archive-deadline.js";
|
|
4
4
|
import { ArchiveSecurityError } from "./archive-errors.js";
|
|
5
5
|
export type ArchiveDirectoryGuard = AsyncDirectoryGuard<BigIntStats>;
|
|
6
|
-
export { ArchiveSecurityError, type ArchiveSecurityErrorCode } from "./archive-errors.js";
|
|
7
6
|
export declare function createDirectoryIdentityGuard(dir: string): Promise<ArchiveDirectoryGuard>;
|
|
8
7
|
export declare function assertDirectoryIdentityGuard(guard: ArchiveDirectoryGuard): Promise<void>;
|
|
9
8
|
export declare function prepareArchiveDestinationGuard(destDir: string): Promise<ArchiveDirectoryGuard>;
|
|
@@ -29,5 +28,5 @@ export declare function withStagedArchiveDestination<T>(params: {
|
|
|
29
28
|
stagingDirPrefix?: string;
|
|
30
29
|
run: (stagingDir: string) => Promise<T>;
|
|
31
30
|
}): Promise<T>;
|
|
32
|
-
export { mergeExtractedTreeIntoDestination } from "./archive-merge.js";
|
|
33
31
|
export declare function createArchiveSymlinkTraversalError(originalPath: string): ArchiveSecurityError;
|
|
32
|
+
export {};
|
|
@@ -21,7 +21,6 @@ const ARCHIVE_STAGING_MODE = 0o700;
|
|
|
21
21
|
function checkExtractionDeadline(deadline) {
|
|
22
22
|
deadline?.check();
|
|
23
23
|
}
|
|
24
|
-
export { ArchiveSecurityError } from "./archive-errors.js";
|
|
25
24
|
function symlinkTraversalError(originalPath) {
|
|
26
25
|
return new ArchiveSecurityError("destination-symlink-traversal", `${ERROR_ARCHIVE_ENTRY_TRAVERSES_SYMLINK}: ${formatErrorDetail(originalPath)}`);
|
|
27
26
|
}
|
|
@@ -134,7 +133,9 @@ export async function assertResolvedInsideDestination(params) {
|
|
|
134
133
|
}
|
|
135
134
|
async function mkdirArchiveOutput(params) {
|
|
136
135
|
try {
|
|
137
|
-
|
|
136
|
+
const relativePath = params.relativePath;
|
|
137
|
+
// Archive names are literal; retain Root.mkdir's admission without home expansion.
|
|
138
|
+
await params.targetRoot.mkdir(relativePath === "~" || relativePath.startsWith("~/") ? `./${relativePath}` : relativePath);
|
|
138
139
|
}
|
|
139
140
|
catch (error) {
|
|
140
141
|
if (error instanceof FsSafeError) {
|
|
@@ -302,7 +303,6 @@ export async function withStagedArchiveDestination(params) {
|
|
|
302
303
|
}
|
|
303
304
|
}
|
|
304
305
|
}
|
|
305
|
-
export { mergeExtractedTreeIntoDestination } from "./archive-merge.js";
|
|
306
306
|
export function createArchiveSymlinkTraversalError(originalPath) {
|
|
307
307
|
return symlinkTraversalError(originalPath);
|
|
308
308
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assertArchiveEntryCountWithinLimit, } from "./archive-limits.js";
|
|
2
2
|
import { admitZipNames, zipExtraFields, zipFormat, zipUInt64 } from "./archive-zip-names.js";
|
|
3
|
+
import { createArchiveOutputPathTracker } from "./archive-entry.js";
|
|
3
4
|
function entryKind(attributes, directory) {
|
|
4
5
|
const type = (attributes >>> 16) & 0o170000;
|
|
5
6
|
// High-word symlinks remain links regardless of the creator or directory bits.
|
|
@@ -186,6 +187,7 @@ export function* scanZipDirectory(size, limits, onEntry) {
|
|
|
186
187
|
const directory = yield* layout(size);
|
|
187
188
|
assertArchiveEntryCountWithinLimit(directory.count, limits);
|
|
188
189
|
const seen = new Set();
|
|
190
|
+
const trackKnownPath = createArchiveOutputPathTracker();
|
|
189
191
|
const spans = [];
|
|
190
192
|
let at = directory.start;
|
|
191
193
|
let count = 0;
|
|
@@ -226,6 +228,8 @@ export function* scanZipDirectory(size, limits, onEntry) {
|
|
|
226
228
|
const localNames = yield* read(localAt + 30, localNameLength + localExtraLength, directory.start);
|
|
227
229
|
const localExtra = zipExtraFields(localNames.subarray(localNameLength));
|
|
228
230
|
const admittedName = admitZipNames({ central: centralName, local: localNames.subarray(0, localNameLength), flags, centralExtra, localExtra, seen });
|
|
231
|
+
if (admittedName.path !== undefined)
|
|
232
|
+
trackKnownPath(admittedName.path, admittedName.path);
|
|
229
233
|
const localValues = wideValues(local, localExtra, false);
|
|
230
234
|
const crc = central.readUInt32LE(16);
|
|
231
235
|
if (!(flags & 8) && (local.readUInt32LE(14) !== crc || localValues.compressed !== values.compressed || localValues.uncompressed !== values.uncompressed)) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ArchiveEntryKind } from "./archive-plan.js";
|
|
2
2
|
import type { ZipDirectoryEntry } from "./archive-zip-directory.js";
|
|
3
3
|
export type ZipEntry = {
|
|
4
4
|
name: string;
|
|
@@ -12,13 +12,13 @@ export type ZipEntry = {
|
|
|
12
12
|
nodeStream?: () => NodeJS.ReadableStream;
|
|
13
13
|
async: (type: "nodebuffer") => Promise<Buffer>;
|
|
14
14
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export declare function
|
|
15
|
+
export type AdmittedZipEntry = Readonly<{
|
|
16
|
+
entry: ZipEntry;
|
|
17
|
+
name: string;
|
|
18
|
+
kind: ArchiveEntryKind;
|
|
19
|
+
mode: number | undefined;
|
|
20
|
+
size: number;
|
|
21
|
+
crc32: number;
|
|
22
|
+
}>;
|
|
23
|
+
/** Internal: create only after the complete decoder/admission association. */
|
|
24
|
+
export declare function createAdmittedZipEntry(entry: ZipEntry, name: string, physical: ZipDirectoryEntry): AdmittedZipEntry;
|
|
@@ -1,42 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/** Internal: register only after the complete decoder/admission association. */
|
|
4
|
-
export function registerAdmittedZipEntry(entry, physical) {
|
|
1
|
+
/** Internal: create only after the complete decoder/admission association. */
|
|
2
|
+
export function createAdmittedZipEntry(entry, name, physical) {
|
|
5
3
|
const mode = physical.creatorSystem === 3 ? physical.externalAttributes >>> 16 : undefined;
|
|
6
|
-
admittedMetadata.set(entry, { kind: physical.kind, mode, size: physical.size });
|
|
7
4
|
entry.dir = physical.kind === "directory";
|
|
8
5
|
// Previously unsupported non-UNIX symlinks must also be recognizable to
|
|
9
6
|
// public preflight consumers using JSZip's conventional type inspection.
|
|
10
7
|
entry.unixPermissions = mode ?? (physical.kind === "symlink" ? 0o120000 : null);
|
|
11
8
|
entry.dosPermissions = physical.creatorSystem === 0 ? physical.externalAttributes & 0x3f : null;
|
|
12
|
-
}
|
|
13
|
-
export function zipEntryIntegrityMetadata(entry) {
|
|
14
|
-
const data = entry._data;
|
|
15
|
-
if (!data || "then" in data)
|
|
16
|
-
return undefined;
|
|
17
|
-
return data;
|
|
18
|
-
}
|
|
19
|
-
const ZIP_UNIX_FILE_TYPE_MASK = 0o170000;
|
|
20
|
-
const ZIP_UNIX_SYMLINK_TYPE = 0o120000;
|
|
21
|
-
export function isZipSymlinkEntry(entry) {
|
|
22
|
-
return zipEntryKind(entry) === "symlink";
|
|
23
|
-
}
|
|
24
|
-
export function zipEntryKind(entry) {
|
|
25
|
-
const metadata = admittedMetadata.get(entry);
|
|
26
|
-
if (metadata)
|
|
27
|
-
return metadata.kind;
|
|
28
|
-
return typeof entry.unixPermissions === "number" &&
|
|
29
|
-
(entry.unixPermissions & ZIP_UNIX_FILE_TYPE_MASK) === ZIP_UNIX_SYMLINK_TYPE
|
|
30
|
-
? "symlink" : entry.dir ? "directory" : "file";
|
|
31
|
-
}
|
|
32
|
-
export function zipEntryMode(entry, policy) {
|
|
33
|
-
const metadata = admittedMetadata.get(entry);
|
|
34
|
-
return resolveArchiveEntryMode({
|
|
35
|
-
kind: entry.dir ? "directory" : "file",
|
|
36
|
-
archivedMode: metadata ? metadata.mode : entry.unixPermissions,
|
|
37
|
-
policy,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
export function zipEntryDeclaredSize(entry) {
|
|
41
|
-
return admittedMetadata.get(entry)?.size ?? Math.max(0, Math.floor(zipEntryIntegrityMetadata(entry)?.uncompressedSize ?? 0));
|
|
9
|
+
return { entry, name, kind: physical.kind, mode, size: physical.size, crc32: physical.crc32 };
|
|
42
10
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Transform } from "node:stream";
|
|
2
|
-
import {
|
|
2
|
+
import type { AdmittedZipEntry } from "./archive-zip-entry.js";
|
|
3
3
|
export declare function normalizeZipIntegrityError(error: unknown): Error;
|
|
4
|
-
export declare function createZipIntegrityTransform(
|
|
4
|
+
export declare function createZipIntegrityTransform(record: AdmittedZipEntry): Transform;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Transform } from "node:stream";
|
|
2
2
|
import { ArchiveFormatError } from "./archive-errors.js";
|
|
3
|
-
import { zipEntryIntegrityMetadata, } from "./archive-zip-entry.js";
|
|
4
3
|
import { updateCrc32 } from "./archive-crc32.js";
|
|
5
4
|
export function normalizeZipIntegrityError(error) {
|
|
6
5
|
if (error instanceof Error &&
|
|
@@ -9,17 +8,8 @@ export function normalizeZipIntegrityError(error) {
|
|
|
9
8
|
}
|
|
10
9
|
return error instanceof Error ? error : new Error(String(error));
|
|
11
10
|
}
|
|
12
|
-
export function createZipIntegrityTransform(
|
|
13
|
-
const
|
|
14
|
-
const expectedCrc32 = metadata?.crc32;
|
|
15
|
-
const expectedSize = metadata?.uncompressedSize;
|
|
16
|
-
if (typeof expectedCrc32 !== "number" ||
|
|
17
|
-
!Number.isInteger(expectedCrc32) ||
|
|
18
|
-
typeof expectedSize !== "number" ||
|
|
19
|
-
!Number.isSafeInteger(expectedSize) ||
|
|
20
|
-
expectedSize < 0) {
|
|
21
|
-
throw new ArchiveFormatError(`zip entry has invalid integrity metadata: ${entry.name}`);
|
|
22
|
-
}
|
|
11
|
+
export function createZipIntegrityTransform(record) {
|
|
12
|
+
const { entry, crc32: expectedCrc32, size: expectedSize } = record;
|
|
23
13
|
let actualCrc32 = 0;
|
|
24
14
|
let actualSize = 0;
|
|
25
15
|
return new Transform({
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { ZipDirectoryEntry } from "./archive-zip-directory.js";
|
|
2
|
-
import { type
|
|
2
|
+
import { type AdmittedZipEntry } from "./archive-zip-entry.js";
|
|
3
3
|
export type ZipArchiveWithFiles = {
|
|
4
4
|
files: Record<string, unknown>;
|
|
5
5
|
};
|
|
6
|
-
export
|
|
6
|
+
export type ZipArchiveAdmission = {
|
|
7
|
+
archive: ZipArchiveWithFiles;
|
|
8
|
+
entries: ReadonlyMap<string, AdmittedZipEntry>;
|
|
9
|
+
};
|
|
10
|
+
export declare function assertZipEntryBinding(archive: ZipArchiveWithFiles, record: AdmittedZipEntry, path: string): void;
|
|
7
11
|
/** Internal: the caller has admitted these unchanged bytes and their metadata. */
|
|
8
|
-
export declare function loadAdmittedZipArchive(buffer: Buffer | Uint8Array, admitted: ZipDirectoryEntry[]): Promise<
|
|
12
|
+
export declare function loadAdmittedZipArchive(buffer: Buffer | Uint8Array, admitted: ZipDirectoryEntry[]): Promise<ZipArchiveAdmission>;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { ArchiveFormatError, ArchiveSecurityError } from "./archive-errors.js";
|
|
2
|
-
import { validateArchiveEntryPath } from "./archive-entry.js";
|
|
3
|
-
import {
|
|
2
|
+
import { createArchiveOutputPathTracker, validateArchiveEntryPath } from "./archive-entry.js";
|
|
3
|
+
import { createAdmittedZipEntry } from "./archive-zip-entry.js";
|
|
4
4
|
import { zipPathKey } from "./archive-zip-names.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export function assertZipEntryBinding(archive, record, path) {
|
|
6
|
+
const { entry } = record;
|
|
7
|
+
const name = entry.name;
|
|
8
|
+
validateArchiveEntryPath(name, { escapeLabel: "archive root" });
|
|
9
|
+
if (archive.files[record.name] !== entry || zipPathKey(name) !== path)
|
|
10
|
+
disagreement();
|
|
8
11
|
}
|
|
9
12
|
function disagreement() {
|
|
10
13
|
throw new ArchiveFormatError("ZIP decoder disagrees with admitted directory metadata");
|
|
@@ -24,7 +27,9 @@ function matchesData(value, physical) {
|
|
|
24
27
|
/** Internal: the caller has admitted these unchanged bytes and their metadata. */
|
|
25
28
|
export async function loadAdmittedZipArchive(buffer, admitted) {
|
|
26
29
|
const physicalByPath = new Map();
|
|
30
|
+
const trackOutputPath = createArchiveOutputPathTracker();
|
|
27
31
|
for (const entry of admitted) {
|
|
32
|
+
trackOutputPath(entry.portableKey, entry.portableKey);
|
|
28
33
|
if (physicalByPath.has(entry.portableKey))
|
|
29
34
|
collision();
|
|
30
35
|
physicalByPath.set(entry.portableKey, entry);
|
|
@@ -110,7 +115,7 @@ export async function loadAdmittedZipArchive(buffer, admitted) {
|
|
|
110
115
|
if (remaining.size || inserted.size)
|
|
111
116
|
disagreement();
|
|
112
117
|
const files = Object.create(null);
|
|
113
|
-
const entries =
|
|
118
|
+
const entries = new Map();
|
|
114
119
|
for (const [name, entry, physical] of normalized) {
|
|
115
120
|
const appendSlash = physical.kind === "directory" && !name.endsWith("/");
|
|
116
121
|
const normalizedName = appendSlash ? `${name}/` : name;
|
|
@@ -120,12 +125,10 @@ export async function loadAdmittedZipArchive(buffer, admitted) {
|
|
|
120
125
|
entry.name = `${entry.name}/`;
|
|
121
126
|
}
|
|
122
127
|
files[normalizedName] = entry;
|
|
123
|
-
|
|
124
|
-
entries.push(entry);
|
|
128
|
+
entries.set(physical.portableKey, createAdmittedZipEntry(entry, normalizedName, physical));
|
|
125
129
|
}
|
|
126
130
|
archive.files = files;
|
|
127
|
-
|
|
128
|
-
return archive;
|
|
131
|
+
return { archive, entries };
|
|
129
132
|
}
|
|
130
133
|
async function importOptionalJsZip() {
|
|
131
134
|
try {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ArchiveFormatError, ArchiveSecurityError } from "./archive-errors.js";
|
|
2
|
-
import { stripArchivePath } from "./archive-entry.js";
|
|
2
|
+
import { createArchiveOutputPathTracker, stripArchivePath } from "./archive-entry.js";
|
|
3
3
|
/** Associate all native entries with physical admission before exposing any. */
|
|
4
4
|
export function validateNativeZipManifest(manifest, admitted) {
|
|
5
5
|
if (manifest.length !== admitted.length) {
|
|
6
6
|
throw new ArchiveSecurityError("entry-path", "zip decoder collapsed entry names");
|
|
7
7
|
}
|
|
8
|
+
const trackOutputPath = createArchiveOutputPathTracker();
|
|
8
9
|
for (const [ordinal, entry] of manifest.entries()) {
|
|
9
10
|
const physical = admitted[ordinal];
|
|
10
11
|
const physicalPath = physical?.path;
|
|
@@ -18,5 +19,6 @@ export function validateNativeZipManifest(manifest, admitted) {
|
|
|
18
19
|
(physical.creatorSystem === 3 && entry.mode !== physical.externalAttributes >>> 16)) {
|
|
19
20
|
throw new ArchiveFormatError("ZIP decoder disagrees with admitted directory metadata");
|
|
20
21
|
}
|
|
22
|
+
trackOutputPath(entry.path, entry.path);
|
|
21
23
|
}
|
|
22
24
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type ArchiveExtractLimits } from "./archive-limits.js";
|
|
2
|
-
import { type ZipArchiveWithFiles } from "./archive-zip-loader.js";
|
|
3
|
-
export
|
|
4
|
-
export type { ZipArchiveWithFiles } from "./archive-zip-loader.js";
|
|
2
|
+
import { type ZipArchiveAdmission, type ZipArchiveWithFiles } from "./archive-zip-loader.js";
|
|
3
|
+
export declare function loadZipArchiveWithAdmission(buffer: Buffer | Uint8Array, limits?: ArchiveExtractLimits): Promise<ZipArchiveAdmission>;
|
|
5
4
|
export declare function loadZipArchiveWithPreflight(buffer: Buffer | Uint8Array, limits?: ArchiveExtractLimits): Promise<ZipArchiveWithFiles>;
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import { ARCHIVE_LIMIT_ERROR_CODE, ArchiveLimitError, resolveExtractLimits, } from "./archive-limits.js";
|
|
2
2
|
import { admitZipBuffer } from "./archive-zip-admission.js";
|
|
3
3
|
import { loadAdmittedZipArchive } from "./archive-zip-loader.js";
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
export function loadZipArchiveWithAdmission(buffer, limits) {
|
|
5
|
+
try {
|
|
6
|
+
const resolvedLimits = resolveExtractLimits(limits);
|
|
7
|
+
if (buffer.byteLength > resolvedLimits.maxArchiveBytes) {
|
|
8
|
+
throw new ArchiveLimitError(ARCHIVE_LIMIT_ERROR_CODE.ARCHIVE_SIZE_EXCEEDS_LIMIT);
|
|
9
|
+
}
|
|
10
|
+
const entries = [];
|
|
11
|
+
admitZipBuffer(buffer, resolvedLimits, entry => { entries.push(entry); });
|
|
12
|
+
return loadAdmittedZipArchive(buffer, entries);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
// Keep validation failures in the promise handed to the extraction deadline.
|
|
16
|
+
return Promise.reject(error);
|
|
9
17
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return await
|
|
18
|
+
}
|
|
19
|
+
export async function loadZipArchiveWithPreflight(buffer, limits) {
|
|
20
|
+
return (await loadZipArchiveWithAdmission(buffer, limits)).archive;
|
|
13
21
|
}
|
|
@@ -6,10 +6,13 @@ export { resolveArchiveKind, resolvePackedRootDir, type ArchiveKind } from "./ar
|
|
|
6
6
|
export { readArchiveEntry } from "./archive-read.js";
|
|
7
7
|
export { ARCHIVE_LIMIT_ERROR_CODE, ArchiveLimitError, DEFAULT_MAX_ARCHIVE_BYTES_ZIP, DEFAULT_MAX_ENTRIES, DEFAULT_MAX_EXTRACTED_BYTES, DEFAULT_MAX_ENTRY_BYTES, DEFAULT_MAX_META_ENTRY_BYTES, DEFAULT_MAX_ENTRY_PATH_COMPONENTS, type ArchiveExtractLimits, type ArchiveLimitErrorCode, } from "./archive-limits.js";
|
|
8
8
|
export { ArchiveFormatError, type ArchiveFormatErrorCode } from "./archive-errors.js";
|
|
9
|
-
export { ArchiveSecurityError, type ArchiveSecurityErrorCode } from "./archive-
|
|
10
|
-
export { createArchiveSymlinkTraversalError,
|
|
9
|
+
export { ArchiveSecurityError, type ArchiveSecurityErrorCode } from "./archive-errors.js";
|
|
10
|
+
export { createArchiveSymlinkTraversalError, prepareArchiveDestinationDir, prepareArchiveOutputPath, withStagedArchiveDestination, } from "./archive-staging.js";
|
|
11
|
+
export { mergeExtractedTreeIntoDestination } from "./archive-merge.js";
|
|
11
12
|
export { createTarEntryPreflightChecker, type TarEntryInfo } from "./archive-plan.js";
|
|
12
|
-
export { loadZipArchiveWithPreflight
|
|
13
|
+
export { loadZipArchiveWithPreflight } from "./archive-zip-preflight.js";
|
|
14
|
+
export { readZipCentralDirectoryEntryCount } from "./archive-zip-count.js";
|
|
15
|
+
export type { ZipArchiveWithFiles } from "./archive-zip-loader.js";
|
|
13
16
|
export declare function extractArchive(params: ExtractArchiveOptions): Promise<void>;
|
|
14
17
|
export type InspectTarArchiveOptions = Pick<ExtractArchiveOptions, "archivePath" | "timeoutMs" | "limits" | "entryFilter" | "onFiltered">;
|
|
15
18
|
export type InspectedTarEntry = Readonly<Pick<ArchivePlanEntry, "path" | "kind" | "size">>;
|