@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.
Files changed (244) hide show
  1. package/assets/icon.png +0 -0
  2. package/dist/index.js +75 -229
  3. package/node_modules/@openclaw/fs-safe/CHANGELOG.md +102 -0
  4. package/node_modules/@openclaw/fs-safe/README.md +24 -6
  5. package/node_modules/@openclaw/fs-safe/dist/advanced.d.ts +6 -1
  6. package/node_modules/@openclaw/fs-safe/dist/advanced.js +3 -1
  7. package/node_modules/@openclaw/fs-safe/dist/archive-durability.js +1 -1
  8. package/node_modules/@openclaw/fs-safe/dist/archive-merge.js +1 -2
  9. package/node_modules/@openclaw/fs-safe/dist/archive-plan.d.ts +2 -7
  10. package/node_modules/@openclaw/fs-safe/dist/archive-read.js +9 -18
  11. package/node_modules/@openclaw/fs-safe/dist/archive-staging.d.ts +1 -2
  12. package/node_modules/@openclaw/fs-safe/dist/archive-staging.js +3 -3
  13. package/node_modules/@openclaw/fs-safe/dist/archive-zip-directory.js +4 -0
  14. package/node_modules/@openclaw/fs-safe/dist/archive-zip-entry.d.ts +11 -11
  15. package/node_modules/@openclaw/fs-safe/dist/archive-zip-entry.js +3 -35
  16. package/node_modules/@openclaw/fs-safe/dist/archive-zip-integrity.d.ts +2 -2
  17. package/node_modules/@openclaw/fs-safe/dist/archive-zip-integrity.js +2 -12
  18. package/node_modules/@openclaw/fs-safe/dist/archive-zip-loader.d.ts +7 -3
  19. package/node_modules/@openclaw/fs-safe/dist/archive-zip-loader.js +13 -10
  20. package/node_modules/@openclaw/fs-safe/dist/archive-zip-manifest.js +3 -1
  21. package/node_modules/@openclaw/fs-safe/dist/archive-zip-preflight.d.ts +2 -3
  22. package/node_modules/@openclaw/fs-safe/dist/archive-zip-preflight.js +16 -8
  23. package/node_modules/@openclaw/fs-safe/dist/archive.d.ts +6 -3
  24. package/node_modules/@openclaw/fs-safe/dist/archive.js +22 -19
  25. package/node_modules/@openclaw/fs-safe/dist/atomic.d.ts +1 -1
  26. package/node_modules/@openclaw/fs-safe/dist/copy-publication.d.ts +1 -3
  27. package/node_modules/@openclaw/fs-safe/dist/copy-publication.js +2 -6
  28. package/node_modules/@openclaw/fs-safe/dist/deny-mutation-match.d.ts +2 -0
  29. package/node_modules/@openclaw/fs-safe/dist/deny-mutation-match.js +71 -0
  30. package/node_modules/@openclaw/fs-safe/dist/deny-mutations.js +4 -3
  31. package/node_modules/@openclaw/fs-safe/dist/directory-guard.d.ts +0 -1
  32. package/node_modules/@openclaw/fs-safe/dist/directory-guard.js +0 -3
  33. package/node_modules/@openclaw/fs-safe/dist/directory-mode-node.d.ts +20 -2
  34. package/node_modules/@openclaw/fs-safe/dist/directory-mode-node.js +77 -1
  35. package/node_modules/@openclaw/fs-safe/dist/directory-receipt.js +5 -7
  36. package/node_modules/@openclaw/fs-safe/dist/effective-uid.js +1 -4
  37. package/node_modules/@openclaw/fs-safe/dist/errors.d.ts +3 -1
  38. package/node_modules/@openclaw/fs-safe/dist/errors.js +3 -2
  39. package/node_modules/@openclaw/fs-safe/dist/file-identity.js +10 -2
  40. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-acquisition.js +1 -1
  41. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-admission.js +5 -1
  42. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-held.d.ts +4 -11
  43. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-held.js +1 -4
  44. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-io.d.ts +3 -6
  45. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-io.js +1 -1
  46. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-options.d.ts +2 -10
  47. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root.d.ts +2 -4
  48. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync.js +2 -2
  49. package/node_modules/@openclaw/fs-safe/dist/file-store-boundary.d.ts +3 -7
  50. package/node_modules/@openclaw/fs-safe/dist/file-store-boundary.js +7 -10
  51. package/node_modules/@openclaw/fs-safe/dist/file-store-prune.js +7 -6
  52. package/node_modules/@openclaw/fs-safe/dist/file-store.d.ts +4 -7
  53. package/node_modules/@openclaw/fs-safe/dist/file-store.js +19 -21
  54. package/node_modules/@openclaw/fs-safe/dist/guest-native-python.js +23 -31
  55. package/node_modules/@openclaw/fs-safe/dist/guest.js +21 -12
  56. package/node_modules/@openclaw/fs-safe/dist/json-document-store.d.ts +4 -9
  57. package/node_modules/@openclaw/fs-safe/dist/json-durable-queue-ownership.d.ts +1 -5
  58. package/node_modules/@openclaw/fs-safe/dist/json-durable-queue.d.ts +0 -1
  59. package/node_modules/@openclaw/fs-safe/dist/json-durable-queue.js +2 -7
  60. package/node_modules/@openclaw/fs-safe/dist/local-file-access.js +2 -5
  61. package/node_modules/@openclaw/fs-safe/dist/local-file-descriptor.d.ts +2 -5
  62. package/node_modules/@openclaw/fs-safe/dist/local-roots.d.ts +2 -7
  63. package/node_modules/@openclaw/fs-safe/dist/move-path-cleanup.js +4 -4
  64. package/node_modules/@openclaw/fs-safe/dist/mutation-authority.js +5 -0
  65. package/node_modules/@openclaw/fs-safe/dist/native-binding.d.ts +51 -14
  66. package/node_modules/@openclaw/fs-safe/dist/native-pinned-write.js +8 -2
  67. package/node_modules/@openclaw/fs-safe/dist/native-staged-symlink.d.ts +13 -0
  68. package/node_modules/@openclaw/fs-safe/dist/native-staged-symlink.js +303 -0
  69. package/node_modules/@openclaw/fs-safe/dist/owner-dacl-batch-worker.d.ts +1 -0
  70. package/node_modules/@openclaw/fs-safe/dist/owner-dacl-batch-worker.js +54 -0
  71. package/node_modules/@openclaw/fs-safe/dist/owner-dacl-batch.d.ts +5 -0
  72. package/node_modules/@openclaw/fs-safe/dist/owner-dacl-batch.js +64 -0
  73. package/node_modules/@openclaw/fs-safe/dist/owner-dacl.d.ts +2 -0
  74. package/node_modules/@openclaw/fs-safe/dist/owner-dacl.js +3 -0
  75. package/node_modules/@openclaw/fs-safe/dist/path.js +17 -1
  76. package/node_modules/@openclaw/fs-safe/dist/permission-exec.d.ts +6 -0
  77. package/node_modules/@openclaw/fs-safe/dist/permission-exec.js +3 -6
  78. package/node_modules/@openclaw/fs-safe/dist/permissions-public.d.ts +3 -1
  79. package/node_modules/@openclaw/fs-safe/dist/permissions-public.js +1 -0
  80. package/node_modules/@openclaw/fs-safe/dist/permissions-windows.d.ts +3 -6
  81. package/node_modules/@openclaw/fs-safe/dist/permissions.d.ts +3 -10
  82. package/node_modules/@openclaw/fs-safe/dist/permissions.js +0 -1
  83. package/node_modules/@openclaw/fs-safe/dist/pinned-mutation-admission.d.ts +0 -1
  84. package/node_modules/@openclaw/fs-safe/dist/pinned-mutation-admission.js +4 -2
  85. package/node_modules/@openclaw/fs-safe/dist/pinned-mutation-shared-route.d.ts +2 -8
  86. package/node_modules/@openclaw/fs-safe/dist/pinned-open.d.ts +1 -1
  87. package/node_modules/@openclaw/fs-safe/dist/pinned-open.js +2 -3
  88. package/node_modules/@openclaw/fs-safe/dist/publish-copy-stage.js +4 -0
  89. package/node_modules/@openclaw/fs-safe/dist/read-opened-file.d.ts +2 -5
  90. package/node_modules/@openclaw/fs-safe/dist/regular-file.js +3 -3
  91. package/node_modules/@openclaw/fs-safe/dist/replace-directory.js +5 -17
  92. package/node_modules/@openclaw/fs-safe/dist/replace-file-buffer.d.ts +4 -0
  93. package/node_modules/@openclaw/fs-safe/dist/replace-file-buffer.js +36 -0
  94. package/node_modules/@openclaw/fs-safe/dist/replace-file-copy-fallback.d.ts +4 -10
  95. package/node_modules/@openclaw/fs-safe/dist/replace-file-copy-fallback.js +66 -38
  96. package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.d.ts +7 -11
  97. package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.js +10 -2
  98. package/node_modules/@openclaw/fs-safe/dist/replace-file-destination.d.ts +21 -0
  99. package/node_modules/@openclaw/fs-safe/dist/replace-file-destination.js +123 -0
  100. package/node_modules/@openclaw/fs-safe/dist/replace-file-mutation.d.ts +26 -0
  101. package/node_modules/@openclaw/fs-safe/dist/replace-file-mutation.js +47 -0
  102. package/node_modules/@openclaw/fs-safe/dist/replace-file-temp-owner.d.ts +2 -2
  103. package/node_modules/@openclaw/fs-safe/dist/replace-file-temp-owner.js +16 -4
  104. package/node_modules/@openclaw/fs-safe/dist/replace-file-types.d.ts +55 -0
  105. package/node_modules/@openclaw/fs-safe/dist/replace-file-types.js +1 -0
  106. package/node_modules/@openclaw/fs-safe/dist/replace-file.d.ts +3 -55
  107. package/node_modules/@openclaw/fs-safe/dist/replace-file.js +31 -11
  108. package/node_modules/@openclaw/fs-safe/dist/retained-directory-replacement.d.ts +1 -0
  109. package/node_modules/@openclaw/fs-safe/dist/retained-directory-replacement.js +1 -1
  110. package/node_modules/@openclaw/fs-safe/dist/retained-file-types.d.ts +50 -0
  111. package/node_modules/@openclaw/fs-safe/dist/retained-file-types.js +1 -0
  112. package/node_modules/@openclaw/fs-safe/dist/retained-file.d.ts +3 -0
  113. package/node_modules/@openclaw/fs-safe/dist/retained-file.js +121 -0
  114. package/node_modules/@openclaw/fs-safe/dist/root-context.js +3 -2
  115. package/node_modules/@openclaw/fs-safe/dist/root-directory-entry.d.ts +9 -0
  116. package/node_modules/@openclaw/fs-safe/dist/root-directory-entry.js +28 -0
  117. package/node_modules/@openclaw/fs-safe/dist/root-directory-list.d.ts +9 -1
  118. package/node_modules/@openclaw/fs-safe/dist/root-directory-list.js +88 -37
  119. package/node_modules/@openclaw/fs-safe/dist/root-file-final-admission.d.ts +1 -1
  120. package/node_modules/@openclaw/fs-safe/dist/root-file-final-admission.js +1 -6
  121. package/node_modules/@openclaw/fs-safe/dist/root-file.js +2 -5
  122. package/node_modules/@openclaw/fs-safe/dist/root-handle-context.d.ts +4 -0
  123. package/node_modules/@openclaw/fs-safe/dist/root-handle-context.js +12 -0
  124. package/node_modules/@openclaw/fs-safe/dist/root-impl.d.ts +3 -3
  125. package/node_modules/@openclaw/fs-safe/dist/root-impl.js +8 -5
  126. package/node_modules/@openclaw/fs-safe/dist/root-move-noreplace.d.ts +2 -7
  127. package/node_modules/@openclaw/fs-safe/dist/root-move-noreplace.js +3 -3
  128. package/node_modules/@openclaw/fs-safe/dist/root-observed-path.d.ts +0 -1
  129. package/node_modules/@openclaw/fs-safe/dist/root-observed-path.js +0 -3
  130. package/node_modules/@openclaw/fs-safe/dist/root-path-observation.d.ts +4 -11
  131. package/node_modules/@openclaw/fs-safe/dist/root-path.js +7 -10
  132. package/node_modules/@openclaw/fs-safe/dist/root-paths.d.ts +2 -6
  133. package/node_modules/@openclaw/fs-safe/dist/root-remove-identity.d.ts +1 -3
  134. package/node_modules/@openclaw/fs-safe/dist/root-walk.d.ts +19 -12
  135. package/node_modules/@openclaw/fs-safe/dist/root-walk.js +56 -20
  136. package/node_modules/@openclaw/fs-safe/dist/root-write-admission.js +1 -6
  137. package/node_modules/@openclaw/fs-safe/dist/root-write-complete-parent.d.ts +2 -0
  138. package/node_modules/@openclaw/fs-safe/dist/root-write-complete-parent.js +1 -1
  139. package/node_modules/@openclaw/fs-safe/dist/safe-path-segment.d.ts +1 -0
  140. package/node_modules/@openclaw/fs-safe/dist/safe-path-segment.js +8 -2
  141. package/node_modules/@openclaw/fs-safe/dist/secret-file.d.ts +6 -2
  142. package/node_modules/@openclaw/fs-safe/dist/secret-file.js +12 -16
  143. package/node_modules/@openclaw/fs-safe/dist/secret-read-policy.js +1 -1
  144. package/node_modules/@openclaw/fs-safe/dist/secure-file-windows.js +5 -14
  145. package/node_modules/@openclaw/fs-safe/dist/secure-file.js +3 -2
  146. package/node_modules/@openclaw/fs-safe/dist/secure-temp-dir.js +2 -7
  147. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-acquire.js +4 -4
  148. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-admission-parser.d.ts +1 -2
  149. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-handle.d.ts +2 -8
  150. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-policy.d.ts +2 -7
  151. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.d.ts +2 -2
  152. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.js +11 -12
  153. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-stale-admission.d.ts +1 -5
  154. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock.js +9 -7
  155. package/node_modules/@openclaw/fs-safe/dist/staged-symlink-types.d.ts +39 -0
  156. package/node_modules/@openclaw/fs-safe/dist/staged-symlink-types.js +1 -0
  157. package/node_modules/@openclaw/fs-safe/dist/stat-observation.js +3 -10
  158. package/node_modules/@openclaw/fs-safe/dist/strict-file-identity.d.ts +2 -0
  159. package/node_modules/@openclaw/fs-safe/dist/strict-file-identity.js +6 -6
  160. package/node_modules/@openclaw/fs-safe/dist/symlink-parents.js +58 -7
  161. package/node_modules/@openclaw/fs-safe/dist/temp-target.js +8 -10
  162. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-admission.js +28 -33
  163. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-child-admission.d.ts +1 -1
  164. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-child-admission.js +16 -17
  165. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-descriptor.js +1 -2
  166. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-owner.js +4 -9
  167. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-ownership.d.ts +8 -0
  168. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-ownership.js +52 -0
  169. package/node_modules/@openclaw/fs-safe/dist/test-hooks.d.ts +5 -1
  170. package/node_modules/@openclaw/fs-safe/dist/text-atomic.d.ts +2 -1
  171. package/node_modules/@openclaw/fs-safe/dist/text-atomic.js +2 -0
  172. package/node_modules/@openclaw/fs-safe/dist/trash.js +27 -1
  173. package/node_modules/@openclaw/fs-safe/dist/walk.d.ts +2 -5
  174. package/node_modules/@openclaw/fs-safe/dist/watch-alias.d.ts +6 -0
  175. package/node_modules/@openclaw/fs-safe/dist/watch-alias.js +88 -0
  176. package/node_modules/@openclaw/fs-safe/dist/watch-hints.d.ts +9 -0
  177. package/node_modules/@openclaw/fs-safe/dist/watch-hints.js +93 -0
  178. package/node_modules/@openclaw/fs-safe/dist/watch-native.d.ts +36 -0
  179. package/node_modules/@openclaw/fs-safe/dist/watch-native.js +73 -0
  180. package/node_modules/@openclaw/fs-safe/dist/watch-scan.d.ts +28 -0
  181. package/node_modules/@openclaw/fs-safe/dist/watch-scan.js +300 -0
  182. package/node_modules/@openclaw/fs-safe/dist/watch-stream.d.ts +8 -0
  183. package/node_modules/@openclaw/fs-safe/dist/watch-stream.js +32 -0
  184. package/node_modules/@openclaw/fs-safe/dist/watch-types.d.ts +60 -0
  185. package/node_modules/@openclaw/fs-safe/dist/watch-types.js +1 -0
  186. package/node_modules/@openclaw/fs-safe/dist/watch.d.ts +5 -0
  187. package/node_modules/@openclaw/fs-safe/dist/watch.js +530 -0
  188. package/node_modules/@openclaw/fs-safe/dist/windows-owner.d.ts +3 -7
  189. package/node_modules/@openclaw/fs-safe/dist/windows-owner.js +0 -1
  190. package/node_modules/@openclaw/fs-safe/dist/windows-security-bridge.cs +6 -6
  191. package/node_modules/@openclaw/fs-safe/dist/windows-security-bridge.ps1 +78 -3
  192. package/node_modules/@openclaw/fs-safe/dist/windows-security-command.d.ts +8 -0
  193. package/node_modules/@openclaw/fs-safe/dist/windows-security-command.js +66 -15
  194. package/node_modules/@openclaw/fs-safe/dist/windows-security-facts.d.ts +4 -0
  195. package/node_modules/@openclaw/fs-safe/dist/windows-security-facts.js +6 -2
  196. package/node_modules/@openclaw/fs-safe/docs/advanced.md +4 -2
  197. package/node_modules/@openclaw/fs-safe/docs/archive.md +16 -0
  198. package/node_modules/@openclaw/fs-safe/docs/atomic.md +93 -3
  199. package/node_modules/@openclaw/fs-safe/docs/contributing.md +102 -4
  200. package/node_modules/@openclaw/fs-safe/docs/copy.md +2 -0
  201. package/node_modules/@openclaw/fs-safe/docs/durability.md +7 -0
  202. package/node_modules/@openclaw/fs-safe/docs/file-store.md +5 -0
  203. package/node_modules/@openclaw/fs-safe/docs/guest.md +7 -1
  204. package/node_modules/@openclaw/fs-safe/docs/index.md +1 -0
  205. package/node_modules/@openclaw/fs-safe/docs/install.md +30 -0
  206. package/node_modules/@openclaw/fs-safe/docs/native-helper.md +20 -4
  207. package/node_modules/@openclaw/fs-safe/docs/native.md +63 -1
  208. package/node_modules/@openclaw/fs-safe/docs/permissions.md +66 -0
  209. package/node_modules/@openclaw/fs-safe/docs/public-api.md +30 -3
  210. package/node_modules/@openclaw/fs-safe/docs/retained-file.md +115 -0
  211. package/node_modules/@openclaw/fs-safe/docs/root.md +35 -9
  212. package/node_modules/@openclaw/fs-safe/docs/secret-file.md +19 -0
  213. package/node_modules/@openclaw/fs-safe/docs/security-model.md +4 -1
  214. package/node_modules/@openclaw/fs-safe/docs/sidecar-lock.md +5 -1
  215. package/node_modules/@openclaw/fs-safe/docs/staged-symlink.md +124 -0
  216. package/node_modules/@openclaw/fs-safe/docs/store.md +3 -1
  217. package/node_modules/@openclaw/fs-safe/docs/temp.md +24 -4
  218. package/node_modules/@openclaw/fs-safe/docs/testing.md +210 -0
  219. package/node_modules/@openclaw/fs-safe/docs/types.md +6 -0
  220. package/node_modules/@openclaw/fs-safe/docs/walk.md +34 -1
  221. package/node_modules/@openclaw/fs-safe/docs/watch.md +251 -0
  222. package/node_modules/@openclaw/fs-safe/docs/writing.md +21 -0
  223. package/node_modules/@openclaw/fs-safe/package.json +13 -9
  224. package/node_modules/@openclaw/fs-safe-darwin-arm64/fs-safe-native.node +0 -0
  225. package/node_modules/@openclaw/fs-safe-darwin-arm64/package.json +1 -1
  226. package/node_modules/@openclaw/fs-safe-darwin-x64/fs-safe-native.node +0 -0
  227. package/node_modules/@openclaw/fs-safe-darwin-x64/package.json +1 -1
  228. package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/fs-safe-native.node +0 -0
  229. package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/package.json +1 -1
  230. package/node_modules/@openclaw/fs-safe-linux-arm64-musl/fs-safe-native.node +0 -0
  231. package/node_modules/@openclaw/fs-safe-linux-arm64-musl/package.json +1 -1
  232. package/node_modules/@openclaw/fs-safe-linux-x64-gnu/fs-safe-native.node +0 -0
  233. package/node_modules/@openclaw/fs-safe-linux-x64-gnu/package.json +1 -1
  234. package/node_modules/@openclaw/fs-safe-linux-x64-musl/fs-safe-native.node +0 -0
  235. package/node_modules/@openclaw/fs-safe-linux-x64-musl/package.json +1 -1
  236. package/node_modules/@openclaw/fs-safe-win32-x64-msvc/fs-safe-native.node +0 -0
  237. package/node_modules/@openclaw/fs-safe-win32-x64-msvc/package.json +1 -1
  238. package/node_modules/p-limit/index.d.ts +2 -0
  239. package/node_modules/p-limit/index.js +17 -1
  240. package/node_modules/p-limit/package.json +1 -1
  241. package/node_modules/p-limit/readme.md +2 -0
  242. package/package.json +6 -6
  243. package/node_modules/@openclaw/fs-safe/dist/directory-mode-owner.d.ts +0 -20
  244. 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 native opens are kernel-atomic; macOS, Windows, and JavaScript paths are best-effort.
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. There are no postinstall
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; macOS, Windows,
98
- and guarded JavaScript results are best-effort. See the [security model](docs/security-model.md#containment-guarantees-by-platform) before using that fact in higher-level policy.
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, in-root symlink following, cancellation, and a
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 PermissionCommandFailure, type PermissionExec, type WindowsAclEntry, type WindowsAclSummary, } from "./permissions.js";
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, { hardlinks: "reject", symlinks: "reject" })
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, sourcePath, options);
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
- stripComponents?: number;
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
- let entry;
98
- // JSZip keys retain some aliases and may use Unicode Path metadata. Scan the
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
- if (isZipSymlinkEntry(entry)) {
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 (zipEntryKind(entry) !== "file")
105
+ if (kind !== "file")
115
106
  throw new Error(`archive entry is not a file: ${formatErrorDetail(entryPath)}`);
116
- const integrity = createZipIntegrityTransform(entry);
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
- await params.targetRoot.mkdir(params.relativePath);
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 { type ArchiveEntryModePolicy, type ArchiveEntryKind } from "./archive-plan.js";
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
- /** Internal: register only after the complete decoder/admission association. */
16
- export declare function registerAdmittedZipEntry(entry: ZipEntry, physical: ZipDirectoryEntry): void;
17
- export declare function zipEntryIntegrityMetadata(entry: ZipEntry): {
18
- crc32?: number;
19
- uncompressedSize?: number;
20
- } | undefined;
21
- export declare function isZipSymlinkEntry(entry: ZipEntry): boolean;
22
- export declare function zipEntryKind(entry: ZipEntry): ArchiveEntryKind;
23
- export declare function zipEntryMode(entry: ZipEntry, policy: ArchiveEntryModePolicy | undefined): number;
24
- export declare function zipEntryDeclaredSize(entry: ZipEntry): number;
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
- import { resolveArchiveEntryMode, } from "./archive-plan.js";
2
- const admittedMetadata = new WeakMap();
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 { type ZipEntry } from "./archive-zip-entry.js";
2
+ import type { AdmittedZipEntry } from "./archive-zip-entry.js";
3
3
  export declare function normalizeZipIntegrityError(error: unknown): Error;
4
- export declare function createZipIntegrityTransform(entry: ZipEntry): Transform;
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(entry) {
13
- const metadata = zipEntryIntegrityMetadata(entry);
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 ZipEntry } from "./archive-zip-entry.js";
2
+ import { type AdmittedZipEntry } from "./archive-zip-entry.js";
3
3
  export type ZipArchiveWithFiles = {
4
4
  files: Record<string, unknown>;
5
5
  };
6
- export declare function admittedZipEntries(archive: ZipArchiveWithFiles): readonly ZipEntry[];
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<ZipArchiveWithFiles>;
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 { registerAdmittedZipEntry } from "./archive-zip-entry.js";
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
- const orderedEntries = new WeakMap();
6
- export function admittedZipEntries(archive) {
7
- return orderedEntries.get(archive) ?? disagreement();
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
- registerAdmittedZipEntry(entry, physical);
124
- entries.push(entry);
128
+ entries.set(physical.portableKey, createAdmittedZipEntry(entry, normalizedName, physical));
125
129
  }
126
130
  archive.files = files;
127
- orderedEntries.set(archive, entries);
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 { readZipCentralDirectoryEntryCount } from "./archive-zip-count.js";
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 { readZipCentralDirectoryEntryCount } from "./archive-zip-count.js";
5
- export async function loadZipArchiveWithPreflight(buffer, limits) {
6
- const resolvedLimits = resolveExtractLimits(limits);
7
- if (buffer.byteLength > resolvedLimits.maxArchiveBytes) {
8
- throw new ArchiveLimitError(ARCHIVE_LIMIT_ERROR_CODE.ARCHIVE_SIZE_EXCEEDS_LIMIT);
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
- const entries = [];
11
- admitZipBuffer(buffer, resolvedLimits, entry => { entries.push(entry); });
12
- return await loadAdmittedZipArchive(buffer, entries);
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-staging.js";
10
- export { createArchiveSymlinkTraversalError, mergeExtractedTreeIntoDestination, prepareArchiveDestinationDir, prepareArchiveOutputPath, withStagedArchiveDestination, } from "./archive-staging.js";
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, readZipCentralDirectoryEntryCount, type ZipArchiveWithFiles, } from "./archive-zip-preflight.js";
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">>;