@openclaw/matrix 2026.11.11 → 2026.12.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.setup/{approval-handler.runtime-CCGCnRgz.mjs → approval-handler.runtime-BfY586xJ.mjs} +4 -4
- package/dist/.setup/{channel-BEgolhUJ.mjs → channel-Cc7auxIF.mjs} +8 -8
- package/dist/.setup/{channel.runtime-_NMfiRJl.mjs → channel.runtime-B6ZmWLDZ.mjs} +5 -5
- package/dist/.setup/{channel.setup-B7r4NCcE.mjs → channel.setup-D9-chyNP.mjs} +2 -2
- package/dist/.setup/{cli-CyjnAIzU.mjs → cli-BrTpL9JI.mjs} +7 -7
- package/dist/.setup/{cli-metadata-DNeLBXHC.mjs → cli-metadata-R7WyIFzA.mjs} +1 -1
- package/dist/.setup/{client-BVgnwwz0.mjs → client-BmxOI9-U.mjs} +2 -2
- package/dist/.setup/{client-gch0wggI.mjs → client-DOb_5cJm.mjs} +2 -2
- package/dist/.setup/{client-bootstrap-CHs5OQ1Z.mjs → client-bootstrap-BwDbzw5i.mjs} +1 -1
- package/dist/.setup/{create-client-mnjEWdZV.mjs → create-client-BQpMgtl2.mjs} +2 -2
- package/dist/.setup/{crypto-runtime-tZ95jwNO.mjs → crypto-runtime-CStae6zK.mjs} +1 -1
- package/dist/.setup/{direct-management-D59C1WO-.mjs → direct-management-Bm4vd-k1.mjs} +1 -1
- package/dist/.setup/{directory-live-CQNKUJJx.mjs → directory-live-DRGF3zFp.mjs} +1 -1
- package/dist/.setup/{draft-stream-DI_6HWy4.mjs → draft-stream-DpSefQTK.mjs} +2 -2
- package/dist/.setup/{exec-approvals-B23spbVI.mjs → exec-approvals-CTkGLt3Z.mjs} +2 -2
- package/dist/.setup/{messages-VnZ4u4iq.mjs → messages-DjmI7l5t.mjs} +3 -3
- package/dist/.setup/{monitor-wbUkxHXK.mjs → monitor-HjyjGlys.mjs} +18 -18
- package/dist/.setup/{onboarding-B51d5a6R.mjs → onboarding-BPkKv4dw.mjs} +3 -3
- package/dist/.setup/{outbound-D8rgFTRa.mjs → outbound-CthMgcxZ.mjs} +2 -2
- package/dist/.setup/{profile-update-DAQFPf4L.mjs → profile-update-myTQ_w_e.mjs} +3 -3
- package/dist/.setup/{reaction-events-CZlbNkx_.mjs → reaction-events-C22fpTeK.mjs} +5 -5
- package/dist/.setup/{resolve-targets-B3NLls5a.mjs → resolve-targets-3B6QJQUf.mjs} +1 -1
- package/dist/.setup/{room-info-Cw-BH1CA.mjs → room-info-7ER9IkzT.mjs} +3 -3
- package/dist/.setup/{sdk-Bzp2OIxv.mjs → sdk-DphkoEH1.mjs} +32 -33
- package/dist/.setup/{send-CK8h-x83.mjs → send-CAfHI3Oi.mjs} +18 -13
- package/dist/.setup/{send-currentness-D1x6YP9O.mjs → send-currentness-Zv5Z-1_t.mjs} +9 -5
- package/dist/.setup/{setup-bootstrap-DsHa4swp.mjs → setup-bootstrap-COKlzUTV.mjs} +2 -2
- package/dist/.setup/{setup-core-B3MI_zz4.mjs → setup-core-B1dRvn1h.mjs} +1 -1
- package/dist/.setup/setup-plugin-api-BGpOj2cE.mjs +2 -0
- package/dist/.setup/{thread-bindings-C_SHelhg.mjs → thread-bindings-DFF_4WP3.mjs} +1 -1
- package/dist/.setup/{tool-actions-nhsof0wb.mjs → tool-actions-Cal-116X.mjs} +11 -11
- package/dist/.setup/{verification-BZqaSKCW.mjs → verification-2flsiwT7.mjs} +1 -1
- package/dist/.source-module-urls/1cd4d4ff8d44e1c8b830932b44d7cf8a7f3350e09e169910e1d7a85e131b7bea.json +1 -1
- package/dist/api.js +4 -4
- package/dist/channel-plugin-api.js +1 -1
- package/dist/cli-metadata.js +1 -1
- package/dist/contract-api.js +2 -2
- package/dist/index.js +1 -1
- package/dist/plugin-entry.handlers.runtime.js +2 -2
- package/dist/session-binding-contract-api.js +1 -1
- package/dist/setup-entry.js +1 -1
- package/dist/setup-plugin-api.js +1 -1
- package/node_modules/@openclaw/fs-safe/CHANGELOG.md +57 -0
- package/node_modules/@openclaw/fs-safe/README.md +6 -0
- package/node_modules/@openclaw/fs-safe/dist/archive-parser.wasm +0 -0
- package/node_modules/@openclaw/fs-safe/dist/atomic-io.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/atomic-io.js +10 -0
- package/node_modules/@openclaw/fs-safe/dist/bounded-read.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/bounded-read.js +15 -4
- package/node_modules/@openclaw/fs-safe/dist/directory-guard.js +11 -2
- package/node_modules/@openclaw/fs-safe/dist/drvfs-parent.d.ts +6 -0
- package/node_modules/@openclaw/fs-safe/dist/drvfs-parent.js +38 -0
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-acquisition.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-acquisition.js +2 -2
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-acquire.js +13 -8
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-io.js +13 -0
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-mutation.d.ts +2 -2
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-mutation.js +34 -24
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-stale-admission.js +7 -2
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync.js +20 -20
- package/node_modules/@openclaw/fs-safe/dist/file-observation.d.ts +13 -2
- package/node_modules/@openclaw/fs-safe/dist/file-observation.js +8 -4
- package/node_modules/@openclaw/fs-safe/dist/file-store-sync-write.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/file-store-sync-write.js +11 -1
- package/node_modules/@openclaw/fs-safe/dist/file-store-write-options.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/file-store-write-options.js +17 -0
- package/node_modules/@openclaw/fs-safe/dist/file-store.d.ts +2 -1
- package/node_modules/@openclaw/fs-safe/dist/file-store.js +12 -16
- package/node_modules/@openclaw/fs-safe/dist/guest-native-python.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/guest.js +3 -4
- package/node_modules/@openclaw/fs-safe/dist/json-document-store.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/json-document-store.js +1 -0
- package/node_modules/@openclaw/fs-safe/dist/json-store.js +1 -0
- package/node_modules/@openclaw/fs-safe/dist/json.d.ts +5 -2
- package/node_modules/@openclaw/fs-safe/dist/json.js +6 -2
- package/node_modules/@openclaw/fs-safe/dist/local-file-descriptor.js +16 -10
- package/node_modules/@openclaw/fs-safe/dist/native-binding.d.ts +6 -0
- package/node_modules/@openclaw/fs-safe/dist/native-pinned-write.js +4 -0
- package/node_modules/@openclaw/fs-safe/dist/native-staged-file-metadata.d.ts +20 -0
- package/node_modules/@openclaw/fs-safe/dist/native-staged-file-metadata.js +18 -0
- package/node_modules/@openclaw/fs-safe/dist/native-staged-file.d.ts +3 -18
- package/node_modules/@openclaw/fs-safe/dist/native-staged-file.js +48 -24
- package/node_modules/@openclaw/fs-safe/dist/opened-file-failure.js +19 -7
- package/node_modules/@openclaw/fs-safe/dist/output.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/output.js +3 -0
- package/node_modules/@openclaw/fs-safe/dist/path-policy.js +4 -1
- package/node_modules/@openclaw/fs-safe/dist/permissions-windows.js +35 -10
- package/node_modules/@openclaw/fs-safe/dist/pinned-open.d.ts +9 -2
- package/node_modules/@openclaw/fs-safe/dist/pinned-open.js +42 -23
- package/node_modules/@openclaw/fs-safe/dist/pinned-write-staged.js +85 -34
- package/node_modules/@openclaw/fs-safe/dist/pinned-write-types.d.ts +3 -0
- package/node_modules/@openclaw/fs-safe/dist/pinned-write.js +4 -0
- package/node_modules/@openclaw/fs-safe/dist/prepare-directory-mode.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/prepare-directory-mode.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/private-temp-workspace.js +2 -2
- package/node_modules/@openclaw/fs-safe/dist/publication-recovery.d.ts +24 -0
- package/node_modules/@openclaw/fs-safe/dist/publication-recovery.js +151 -0
- package/node_modules/@openclaw/fs-safe/dist/publish-copy-stage.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/publish-copy-stage.js +2 -1
- package/node_modules/@openclaw/fs-safe/dist/realpath.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/realpath.js +22 -11
- package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.js +5 -0
- package/node_modules/@openclaw/fs-safe/dist/replace-file-temp-owner.d.ts +7 -0
- package/node_modules/@openclaw/fs-safe/dist/replace-file-temp-owner.js +75 -2
- package/node_modules/@openclaw/fs-safe/dist/replace-file-types.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/replace-file.js +14 -10
- package/node_modules/@openclaw/fs-safe/dist/root-context.js +28 -12
- package/node_modules/@openclaw/fs-safe/dist/root-copy.js +1 -0
- package/node_modules/@openclaw/fs-safe/dist/root-create-input.js +2 -2
- package/node_modules/@openclaw/fs-safe/dist/root-file-final-admission.d.ts +4 -0
- package/node_modules/@openclaw/fs-safe/dist/root-file-final-admission.js +53 -36
- package/node_modules/@openclaw/fs-safe/dist/root-file-open-batch-sync.js +3 -1
- package/node_modules/@openclaw/fs-safe/dist/root-file.d.ts +2 -1
- package/node_modules/@openclaw/fs-safe/dist/root-file.js +24 -13
- package/node_modules/@openclaw/fs-safe/dist/root-impl.js +17 -1
- package/node_modules/@openclaw/fs-safe/dist/root-options.d.ts +4 -2
- package/node_modules/@openclaw/fs-safe/dist/root-path.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/root-path.js +2 -1
- package/node_modules/@openclaw/fs-safe/dist/root-read-admission.js +31 -9
- package/node_modules/@openclaw/fs-safe/dist/root-write-admission.js +6 -2
- package/node_modules/@openclaw/fs-safe/dist/secret-file.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/secret-file.js +2 -0
- package/node_modules/@openclaw/fs-safe/dist/sibling-staged-file.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/sibling-staged-file.js +84 -4
- package/node_modules/@openclaw/fs-safe/dist/sibling-temp.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/sibling-temp.js +2 -0
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-acquire.js +22 -15
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-publication.d.ts +22 -0
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-publication.js +303 -0
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.js +9 -1
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-root.d.ts +8 -0
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-root.js +37 -3
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-staging.d.ts +14 -0
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-staging.js +155 -0
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-stale-admission.js +7 -2
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-write.d.ts +10 -0
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-write.js +143 -0
- package/node_modules/@openclaw/fs-safe/dist/temp-target.js +28 -7
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-admission.d.ts +2 -2
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-admission.js +34 -18
- 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 +13 -3
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-ownership.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-types.d.ts +9 -0
- package/node_modules/@openclaw/fs-safe/dist/test-hooks.d.ts +6 -0
- package/node_modules/@openclaw/fs-safe/dist/text-atomic.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/text-atomic.js +1 -0
- package/node_modules/@openclaw/fs-safe/dist/windows-owner.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/windows-owner.js +2 -1
- package/node_modules/@openclaw/fs-safe/dist/windows-security-helper.exe +0 -0
- package/node_modules/@openclaw/fs-safe/docs/advanced.md +6 -1
- package/node_modules/@openclaw/fs-safe/docs/atomic.md +64 -0
- package/node_modules/@openclaw/fs-safe/docs/contributing.md +69 -0
- package/node_modules/@openclaw/fs-safe/docs/file-store.md +2 -0
- package/node_modules/@openclaw/fs-safe/docs/json-store.md +2 -0
- package/node_modules/@openclaw/fs-safe/docs/json.md +2 -0
- package/node_modules/@openclaw/fs-safe/docs/output.md +2 -0
- package/node_modules/@openclaw/fs-safe/docs/permissions.md +20 -7
- package/node_modules/@openclaw/fs-safe/docs/reading.md +24 -9
- package/node_modules/@openclaw/fs-safe/docs/root.md +2 -0
- package/node_modules/@openclaw/fs-safe/docs/security-model.md +2 -0
- package/node_modules/@openclaw/fs-safe/docs/sidecar-lock.md +12 -7
- package/node_modules/@openclaw/fs-safe/docs/staged-file.md +2 -0
- package/node_modules/@openclaw/fs-safe/docs/temp-isolation-reference.md +73 -0
- package/node_modules/@openclaw/fs-safe/docs/temp.md +65 -0
- package/node_modules/@openclaw/fs-safe/docs/testing.md +1 -0
- package/node_modules/@openclaw/fs-safe/docs/writing.md +2 -0
- package/node_modules/@openclaw/fs-safe/package.json +25 -20
- 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-freebsd-arm64/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-freebsd-arm64/package.json +1 -1
- package/node_modules/@openclaw/fs-safe-freebsd-x64/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-freebsd-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-arm64-msvc/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-win32-arm64-msvc/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/package.json +5 -5
- package/dist/.setup/setup-plugin-api-D6-D6LLj.mjs +0 -2
|
@@ -14,7 +14,7 @@ export declare function projectTempWorkspaceNumericIdentity(identity: TempWorksp
|
|
|
14
14
|
export declare function inspectTempWorkspaceDescriptorIdentitySync(fd: number, expected: TempWorkspaceIdentity, numeric: TempWorkspaceNumericIdentity | undefined): TempWorkspaceIdentityStat;
|
|
15
15
|
export declare function inspectTempWorkspaceDirectoryIdentitySync(dir: string, expected: TempWorkspaceIdentity, numeric: TempWorkspaceNumericIdentity | undefined): TempWorkspaceIdentityStat;
|
|
16
16
|
export declare function validateTempWorkspaceDirMode(mode: number): void;
|
|
17
|
-
export declare function assertTrustedTempWorkspaceDirectory(stat: Pick<BigIntStats, "uid" | "gid" | "mode"> | Pick<Stats, "uid" | "gid" | "mode">, uid: number | undefined, privateDirectory: boolean, dir: string): void;
|
|
17
|
+
export declare function assertTrustedTempWorkspaceDirectory(stat: Pick<BigIntStats, "uid" | "gid" | "mode"> | Pick<Stats, "uid" | "gid" | "mode">, uid: number | undefined, privateDirectory: boolean, dir: string, allowWritableAncestor?: boolean): void;
|
|
18
18
|
export declare function assertTempWorkspaceChildState(stat: BigIntStats | Stats, ownerUid: number | undefined, dir: string): void;
|
|
19
19
|
export declare function validateInitialTempWorkspaceChild(stat: BigIntStats, ownerUid: number | undefined, mode: number, dir: string): boolean;
|
|
20
20
|
export declare function childHasRequestedMode(stat: BigIntStats | Stats, mode: number): boolean;
|
|
@@ -44,7 +44,14 @@ export function validateTempWorkspaceDirMode(mode) {
|
|
|
44
44
|
throw new FsSafeError("insecure-permissions", "temp workspace must not be group/world writable");
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
let warnedTrustedWritableAncestor = false;
|
|
48
|
+
function warnTrustedWritableAncestor() {
|
|
49
|
+
if (warnedTrustedWritableAncestor)
|
|
50
|
+
return;
|
|
51
|
+
warnedTrustedWritableAncestor = true;
|
|
52
|
+
process.emitWarning("Temp workspace ancestor write protection is bypassed by trustedWritableAncestors; external isolation must prevent untrusted writers, including same-UID processes, from replacing the directory ancestry for the workspace lifetime.", { code: "FS_SAFE_TRUSTED_WRITABLE_ANCESTOR", type: "FsSafeWarning" });
|
|
53
|
+
}
|
|
54
|
+
export function assertTrustedTempWorkspaceDirectory(stat, uid, privateDirectory, dir, allowWritableAncestor = false) {
|
|
48
55
|
if (uid === undefined)
|
|
49
56
|
return;
|
|
50
57
|
const ownership = classifyTempWorkspaceOwner(stat, uid);
|
|
@@ -53,7 +60,8 @@ export function assertTrustedTempWorkspaceDirectory(stat, uid, privateDirectory,
|
|
|
53
60
|
}
|
|
54
61
|
// Unmapped host owners are unverifiable; trust the host directory hierarchy.
|
|
55
62
|
// Admit sticky ancestors so PrivateUsers keeps host /tmp and PrivateTmp usable.
|
|
56
|
-
// Leaf roots stay euid-owned/private
|
|
63
|
+
// Leaf roots stay euid-owned/private. Only explicitly trusted ancestors may
|
|
64
|
+
// rely on external isolation instead of sticky protection against other writers.
|
|
57
65
|
const writeMask = !privateDirectory && hasTrustedAndroidTempAncestorGroup(stat, uid, ownership)
|
|
58
66
|
? 0o002 : 0o022;
|
|
59
67
|
const writable = typeof stat.mode === "bigint"
|
|
@@ -65,11 +73,13 @@ export function assertTrustedTempWorkspaceDirectory(stat, uid, privateDirectory,
|
|
|
65
73
|
if (typeof stat.mode !== "bigint" && (!Number.isSafeInteger(stat.mode) || stat.mode < 0)) {
|
|
66
74
|
throw new FsSafeError("insecure-permissions", `temp workspace directory ${JSON.stringify(dir)} permissions are invalid; ${privateTempDirectoryFix(uid)}`);
|
|
67
75
|
}
|
|
68
|
-
if (writable && (privateDirectory || !sticky)) {
|
|
76
|
+
if (writable && (privateDirectory || (!sticky && !allowWritableAncestor))) {
|
|
69
77
|
throw new FsSafeError("insecure-permissions", privateDirectory
|
|
70
78
|
? `temp workspace directory ${JSON.stringify(dir)} has group/world-writable mode ${tempDirectoryMode(stat.mode)}; root and child must not be group/world writable, even with the sticky bit; ${privateTempDirectoryFix(uid)}`
|
|
71
79
|
: `temp workspace ancestor ${JSON.stringify(dir)} has group/world-writable mode ${tempDirectoryMode(stat.mode)} without sticky protection (sticky bit missing); have its administrator restore safe permissions (1777 for a shared system temp directory), or move the private root under trusted ancestors`);
|
|
72
80
|
}
|
|
81
|
+
if (!privateDirectory && writable && !sticky && allowWritableAncestor)
|
|
82
|
+
warnTrustedWritableAncestor();
|
|
73
83
|
if (ownership === "unmapped")
|
|
74
84
|
warnUnmappedTempWorkspaceAncestor();
|
|
75
85
|
}
|
|
@@ -70,5 +70,5 @@ export function warnUnmappedTempWorkspaceAncestor() {
|
|
|
70
70
|
if (warned)
|
|
71
71
|
return;
|
|
72
72
|
warned = true;
|
|
73
|
-
process.emitWarning("Temp workspace ancestor ownership is unverifiable in this user namespace; trusting the host directory hierarchy while enforcing ancestor
|
|
73
|
+
process.emitWarning("Temp workspace ancestor ownership is unverifiable in this user namespace; trusting the host directory hierarchy while enforcing the configured ancestor policy and a process-owned private root.", { code: "FS_SAFE_UNMAPPED_TEMP_ANCESTOR", type: "FsSafeWarning" });
|
|
74
74
|
}
|
|
@@ -9,6 +9,15 @@ export type TempWorkspaceOptions = {
|
|
|
9
9
|
dirMode?: DirectoryMode;
|
|
10
10
|
mode?: number;
|
|
11
11
|
cleanupSafety?: TempWorkspaceCleanupSafety;
|
|
12
|
+
/**
|
|
13
|
+
* Allow ancestor write bits at exact canonical paths, relying on external isolation.
|
|
14
|
+
* Untrusted writers, including same-UID model/terminal processes, must not be able
|
|
15
|
+
* to rename or recreate the ancestry for the workspace lifetime: later I/O may
|
|
16
|
+
* otherwise target replacement directories. Private modes and bounded cleanup
|
|
17
|
+
* do not prevent redirected I/O. Use only trusted deployment configuration.
|
|
18
|
+
* Emits FS_SAFE_TRUSTED_WRITABLE_ANCESTOR once per process when a check is bypassed.
|
|
19
|
+
*/
|
|
20
|
+
trustedWritableAncestors?: readonly string[];
|
|
12
21
|
};
|
|
13
22
|
export type TempWorkspace = {
|
|
14
23
|
dir: string;
|
|
@@ -23,6 +23,7 @@ export type FsSafeTestHooks = {
|
|
|
23
23
|
beforeRootListObservation?: (directoryPath: string, withFileTypes: boolean) => Promise<void> | void;
|
|
24
24
|
afterPinnedWriteFallbackRename?: (targetPath: string) => Promise<void> | void;
|
|
25
25
|
beforeSiblingTempWrite?: (tempPath: string) => Promise<void> | void;
|
|
26
|
+
beforeSidecarLockPublish?: (lockPath: string, temporaryPath: string) => void;
|
|
26
27
|
beforeSidecarLockSnapshotOpen?: (lockPath: string) => Promise<void> | void;
|
|
27
28
|
beforeRegularFileAppendOpen?: (filePath: string) => Promise<void> | void;
|
|
28
29
|
beforeRegularFileAppendOpenSync?: (filePath: string) => void;
|
|
@@ -31,6 +32,11 @@ export type FsSafeTestHooks = {
|
|
|
31
32
|
beforeTrashMove?: (targetPath: string, destPath: string) => void;
|
|
32
33
|
afterPublishTargetCreated?: (method: "hardlink" | "exclusive-copy" | "rename-noreplace", targetPath: string, identity: FileIdentityStat) => Promise<void> | void;
|
|
33
34
|
beforePublishDirectorySync?: NonNullable<FsSafeTestHooks["afterPublishTargetCreated"]>;
|
|
35
|
+
drvfsMountObservation?: (parentFd: number) => {
|
|
36
|
+
magic: bigint;
|
|
37
|
+
fdinfo: string;
|
|
38
|
+
mountinfo: string;
|
|
39
|
+
} | undefined;
|
|
34
40
|
};
|
|
35
41
|
export declare function getFsSafeTestHooks(): FsSafeTestHooks | undefined;
|
|
36
42
|
export declare function __setFsSafeTestHooksForTest(hooks?: FsSafeTestHooks): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ReplaceFileAtomicOptions } from "./replace-file.js";
|
|
2
2
|
import type { DirectoryMode } from "./directory-mode-options.js";
|
|
3
|
-
export type WriteTextAtomicOptions = Pick<ReplaceFileAtomicOptions, "beforeRename" | "tempPrefix"> & {
|
|
3
|
+
export type WriteTextAtomicOptions = Pick<ReplaceFileAtomicOptions, "beforeRename" | "tempPrefix" | "allowDrvfsRenameRecovery"> & {
|
|
4
4
|
mode?: number;
|
|
5
5
|
dirMode?: DirectoryMode;
|
|
6
6
|
trailingNewline?: boolean;
|
|
@@ -18,6 +18,7 @@ export type WindowsOwnerAce = {
|
|
|
18
18
|
deny: boolean;
|
|
19
19
|
inheritOnly: boolean;
|
|
20
20
|
};
|
|
21
|
+
export declare const TRUSTED_INSTALLER_SID = "s-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464";
|
|
21
22
|
export declare function inspectWindowsOwner(params: {
|
|
22
23
|
targetPath: string;
|
|
23
24
|
env?: NodeJS.ProcessEnv;
|
|
@@ -6,7 +6,8 @@ import { windowsSecurityHelperPath } from "./windows-security-helper.js";
|
|
|
6
6
|
import { hasWindowsPathAlias } from "./windows-path-alias.js";
|
|
7
7
|
import { APP_CONTAINER_SID_RE } from "./windows-security-facts.js";
|
|
8
8
|
const SID_RE = /^\*?s-\d+-\d+(-\d+)+$/i;
|
|
9
|
-
const
|
|
9
|
+
export const TRUSTED_INSTALLER_SID = "s-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464";
|
|
10
|
+
const TRUSTED_OWNER_SIDS = new Set(["s-1-5-18", "s-1-5-32-544", TRUSTED_INSTALLER_SID]);
|
|
10
11
|
function normalizeSid(value) {
|
|
11
12
|
const normalized = value.trim().toLowerCase();
|
|
12
13
|
return normalized.startsWith("*") ? normalized.slice(1) : normalized;
|
|
Binary file
|
|
@@ -31,7 +31,7 @@ The exports group into a handful of themes. Documented helpers link to their con
|
|
|
31
31
|
| `resolveExistingPathsWithinRoot` | – | Validate existing regular files inside the root, while allowing missing paths. |
|
|
32
32
|
| `resolveStrictExistingPathsWithinRoot` | – | Require every target to exist as a regular non-symlink file inside the root. |
|
|
33
33
|
| `resolveWritablePathWithinRoot` | – | Resolve a write target inside a root. |
|
|
34
|
-
| `resolveRootPath`, `resolveRootPathSync`, `ResolvedRootPath`, `ROOT_PATH_ALIAS_POLICIES`, `RootPathAliasPolicy` | – | Resolve a root directory honoring alias policy. Awaited POSIX traversal uses asynchronous Node metadata and canonicalization; the explicit sync variant blocks. Windows retains synchronous traversal to preserve concurrent reads and atomic publication until canonicalization supports delete sharing.
|
|
34
|
+
| `resolveRootPath`, `resolveRootPathSync`, `ResolvedRootPath`, `ROOT_PATH_ALIAS_POLICIES`, `RootPathAliasPolicy` | – | Resolve a root directory honoring alias policy. Awaited POSIX traversal uses asynchronous Node metadata and canonicalization; the explicit sync variant blocks. Windows retains synchronous traversal to preserve concurrent reads and atomic publication until canonicalization supports delete sharing. Other identity/observation guards may still be synchronous. |
|
|
35
35
|
| `resolvePathViaExistingAncestorSync` | – | Walk to an existing ancestor for paths whose tail does not yet exist. |
|
|
36
36
|
| `resolvePathPrefix`, `resolvePathPrefixSync`, `ResolvedPathPrefix` | [path-prefix.md](path-prefix.md) | Follow physical symlink targets and return a canonical existing prefix with the raw missing suffix; propagate uncertain resolution failures. |
|
|
37
37
|
| `probePathCaseInsensitiveSync`, `ProbePathCaseOptions` | [path-case.md](path-case.md) | Observe local ASCII-case behavior with explicit read-only mode and owned temporary-probe cleanup. |
|
|
@@ -102,6 +102,11 @@ receipts remain numeric. Custom `ioFs` adapters must honor `{ bigint: true }` fo
|
|
|
102
102
|
Windows identities receive one re-inspection without reopening, then fail
|
|
103
103
|
validation if still unknown.
|
|
104
104
|
|
|
105
|
+
With the built-in adapter on POSIX, `openRootFile()` awaits the metadata, native
|
|
106
|
+
canonicalization, descriptor open, and final admission checks. Windows and custom
|
|
107
|
+
`ioFs` adapters retain their synchronous admission path; `openRootFileSync()`
|
|
108
|
+
remains synchronous on every platform.
|
|
109
|
+
|
|
105
110
|
On Windows, these existing-object readers retain their historical support for a
|
|
106
111
|
leading drive-relative spelling such as `C:existing.txt`: it is anchored to that
|
|
107
112
|
drive before confinement and namespace admission. Additional colons remain in
|
|
@@ -35,6 +35,10 @@ are independent of this directory policy.
|
|
|
35
35
|
|
|
36
36
|
Async replacements to the same destination are serialized inside the current process, so two overlapping `replaceFileAtomic()` calls do not interleave their temp-write/rename phases. Use a sidecar lock when multiple processes may write the same target.
|
|
37
37
|
|
|
38
|
+
On DrvFS mounts that hide renamed files while any descriptor is open, the
|
|
39
|
+
strict default rejects post-rename `ENOENT`. See the explicit
|
|
40
|
+
[`allowDrvfsRenameRecovery` exception](#drvfs-hidden-rename-recovery).
|
|
41
|
+
|
|
38
42
|
Relative paths retain their literal suffix so `.` and `..` keep Node's existing
|
|
39
43
|
filesystem semantics. On Windows, an ordinary drive-relative destination such
|
|
40
44
|
as `C:.\\state.json` is captured at entry by anchoring the drive's current
|
|
@@ -72,6 +76,7 @@ type ReplaceFileAtomicOptions = {
|
|
|
72
76
|
maxRestoreBytes?: number; // required with "restore-original"
|
|
73
77
|
destinationHardlinks?: "reject"; // default unset (no destination nlink policy)
|
|
74
78
|
renameIdentity?: "strict" | "verify-content-with-lock"; // default "strict"
|
|
79
|
+
allowDrvfsRenameRecovery?: boolean; // default false; verified DrvFS only
|
|
75
80
|
syncTempFile?: boolean; // fsync(temp) before rename, or the final file after copy fallback; default false
|
|
76
81
|
syncParentDir?: boolean; // fsync(parent) after rename, POSIX only; default false
|
|
77
82
|
throwOnCleanupError?: boolean; // report temp cleanup failure; default false
|
|
@@ -93,6 +98,65 @@ pinned destination. The snapshot does not make replacement a compare-and-swap
|
|
|
93
98
|
operation, so the destination parent must still be protected from untrusted
|
|
94
99
|
concurrent namespace mutation.
|
|
95
100
|
|
|
101
|
+
### DrvFS hidden-rename recovery
|
|
102
|
+
|
|
103
|
+
`allowDrvfsRenameRecovery: true` permits recovery only after a successful rename
|
|
104
|
+
is followed by `ENOENT`. It is off by default. Omitting it preserves strict
|
|
105
|
+
behavior and adds no filesystem calls. On Linux, enabling it first rules out
|
|
106
|
+
non-9p filesystems using the existing device identity or one native `fstatfs`
|
|
107
|
+
on an already-open parent descriptor. Only negative results are cached by
|
|
108
|
+
exact device number; device reuse can therefore only retain strict behavior,
|
|
109
|
+
never enable recovery. After a negative observation, subsequent writes on that
|
|
110
|
+
filesystem add no filesystem calls. Writers without an existing parent descriptor
|
|
111
|
+
reuse their ordinary recovery-parent acquisition for the first observation.
|
|
112
|
+
Unavailable native probes keep the existing preparation path (except known
|
|
113
|
+
block-device filesystems, which cannot be 9p). Healthy publications still use
|
|
114
|
+
their ordinary verification.
|
|
115
|
+
|
|
116
|
+
The retained parent's backing filesystem must have statfs magic `0x01021997`
|
|
117
|
+
(9p). Its `/proc/self/fdinfo/<fd>` mount ID must select exactly one entry in
|
|
118
|
+
`/proc/self/mountinfo` with filesystem type `9p` and `aname=drvfs` in the super
|
|
119
|
+
options. This includes the reporter's Docker Desktop Windows-drive bind mount.
|
|
120
|
+
Unavailable, malformed, ambiguous, or different mount evidence never enables
|
|
121
|
+
recovery. No create/unlink sampling, path-name heuristics, or positive mount
|
|
122
|
+
cache is used.
|
|
123
|
+
|
|
124
|
+
Recovery closes the operation's file descriptors, then reopens the published
|
|
125
|
+
name through guarded helpers. It requires the pre-rename exact bigint device
|
|
126
|
+
and inode, regular-file type, one link, size, mode, owner and group. Parent
|
|
127
|
+
identity/confinement checks remain in force. Byte-backed writes compare content
|
|
128
|
+
as well; callback staging compares a SHA-256 digest captured before rename.
|
|
129
|
+
There are at most five reopen attempts, retrying only `ENOENT` with 20 ms delays.
|
|
130
|
+
A swap, deletion or ownership change fails. A mode that prevents the required
|
|
131
|
+
read also fails; recovery never widens permissions to read the file. Descriptors
|
|
132
|
+
owned by other code can keep the name hidden and exhaust the retry budget.
|
|
133
|
+
|
|
134
|
+
**Residual risk:** closing the last descriptor gives up continuous inode
|
|
135
|
+
retention. If an inode is deleted and its complete identity is recycled before
|
|
136
|
+
verification, identity alone cannot distinguish it. NTFS file references include
|
|
137
|
+
a 16-bit sequence that wraps after 65,536 reuses of the same record; DrvFS
|
|
138
|
+
admission does not prove the underlying Windows filesystem is NTFS. Content
|
|
139
|
+
comparison narrows this risk but cannot distinguish an identical replacement.
|
|
140
|
+
Scheduling pauses are not bounded by retry counts or delays. Enable this option
|
|
141
|
+
only when accepting that tradeoff for the affected mount.
|
|
142
|
+
|
|
143
|
+
| API | Where to enable | Content check after recovery |
|
|
144
|
+
| --- | --- | --- |
|
|
145
|
+
| `replaceFileAtomic`, `replaceFileAtomicSync` | options | exact bytes |
|
|
146
|
+
| `writeTextAtomic`, `writeJson`, `writeJsonSync` | options | exact serialized bytes |
|
|
147
|
+
| `Root.write`, `writeJson`, `create`, `createJson` | Root defaults or per-call options | exact bytes for buffered input |
|
|
148
|
+
| `Root.copyIn`, streamed `Root.create` | Root defaults or per-call options | metadata; bytes are not retained |
|
|
149
|
+
| `fileStore`, `fileStoreSync` | store defaults or write options | exact bytes for buffered/JSON writes |
|
|
150
|
+
| `jsonStore`, `fileStore().json()` | JSON-store options or parent store defaults | exact serialized bytes |
|
|
151
|
+
| `writeSiblingTempFile`, sibling `writeExternalFileWithinRoot` | options | pre-rename digest |
|
|
152
|
+
| `stageFileInDirectory` | staging options | exact bytes |
|
|
153
|
+
| `writeSecretFileAtomic`, `createSecretFileAtomic` | options | exact bytes |
|
|
154
|
+
|
|
155
|
+
The same admission and metadata requirements apply to native and TypeScript
|
|
156
|
+
implementations and synchronous and asynchronous writes. This option is separate
|
|
157
|
+
from `renameIdentity: "verify-content-with-lock"`, which addresses changed inode
|
|
158
|
+
identities on other filesystems; DrvFS recovery never accepts a changed identity.
|
|
159
|
+
|
|
96
160
|
### `beforeRename`
|
|
97
161
|
|
|
98
162
|
Runs after the temp file is fully written and before the rename. Use it to take a backup snapshot, capture the about-to-be-replaced contents, or notify an observer. The helper retains the staged descriptor and exact bigint identity across the hook; replacing, deleting, hardlinking, or changing the temp entry to a non-regular file is rejected before publication:
|
|
@@ -100,6 +100,38 @@ On Linux x64 or arm64 with Docker, run `pnpm build`, copy the matching GNU artif
|
|
|
100
100
|
artifact and run native security and no-replace move tests in Rocky Linux 8
|
|
101
101
|
(glibc 2.28). Both GNU architectures execute this load test on matching runners.
|
|
102
102
|
|
|
103
|
+
### FreeBSD runtime admission
|
|
104
|
+
|
|
105
|
+
The shared FreeBSD 14.4 workflow prepares JavaScript with Node 24.22.1 and
|
|
106
|
+
installs the FreeBSD `node24` package inside each VM. Before native builds or
|
|
107
|
+
package proofs, it verifies the actual executable is stable Node 24, version
|
|
108
|
+
24.22.1 or newer, and matches the expected FreeBSD architecture. The package
|
|
109
|
+
name alone does not establish that its security fixes are present. If admission
|
|
110
|
+
fails, refresh FreeBSD package metadata and upgrade the selected Node package
|
|
111
|
+
before rerunning. Do not bypass the floor to obtain native artifacts; a missing
|
|
112
|
+
patched supplier package blocks this qualification route.
|
|
113
|
+
|
|
114
|
+
### Windows runtime contract
|
|
115
|
+
|
|
116
|
+
Windows x64 and ARM64 addons statically link compiler-specific runtime support
|
|
117
|
+
and dynamically link the inbox, OS-serviced UCRT. Consumers do not need a
|
|
118
|
+
separate Visual C++ Redistributable. `pnpm native:build` and release builds use
|
|
119
|
+
`scripts/build-native.mjs`; it preserves inherited Rust flags and Cargo's
|
|
120
|
+
`CARGO_ENCODED_RUSTFLAGS` precedence while appending the hybrid CRT settings.
|
|
121
|
+
Build, staging, signing preparation and package collection reject ordinary or
|
|
122
|
+
delay imports of VC redistributable DLLs, missing OS UCRT imports, and the wrong
|
|
123
|
+
native architecture or PE kind.
|
|
124
|
+
|
|
125
|
+
The security helper remains a deterministic .NET Framework 4.6.2 IL-only AnyCPU
|
|
126
|
+
PE32 executable, using the Windows CLR and OS P/Invoke libraries. It has no
|
|
127
|
+
native addon architecture or UCRT-import requirement. Its build and package
|
|
128
|
+
gates check that managed format and reject VC redistributable imports without
|
|
129
|
+
changing the helper's framework, signing, unsigned reproducibility comparison
|
|
130
|
+
or signed-byte manifest verification. Import inspection accepts Authenticode
|
|
131
|
+
certificate overlays and never rewrites signed bytes.
|
|
132
|
+
Test fixtures, harnesses and debug builds do not ship and keep their existing
|
|
133
|
+
runtime configuration; they are not subject to release runtime admission.
|
|
134
|
+
|
|
103
135
|
### Windows ARM64 builds
|
|
104
136
|
|
|
105
137
|
`windows-11-arm` builds and runs the ARM64 MSVC addon using native ARM64 Node
|
|
@@ -191,6 +223,43 @@ pnpm build
|
|
|
191
223
|
pnpm test --config scripts/slow-package-copy.config.ts
|
|
192
224
|
```
|
|
193
225
|
|
|
226
|
+
### Windows long-path temporary-file consumers
|
|
227
|
+
|
|
228
|
+
`pnpm package:smoke` includes `consumer-temp-file-probe.mjs` on Windows in
|
|
229
|
+
each normal root-only npm and pnpm installation. The existing bundled-package
|
|
230
|
+
CI jobs run it on Node 22, 24 and 26 using the collected root and native binding.
|
|
231
|
+
It imports `@openclaw/fs-safe/advanced` from the installed package, checks
|
|
232
|
+
compatible and real-native bounded cleanup, and verifies file round-trips,
|
|
233
|
+
path spelling, scoped rejection, and natural/explicit process-exit cleanup.
|
|
234
|
+
Native-off consumers also verify bounded cleanup refuses before creation.
|
|
235
|
+
Receipts, module hashes and source identity are recorded in `consumer-proof.json`.
|
|
236
|
+
|
|
237
|
+
### Windows public-permission/browser boundary proof
|
|
238
|
+
|
|
239
|
+
After `pnpm native:build` and `pnpm build`, Windows x64 contributors with Node
|
|
240
|
+
26 can run:
|
|
241
|
+
|
|
242
|
+
```powershell
|
|
243
|
+
$env:FS_SAFE_NATIVE_MODE = "require"
|
|
244
|
+
pnpm test test/permissions-windows-native.test.ts
|
|
245
|
+
node scripts/windows-permissions-browser-proof.mjs
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
The regression suite applies real ACLs only to task-owned temporary fixtures.
|
|
249
|
+
The browser proof downloads and SHA-256-verifies the affected core's pinned
|
|
250
|
+
layout module, strips TypeScript syntax, and executes the entire module with
|
|
251
|
+
real filesystem operations and this checkout's built permission inspector.
|
|
252
|
+
Its existing dependency seam redirects state and browser-profile roots into
|
|
253
|
+
temporary storage; it never consults an installed OpenClaw or Chrome profile.
|
|
254
|
+
Filesystem wrappers count and forward copy/profile-read operations.
|
|
255
|
+
|
|
256
|
+
The proof creates user-owned source, destination, and profile fixtures with
|
|
257
|
+
TrustedInstaller and other untrusted write grants. It checks refusal before
|
|
258
|
+
copying or reading profile bytes, and verifies private secure reads remain
|
|
259
|
+
strict. Ownership acceptance is covered by synthetic native/fallback descriptor
|
|
260
|
+
tests; changing a real fixture to TrustedInstaller ownership requires privileges
|
|
261
|
+
and is not attempted by this non-elevated proof.
|
|
262
|
+
|
|
194
263
|
## Checks
|
|
195
264
|
|
|
196
265
|
Run the complete repository gate before handoff:
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# File store
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
Store defaults and write options accept `allowDrvfsRenameRecovery`, including synchronous stores and private writes. Buffered/JSON writes compare bytes during [verified DrvFS recovery](atomic.md#drvfs-hidden-rename-recovery); streamed copies retain metadata checks.
|
|
3
5
|
`fileStore` is exported from `@openclaw/fs-safe/store`. It is a managed wrapper around `root()` for the common "store files under a directory at known modes, prune old ones, hand back absolute paths" pattern. Useful for caches, ingest staging, generated artifacts, anywhere the consumer wants object-style access plus stream and copy primitives.
|
|
4
6
|
|
|
5
7
|
```ts
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# JSON store
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
`jsonStore` and `fileStore().json()` accept `allowDrvfsRenameRecovery`, inherited from the parent store unless overridden. See [verified DrvFS recovery](atomic.md#drvfs-hidden-rename-recovery) before enabling this off-by-default exception.
|
|
3
5
|
`jsonStore` is exported from `@openclaw/fs-safe/store`. It is the single-path
|
|
4
6
|
convenience wrapper for `fileStore(...).json(...)`: a small read-modify-write
|
|
5
7
|
handle around a single JSON file. It bakes in atomic writes, explicit fallback
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# JSON files
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
`WriteJsonSyncOptions`, used by `writeJsonSync`, and `WriteJsonOptions`, used by `writeJson`, accept `allowDrvfsRenameRecovery` in their options. It is off by default; [verified DrvFS recovery](atomic.md#drvfs-hidden-rename-recovery) compares the serialized bytes and documents the residual inode-reuse risk.
|
|
3
5
|
`@openclaw/fs-safe/json` is the standalone JSON surface: strict and lenient read variants plus atomic JSON writes.
|
|
4
6
|
|
|
5
7
|
```ts
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# External outputs
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
For sibling staging, `allowDrvfsRenameRecovery` enables the [verified DrvFS exception](atomic.md#drvfs-hidden-rename-recovery). The callback output is hashed before rename and compared after recovery; the same identity, owner, mode, size and parent checks still apply.
|
|
3
5
|
`@openclaw/fs-safe/output` covers the case where another library insists on
|
|
4
6
|
writing to an absolute path you give it. Browser downloads, renderers, media
|
|
5
7
|
tools, and native libraries often have this shape:
|
|
@@ -42,7 +42,7 @@ POSIX remediation strings shell-quote paths with whitespace or metacharacters
|
|
|
42
42
|
and protect option-like paths with `--`, so they can be presented as commands
|
|
43
43
|
without letting the inspected pathname add shell syntax.
|
|
44
44
|
|
|
45
|
-
`inspectPathPermissions()` follows symlink targets for the effective mode but tells you whether the original path was a symlink. On POSIX it reports owner/group/world bits. On Windows it delegates to the ACL helpers below and also reports `ownerSid` plus `ownerTrusted` when ownership can be verified. `ownerTrusted` is true only for a local volume owned by the current user, LocalSystem,
|
|
45
|
+
`inspectPathPermissions()` follows symlink targets for the effective mode but tells you whether the original path was a symlink. On POSIX it reports owner/group/world bits. On Windows it delegates to the ACL helpers below and also reports `ownerSid` plus `ownerTrusted` when ownership can be verified. `ownerTrusted` is true only for a local volume owned by the current user, LocalSystem, built-in Administrators, or the exact TrustedInstaller service SID; remote filesystems fail closed. This remains a pathname reporting API with the fallbacks described below. `readSecureFile()` obtains descriptor-bound owner/DACL facts for the exact handle it reads, using native support or the packaged prebuilt .NET Framework helper in `auto` and `off` modes.
|
|
46
46
|
|
|
47
47
|
## Advanced Windows ACL helpers
|
|
48
48
|
|
|
@@ -139,8 +139,15 @@ principal classification and remediation command construction.
|
|
|
139
139
|
Missing or nonboolean locality leaves both inspectors unverified; only
|
|
140
140
|
`remote: false` establishes locality for owner trust. An explicit `remote: true`
|
|
141
141
|
retains the ACL report but never grants trusted ownership.
|
|
142
|
-
The
|
|
143
|
-
|
|
142
|
+
The public classifier trusts the current user, SYSTEM, and Administrators. It
|
|
143
|
+
also trusts the exact TrustedInstaller service SID
|
|
144
|
+
`S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464`
|
|
145
|
+
as owner. Its servicing grants are trusted only on TrustedInstaller-, SYSTEM-, or
|
|
146
|
+
Administrators-owned paths without an explicit current-user or current-container
|
|
147
|
+
write grant.
|
|
148
|
+
User-owned profiles with TrustedInstaller write grants still report group write
|
|
149
|
+
access; other service SIDs remain untrusted. Private-file and private-directory
|
|
150
|
+
admission retain their stricter policy.
|
|
144
151
|
The built-in query has a fixed 30-second process deadline. A command failure or timeout returns an
|
|
145
152
|
unverified result (`source: "unknown"`) so callers fail closed. Advanced callers
|
|
146
153
|
that inject a custom `exec` implementation own that executor's deadline.
|
|
@@ -176,10 +183,16 @@ apply to the inspected object, and deny ACEs never subtract coarse grants or
|
|
|
176
183
|
claim effective-access evaluation. Unsupported ACE layouts remain unverified.
|
|
177
184
|
|
|
178
185
|
When the native binding is available, `inspectPathPermissions()`
|
|
179
|
-
reads the owner and DACL directly with Windows security APIs
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
cannot classify
|
|
186
|
+
reads the owner and DACL directly with Windows security APIs and applies the
|
|
187
|
+
same public ACE classifier as the structured .NET fallback. Secure descriptor
|
|
188
|
+
reads and private creation retain their separate, narrower principal policy.
|
|
189
|
+
Descriptor forms it cannot classify completely fall back to the structured
|
|
190
|
+
.NET query; `mode: "off"` exercises that fallback deterministically.
|
|
191
|
+
|
|
192
|
+
Ownership does not establish private access or authorize a later operation.
|
|
193
|
+
Additional untrusted writers remain rejected even on a TrustedInstaller-owned
|
|
194
|
+
path. The inspector does not make a pathname race-free; use descriptor-bound
|
|
195
|
+
secure reads and private creation for their stricter contracts.
|
|
183
196
|
|
|
184
197
|
## Policy-free owner and DACL facts
|
|
185
198
|
|
|
@@ -12,13 +12,20 @@ const opened = await fs.open("large.log"); // FileHandle for strea
|
|
|
12
12
|
|
|
13
13
|
## What every read does
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
On POSIX, `root()` acquisition and `Root.open()`/read admission use asynchronous
|
|
16
|
+
metadata and canonicalization, including `~` expansion and bounded-read size
|
|
17
|
+
observations. Bun uses the native resolver on a worker to preserve physical path,
|
|
18
|
+
permission, and record-lock semantics. The optional native addon can still load
|
|
19
|
+
synchronously on first use. File data is read asynchronously.
|
|
20
|
+
Canonical paths retain native realpath spelling, including Windows short paths.
|
|
21
|
+
|
|
22
|
+
Windows retains synchronous metadata and final admission to preserve native
|
|
23
|
+
namespace and delete-sharing behavior. Explicit synchronous APIs and custom
|
|
24
|
+
`openRootFile` `ioFs` adapters also retain their synchronous contract. This does
|
|
25
|
+
not make every fs-safe operation nonblocking: stat/list/walk observation guards,
|
|
26
|
+
archive extraction, copy, publication, move, directory modes, and supporting lock,
|
|
27
|
+
queue, and secret-file operations may still use synchronous metadata or durability
|
|
28
|
+
calls.
|
|
22
29
|
|
|
23
30
|
Regardless of shape, every read goes through the same boundary checks:
|
|
24
31
|
|
|
@@ -197,7 +204,8 @@ for (const absolutePath of sourceFiles) {
|
|
|
197
204
|
try {
|
|
198
205
|
consume(fs.readFileSync(opened.fd));
|
|
199
206
|
} finally {
|
|
200
|
-
|
|
207
|
+
if (opened.close) opened.close();
|
|
208
|
+
else fs.closeSync(opened.fd);
|
|
201
209
|
}
|
|
202
210
|
}
|
|
203
211
|
```
|
|
@@ -213,7 +221,14 @@ are never cached. Other platforms, unavailable native support, other path
|
|
|
213
221
|
spellings, explicit canonical-root hints, custom filesystem adapters, and
|
|
214
222
|
symlink-following policies retain the ordinary per-open admission path.
|
|
215
223
|
|
|
216
|
-
Successful
|
|
224
|
+
Successful native batch opens include an idempotent `opened.close()` bound to
|
|
225
|
+
the descriptor's originating native closer. Always use it when present, including
|
|
226
|
+
after changing native configuration; otherwise close the Node-opened descriptor
|
|
227
|
+
with `fs.closeSync(opened.fd)`. The optional method preserves the existing result
|
|
228
|
+
fields and ordinary one-shot/fallback results. Do not close the same descriptor
|
|
229
|
+
through both methods.
|
|
230
|
+
|
|
231
|
+
Successful opens transfer descriptor ownership to the caller. Batch `close()` and
|
|
217
232
|
`Symbol.dispose` release retained root descriptors, are idempotent, and do not close
|
|
218
233
|
previously returned descriptors. Opening after close returns a validation
|
|
219
234
|
failure with code `invalid-path`. Keep batches scoped to one operation rather
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# root()
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
Root defaults and buffered write/create options accept `allowDrvfsRenameRecovery`. See the [verified DrvFS exception and residual reuse risk](atomic.md#drvfs-hidden-rename-recovery); the default remains strict.
|
|
3
5
|
`root()` is the primary entry point. It takes a trusted directory and returns a capability-style `Root` handle whose methods accept relative paths and refuse to escape the directory.
|
|
4
6
|
|
|
5
7
|
```ts
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Security model
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
The off-by-default [`allowDrvfsRenameRecovery` exception](atomic.md#drvfs-hidden-rename-recovery) releases continuous inode retention only after post-rename ENOENT on a descriptor-verified DrvFS mount. Exact metadata and available content must match afterward. Recycled identities and identical replacement content remain a residual risk; bounded retries do not bound scheduling pauses.
|
|
3
5
|
`fs-safe` is a library-level guardrail: a capability-style root handle for Node.js code that handles untrusted relative paths. It assumes the calling process already has whatever filesystem permissions it needs and aims to stop trivial path tricks from broadening that authority. It is not a sandbox and does not replace operating-system isolation.
|
|
4
6
|
|
|
5
7
|
The same shape exists in other languages: Go's [`os.Root` / `OpenInRoot`](https://go.dev/blog/osroot) and Rust's [`cap-std`](https://github.com/bytecodealliance/cap-std) both expose a root handle whose operations refuse to escape it. `fs-safe` is the Node-side equivalent: a single `root()` capability that carries the boundary across every read, write, move, and remove, instead of leaving each call site to redo `path.resolve(...).startsWith(...)` and hope.
|
|
@@ -2,7 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
For [Linux kernel write leases](platform-capabilities.md#linux-write-leases), `FileWriteLease.isHeld() === false` means “do not act on the file,” including while the kernel is still processing a lease break. The caller’s `SIGIO` handler still owns break notification.
|
|
4
4
|
|
|
5
|
-
`acquireFileLock()` and `withFileLock()` provide a cross-process file lock with retry and process-exit cleanup. The lock is
|
|
5
|
+
`acquireFileLock()` and `withFileLock()` provide a cross-process file lock with retry and process-exit cleanup. The lock is a sidecar file (e.g. `state.json` ↔ `state.json.lock`). Each contender writes and syncs the complete owner record, including its ownership token, to a private same-directory staging file before claiming the final name with native no-replace rename or a hardlink. Exactly one contender can publish; neither operation replaces an existing lock. This applies to raw and Root-backed acquisition, both async and sync.
|
|
6
|
+
|
|
7
|
+
With either publication primitive, a crash before publication leaves no final lock; a crash after publication leaves a complete owner record. The containing directory is synced where supported. These are process-crash guarantees, not a promise against every filesystem or storage device's power-loss behavior. Hardlink publication briefly has two names for the same complete file. Root-backed contenders recognize a matching staging inode and retry without reading or reclaiming that linked record; ordinary Root readers retain their hardlink policy. The staging link is removed before acquisition succeeds.
|
|
8
|
+
|
|
9
|
+
Directory persistence remains best-effort when directory read access or directory fsync is unavailable; this does not prevent otherwise permitted lock acquisition. Other I/O errors and revoked mutation authority still fail acquisition. After a crash leaves both hardlinks, guarded staging cleanup can remove the abandoned link before the existing stale-owner policy inspects the complete final record.
|
|
10
|
+
|
|
11
|
+
When native no-replace rename is unavailable and the filesystem refuses hardlinks with a recognized unsupported-operation error, acquisition falls back to exclusive creation (`O_EXCL`) of the final lock and writes and syncs the owner record through that descriptor. This preserves mutual exclusion on mounts such as FUSE, exFAT, SMB, and Android/Termux without hardlink support. A hardlink permission refusal also has to pass this exclusive open; actual directory permission errors, identity failures, and Root policy failures still propagate. Existing locks are never replaced.
|
|
12
|
+
|
|
13
|
+
This compatibility fallback has a small crash window: contenders can see an empty or partial owner record while it is being written, and a crash can leave that record behind. Unwritten bytes remain NUL-padded until the complete record is written, so even a finished JSON prefix with an unfinished ownership token remains unparseable. Empty records and records containing unwritten NUL padding remain contention and are never reclaimed by age, including through stale-recovery admission and custom parsers. Custom parsers are skipped for empty or NUL-padded records and otherwise retain their legacy-format and exception behavior; without a custom parser, malformed JSON also remains contention. An explicit `shouldReclaim` callback still receives `null` for these records so it can report application-specific diagnostics: `false` keeps waiting, while `true` fails closed with `file_lock_stale`. It never authorizes removal of an unverifiable record, even with `remove-if-unchanged`. Existing empty or incomplete locks remain untouched and require application-owned offline recovery after proving every possible writer has stopped (for example, Doctor can name the lock needing recovery).
|
|
14
|
+
|
|
15
|
+
Staging files use a reserved `.fs-safe-lock-<namespace>-<pid>-<random>.tmp` name. Before staging, an acquisition examines at most 64 directory entries for abandoned stages in its own target/hostname namespace. If the final record has a second link, publication recognition can scan farther and select at most one exact matching stage for the same guarded cleanup. It removes only identity-verified regular files whose local PID is confirmed absent; live or reused PIDs, other targets, unknown ownership, and ambiguous identities are preserved. Root mutation policies are checked against each candidate staging path before removal. A crash during hardlink publication can leave a second staging link; cleanup removes that link only, never the final lock. This bounded, best-effort cleanup may leave unrelated artifacts outside the opportunistic scan or artifacts on filesystems with inconclusive identity. Applications may remove remaining staging artifacts during explicit offline recovery after stopping every owner, including other hosts sharing the directory. No age-based lock or staging reclamation is used.
|
|
6
16
|
|
|
7
17
|
On Windows, both the target and an explicitly supplied `lockPath` reject NTFS
|
|
8
18
|
alternate-stream and directory-index namespace spellings before parent creation,
|
|
@@ -11,12 +21,7 @@ normal meaning, and ordinary colon-bearing POSIX paths remain valid.
|
|
|
11
21
|
|
|
12
22
|
JavaScript raw-sidecar creation passes mode `0o600` to that exclusive open. On POSIX, the process umask may further restrict the new file but cannot add group or other access. No pathname `chmod` fallback is used.
|
|
13
23
|
|
|
14
|
-
Root-backed lock records and reclaim guards
|
|
15
|
-
exclusively, including with the native backend. The native path retains the
|
|
16
|
-
admitted parent descriptor and removes incomplete claims only while their exact
|
|
17
|
-
identity remains owned. Ordinary Root creates still stage privately; lock records
|
|
18
|
-
use this internal exclusive-create path so racing contenders can retry without
|
|
19
|
-
an ambiguous rename outcome.
|
|
24
|
+
Root-backed lock records and reclaim guards retain their admitted parent and native cleanup receipt through publication. Their internal create path uses the same complete-record publication and the same exclusive-create compatibility fallback, while preserving Root mutation policy and exact identity checks. Ordinary Root creates retain their existing publication contract.
|
|
20
25
|
|
|
21
26
|
```ts
|
|
22
27
|
import { acquireFileLock } from "@openclaw/fs-safe/file-lock";
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Retained-directory staging
|
|
3
|
+
|
|
4
|
+
`stageFileInDirectory` accepts `allowDrvfsRenameRecovery`. It is off by default and retains exact staged bytes for the [verified DrvFS recovery check](atomic.md#drvfs-hidden-rename-recovery). Restrictive modes are applied before rename when this option is enabled.
|
|
3
5
|
description: "Prepare and publish one file while retaining its original directory for abort cleanup."
|
|
4
6
|
---
|
|
5
7
|
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Temp workspace isolation reference
|
|
2
|
+
|
|
3
|
+
This reference demonstrates one way to satisfy the lifetime isolation
|
|
4
|
+
precondition for `trustedWritableAncestors`. It qualifies only this configuration;
|
|
5
|
+
it does not establish that another deployment has equivalent isolation.
|
|
6
|
+
|
|
7
|
+
The trusted host runs as UID/GID 10001. Its private temp root is owned by that
|
|
8
|
+
identity at mode `0700`, beneath a root-owned volume directory at mode `2777`.
|
|
9
|
+
An untrusted process uses the same kernel UID/GID. A trusted root supervisor
|
|
10
|
+
places that process in separate mount, PID, network, IPC, and UTS namespaces,
|
|
11
|
+
enters a minimal filesystem root, drops all capabilities and supplementary
|
|
12
|
+
groups, and sets `no_new_privs` before starting untrusted code.
|
|
13
|
+
|
|
14
|
+
The untrusted view contains read-only runtime binaries, a namespace-local
|
|
15
|
+
`/proc`, and a separate writable `/workspace`. It has no mount of the trusted
|
|
16
|
+
temp ancestry, host `/proc`, inherited directory descriptors, or host control
|
|
17
|
+
sockets. Its environment contains no credentials. The PID namespace prevents
|
|
18
|
+
access to same-UID trusted host processes through host process paths. The
|
|
19
|
+
privileged namespace launcher and kernel are trusted; kernel escapes and
|
|
20
|
+
malicious administrators are outside this reference's threat model.
|
|
21
|
+
This proof addresses filesystem namespace integrity; it does not qualify
|
|
22
|
+
resource limits or a complete application sandbox.
|
|
23
|
+
|
|
24
|
+
The enforcement mechanism is the restricted filesystem and process view for
|
|
25
|
+
the entire untrusted process lifetime. A dedicated workload, matching UID,
|
|
26
|
+
private directory modes, or removal of an environment setting alone does not
|
|
27
|
+
provide that mechanism. Any untrusted descendants must remain under equivalent
|
|
28
|
+
restrictions, including during restart and recovery.
|
|
29
|
+
|
|
30
|
+
## Run the proof
|
|
31
|
+
|
|
32
|
+
Use a disposable Linux VM or an isolated Crabbox runner with Node, pnpm, Rust,
|
|
33
|
+
the package build prerequisites, and util-linux (`unshare`, `mount`, `chroot`,
|
|
34
|
+
and `setpriv`). The supervisor needs root to create the namespaces; the host
|
|
35
|
+
and untrusted filesystem operations run unprivileged. Build the package and
|
|
36
|
+
optionally its native binding first:
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
pnpm install --frozen-lockfile
|
|
40
|
+
pnpm native:build
|
|
41
|
+
pnpm build
|
|
42
|
+
sudo env "PATH=$PATH" pnpm proof:temp-isolation
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Do not run the privileged proof on a production host. It creates only temporary
|
|
46
|
+
fixtures and mounts inside its task-owned mount namespaces. The proof fails
|
|
47
|
+
when required isolation features are unavailable rather than skipping them.
|
|
48
|
+
|
|
49
|
+
The unsafe control confirms that the same UID can replace a private root when
|
|
50
|
+
given the writable ancestry. The isolated adversary then repeatedly attempts
|
|
51
|
+
root/workspace rename, removal/recreation, symlink substitution, and process-root
|
|
52
|
+
access while trusted workspace writes and reads continue. It must still be
|
|
53
|
+
able to write its permitted workspace. Protected directory identities must stay
|
|
54
|
+
unchanged. The adversary remains active across normal stop/start, a killed host
|
|
55
|
+
followed by recovery, and overlapping trusted hosts. Normally stopped workspaces
|
|
56
|
+
must clean up successfully; the killed host's workspace must remain intact.
|
|
57
|
+
The proof runs with native mode `off` and `auto`; `auto` exercises a native
|
|
58
|
+
binding only when one has been built and staged.
|
|
59
|
+
It stages a root-owned, read-only copy of the runtime for unprivileged trusted
|
|
60
|
+
workers, so the invoking checkout can remain private to the runner's login user.
|
|
61
|
+
The JSON result records actual native loading, runtime and reference hashes,
|
|
62
|
+
and the Node/kernel versions so the proof can be tied to the tested artifacts.
|
|
63
|
+
|
|
64
|
+
## Applying the result
|
|
65
|
+
|
|
66
|
+
Retain the exact source revision or candidate content hash, runtime image,
|
|
67
|
+
command, configuration, and JSON result. A production deployment needs a review
|
|
68
|
+
of its actual mounts, process namespaces, identities, privilege restrictions,
|
|
69
|
+
descriptor/socket handoffs, other writers, and lifecycle enforcement against
|
|
70
|
+
this contract. Revalidate after changes to that boundary. The library warning
|
|
71
|
+
reports reliance on external isolation and does not verify equivalence.
|
|
72
|
+
|
|
73
|
+
If equivalence cannot be established, keep `trustedWritableAncestors` disabled.
|