@openclaw/matrix 2026.11.6 → 2026.11.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.setup/{approval-handler.runtime-CshxBDs7.mjs → approval-handler.runtime-CKiMSdnX.mjs} +3 -3
- package/dist/.setup/{channel-OLndtGNE.mjs → channel-CZJeLUuu.mjs} +8 -8
- package/dist/.setup/{channel.runtime-CFSou_MS.mjs → channel.runtime-hpiGNile.mjs} +5 -5
- package/dist/.setup/{channel.setup-CqcEb6JR.mjs → channel.setup-Dc4G7kdF.mjs} +6 -2
- package/dist/.setup/{cli-CkMedN4Y.mjs → cli-DnLr6VVE.mjs} +8 -8
- package/dist/.setup/{cli-doctor-BVstkgJE.mjs → cli-doctor-DRM-8rZg.mjs} +1 -1
- package/dist/.setup/{cli-metadata-DN1E7yCf.mjs → cli-metadata-C9wZ_TOY.mjs} +1 -1
- package/dist/.setup/{client-Bk_tBqNp.mjs → client-CnPiPhTg.mjs} +4 -4
- package/dist/.setup/{client-Rlwtz1hG.mjs → client-CsgjDjyA.mjs} +2 -2
- package/dist/.setup/{client-bootstrap-Bhhri97J.mjs → client-bootstrap-CRN75TtW.mjs} +1 -1
- package/dist/.setup/{create-client-CzUtZgYF.mjs → create-client-C5bd0RUQ.mjs} +4 -4
- package/dist/.setup/{credentials-kT20jk_u.mjs → credentials-Byq2Kcqg.mjs} +1 -1
- package/dist/.setup/{crypto-runtime-BI9Pc344.mjs → crypto-runtime-EdW32JgS.mjs} +2 -2
- package/dist/.setup/{crypto-state-store-BZLlwkv_.mjs → crypto-state-store-m13QToc7.mjs} +2 -1
- package/dist/.setup/{crypto-store-ownership-CiQ1l_O7.mjs → crypto-store-ownership-CVeppnSH.mjs} +1 -1
- package/dist/.setup/{crypto-unsafe-state-doctor-CmF1X1dZ.mjs → crypto-unsafe-state-doctor-C_vhqxOm.mjs} +3 -3
- package/dist/.setup/{directory-live-DmkH9hcp.mjs → directory-live-Brv_PC6z.mjs} +1 -1
- package/dist/.setup/{draft-stream-DbTsJkoL.mjs → draft-stream-BAf9CYmE.mjs} +1 -1
- package/dist/.setup/{exec-approvals-CiGrN-cV.mjs → exec-approvals-ClD4sAHY.mjs} +2 -2
- package/dist/.setup/{file-sync-store-BpS12yaK.mjs → file-sync-store-Dilb8bVT.mjs} +2 -2
- package/dist/.setup/{idb-persistence-BTOsltD9.mjs → idb-persistence-COLTtrm_.mjs} +2 -2
- package/dist/.setup/{messages-DJDczJnC.mjs → messages-zsGFORuZ.mjs} +2 -2
- package/dist/.setup/{monitor-ZDbuZRVB.mjs → monitor-CdT6CsWk.mjs} +32 -18
- package/dist/.setup/{onboarding-DwhMV1fp.mjs → onboarding-FJiJ-X6s.mjs} +3 -3
- package/dist/.setup/{outbound-7iSmOloX.mjs → outbound-yjH1XHCr.mjs} +2 -2
- package/dist/.setup/{profile-update-Fu4u-aSC.mjs → profile-update-uRiRQTtX.mjs} +9 -4
- package/dist/.setup/{reaction-events-CBltCP52.mjs → reaction-events-DYJrx8eq.mjs} +3 -3
- package/dist/.setup/{resolve-targets-CWW9zTYp.mjs → resolve-targets-DwRQnBpN.mjs} +1 -1
- package/dist/.setup/{retired-state-JGUEBE72.mjs → retired-state-DohpBmxW.mjs} +1 -37
- package/dist/.setup/{room-info-DFDDmkBC.mjs → room-info-B6-Yo6I5.mjs} +3 -3
- package/dist/.setup/{sdk-ByFgA6Il.mjs → sdk-CPgBCtd2.mjs} +5 -5
- package/dist/.setup/{send-DiS4anyi.mjs → send-CCT72yQb.mjs} +7 -7
- package/dist/.setup/{setup-bootstrap-OfuocnF0.mjs → setup-bootstrap-CB0idLzk.mjs} +2 -2
- package/dist/.setup/{setup-core-CEQJRnym.mjs → setup-core-5sswwYZt.mjs} +1 -1
- package/dist/.setup/setup-plugin-api-BU7RNSl9.mjs +2 -0
- package/dist/.setup/sqlite-state-7WEloajv.mjs +37 -0
- package/dist/.setup/{startup-verification-UkaoSldm.mjs → startup-verification-zrBugJBv.mjs} +3 -2
- package/dist/.setup/{storage-C3N6YZIn.mjs → storage-BjNHtYwT.mjs} +4 -3
- package/dist/.setup/{sync-cache-state-BKVaKRzQ.mjs → sync-cache-state-CovS1oSw.mjs} +2 -1
- package/dist/.setup/{thread-bindings-BvoisBZE.mjs → thread-bindings-DZvpe83d.mjs} +4 -3
- package/dist/.setup/{tool-actions-TYBYDIkj.mjs → tool-actions-Dd8WTKXA.mjs} +10 -10
- package/dist/.setup/{verification-BhFA9xF6.mjs → verification-BKVxSiIq.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/doctor-contract-api.js +6 -5
- 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 +45 -1
- package/node_modules/@openclaw/fs-safe/README.md +4 -0
- package/node_modules/@openclaw/fs-safe/dist/absolute-path.js +2 -2
- package/node_modules/@openclaw/fs-safe/dist/advanced.d.ts +2 -2
- package/node_modules/@openclaw/fs-safe/dist/advanced.js +2 -2
- 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 +6 -0
- package/node_modules/@openclaw/fs-safe/dist/atomic.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/directory-mode-node.d.ts +5 -0
- package/node_modules/@openclaw/fs-safe/dist/directory-mode-node.js +13 -0
- package/node_modules/@openclaw/fs-safe/dist/directory-mode-options.d.ts +3 -0
- package/node_modules/@openclaw/fs-safe/dist/directory-mode-options.js +6 -0
- package/node_modules/@openclaw/fs-safe/dist/errors.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/errors.js +1 -0
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-admission.d.ts +0 -1
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-admission.js +1 -11
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-acquire.js +3 -3
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-stale-admission.js +2 -3
- package/node_modules/@openclaw/fs-safe/dist/file-store-boundary.d.ts +3 -3
- package/node_modules/@openclaw/fs-safe/dist/file-store-boundary.js +30 -4
- package/node_modules/@openclaw/fs-safe/dist/file-store-prune.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/file-store-prune.js +7 -1
- package/node_modules/@openclaw/fs-safe/dist/file-store-sync-directory.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/file-store-sync-directory.js +30 -4
- package/node_modules/@openclaw/fs-safe/dist/file-store-sync-write.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/file-store-sync-write.js +2 -0
- package/node_modules/@openclaw/fs-safe/dist/file-store.d.ts +2 -1
- package/node_modules/@openclaw/fs-safe/dist/file-store.js +5 -0
- package/node_modules/@openclaw/fs-safe/dist/guarded-mkdir.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/guarded-mkdir.js +9 -0
- package/node_modules/@openclaw/fs-safe/dist/json-store.d.ts +2 -1
- package/node_modules/@openclaw/fs-safe/dist/native-binding.d.ts +4 -1
- package/node_modules/@openclaw/fs-safe/dist/native-pinned-write.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/native-staged-file.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/native-staged-file.js +19 -13
- package/node_modules/@openclaw/fs-safe/dist/overwrite-file-handle.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/overwrite-file-handle.js +27 -5
- package/node_modules/@openclaw/fs-safe/dist/path-prefix.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/path-prefix.js +84 -7
- package/node_modules/@openclaw/fs-safe/dist/pinned-write-input.js +0 -11
- package/node_modules/@openclaw/fs-safe/dist/prepare-directory-mode.d.ts +9 -0
- package/node_modules/@openclaw/fs-safe/dist/prepare-directory-mode.js +61 -0
- package/node_modules/@openclaw/fs-safe/dist/private-temp-workspace.js +2 -1
- package/node_modules/@openclaw/fs-safe/dist/realpath.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/realpath.js +16 -0
- package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.d.ts +2 -1
- package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.js +8 -6
- package/node_modules/@openclaw/fs-safe/dist/replace-file-types.d.ts +2 -1
- package/node_modules/@openclaw/fs-safe/dist/replace-file.js +20 -13
- package/node_modules/@openclaw/fs-safe/dist/root-context.js +4 -1
- package/node_modules/@openclaw/fs-safe/dist/root-create-native.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/root-create-native.js +18 -9
- package/node_modules/@openclaw/fs-safe/dist/root-errors.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/root-errors.js +9 -0
- package/node_modules/@openclaw/fs-safe/dist/root-impl.js +4 -1
- package/node_modules/@openclaw/fs-safe/dist/root-mkdir-native.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/root-mkdir-native.js +35 -16
- package/node_modules/@openclaw/fs-safe/dist/root-path-existing.d.ts +6 -2
- package/node_modules/@openclaw/fs-safe/dist/root-path-existing.js +32 -20
- package/node_modules/@openclaw/fs-safe/dist/root-path.js +32 -26
- package/node_modules/@openclaw/fs-safe/dist/root-write-admission.js +4 -1
- package/node_modules/@openclaw/fs-safe/dist/secret-file.d.ts +2 -1
- package/node_modules/@openclaw/fs-safe/dist/secret-file.js +2 -0
- package/node_modules/@openclaw/fs-safe/dist/sibling-temp.d.ts +2 -1
- package/node_modules/@openclaw/fs-safe/dist/sibling-temp.js +5 -4
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-policy.d.ts +3 -2
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-policy.js +8 -9
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-stale-admission.js +3 -1
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-types.d.ts +2 -1
- package/node_modules/@openclaw/fs-safe/dist/text-atomic.d.ts +2 -1
- package/node_modules/@openclaw/fs-safe/dist/types.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/watch-hints.js +12 -3
- package/node_modules/@openclaw/fs-safe/dist/windows-security-helper.exe +0 -0
- package/node_modules/@openclaw/fs-safe/dist/write-file-handle.d.ts +0 -1
- package/node_modules/@openclaw/fs-safe/dist/write-file-handle.js +10 -12
- package/node_modules/@openclaw/fs-safe/docs/advanced.md +3 -3
- package/node_modules/@openclaw/fs-safe/docs/atomic.md +16 -3
- package/node_modules/@openclaw/fs-safe/docs/compiler-qualification.md +1 -1
- package/node_modules/@openclaw/fs-safe/docs/contributing.md +27 -18
- package/node_modules/@openclaw/fs-safe/docs/errors.md +3 -1
- package/node_modules/@openclaw/fs-safe/docs/file-store.md +14 -2
- package/node_modules/@openclaw/fs-safe/docs/in-place-write.md +31 -0
- package/node_modules/@openclaw/fs-safe/docs/install.md +1 -1
- package/node_modules/@openclaw/fs-safe/docs/json-store.md +6 -1
- package/node_modules/@openclaw/fs-safe/docs/json.md +5 -1
- package/node_modules/@openclaw/fs-safe/docs/path-prefix.md +14 -4
- package/node_modules/@openclaw/fs-safe/docs/public-api.md +4 -2
- package/node_modules/@openclaw/fs-safe/docs/secret-file.md +5 -1
- package/node_modules/@openclaw/fs-safe/docs/sidecar-lock.md +4 -0
- package/node_modules/@openclaw/fs-safe/docs/temp.md +9 -1
- package/node_modules/@openclaw/fs-safe/docs/types.md +5 -1
- package/node_modules/@openclaw/fs-safe/package.json +12 -12
- 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-4hHy1k4x.mjs +0 -2
|
@@ -6,7 +6,7 @@ import { FsSafeError } from "./errors.js";
|
|
|
6
6
|
import { assertNoNulPathInput, assertNoUnsafeDeviceReadPath, hasNodeErrorCode, isNotFoundPathError, isPathInside, } from "./path.js";
|
|
7
7
|
import { ROOT_PATH_ALIAS_POLICIES, resolveRootPath } from "./root-path.js";
|
|
8
8
|
import { admitPathInsideRoot } from "./root-boundary.js";
|
|
9
|
-
import { errorCauseOptions, outsideWorkspaceError, rootPathChangedError } from "./root-errors.js";
|
|
9
|
+
import { errorCauseOptions, outsideWorkspaceError, pathTraversalPermissionError, rootPathChangedError } from "./root-errors.js";
|
|
10
10
|
import { isDriveRelativePath } from "./safe-path-segment.js";
|
|
11
11
|
import { realpathSync } from "./realpath.js";
|
|
12
12
|
import { inspectFileIdentity } from "./strict-file-identity.js";
|
|
@@ -205,6 +205,9 @@ export async function resolvePathInRoot(root, relativePath, options) {
|
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
catch (error) {
|
|
208
|
+
const permissionError = pathTraversalPermissionError(error, rawAbsolutePath);
|
|
209
|
+
if (permissionError)
|
|
210
|
+
throw permissionError;
|
|
208
211
|
if (error instanceof FsSafeError && error.code === "symlink") {
|
|
209
212
|
throw error;
|
|
210
213
|
}
|
|
@@ -32,7 +32,7 @@ export type MissingWritableFileInRoot = {
|
|
|
32
32
|
};
|
|
33
33
|
export declare function isNativeCreateCollision(error: unknown): boolean;
|
|
34
34
|
/** Admit only an ordinary direct child; aliases keep the full resolver. */
|
|
35
|
-
export declare function tryMkdirNativeDirectChild(root: RootContext, relativePath: string): boolean;
|
|
35
|
+
export declare function tryMkdirNativeDirectChild(root: RootContext, relativePath: string, mode?: number): boolean;
|
|
36
36
|
export declare function tryMkdirRootNative(params: Creation): Promise<boolean>;
|
|
37
37
|
export declare function verifyMkdirDirectory(binding: NativeBinding, fd: number, pathname: string): void;
|
|
38
38
|
export declare function ensureNativeRootCurrent(root: RootContext): void;
|
|
@@ -56,7 +56,7 @@ import { randomUUID } from "node:crypto";
|
|
|
56
56
|
import fsAsync from "node:fs/promises";
|
|
57
57
|
import path from "node:path";
|
|
58
58
|
import { assertSyncDirectoryGuard, inspectDirectoryIdentitySync } from "./directory-guard.js";
|
|
59
|
-
import { nodeDirectorySearchOnlyFlags } from "./directory-mode-node.js";
|
|
59
|
+
import { finalizeCreatedDirectoryModeSync, nodeDirectorySearchOnlyFlags } from "./directory-mode-node.js";
|
|
60
60
|
import { assertDarwinCreationAcl, assertPrivateDirectory } from "./creation-boundary.js";
|
|
61
61
|
import { assertMutationNotDenied } from "./deny-mutations.js";
|
|
62
62
|
import { FsSafeError } from "./errors.js";
|
|
@@ -295,7 +295,7 @@ async function withNativeDirectory(params, operation, discard) {
|
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
297
|
/** Admit only an ordinary direct child; aliases keep the full resolver. */
|
|
298
|
-
export function tryMkdirNativeDirectChild(root, relativePath) {
|
|
298
|
+
export function tryMkdirNativeDirectChild(root, relativePath, mode) {
|
|
299
299
|
if (!isSafePathSegment(relativePath, { allowDotPrefix: true }) || relativePath.endsWith(".") ||
|
|
300
300
|
getFsSafeTestHooks()?.beforeRootFallbackMutation)
|
|
301
301
|
return false;
|
|
@@ -311,7 +311,7 @@ export function tryMkdirNativeDirectChild(root, relativePath) {
|
|
|
311
311
|
return false;
|
|
312
312
|
}
|
|
313
313
|
try {
|
|
314
|
-
mkdirNativeRootChild({ root, target });
|
|
314
|
+
mkdirNativeRootChild({ root, target }, mode);
|
|
315
315
|
return true;
|
|
316
316
|
}
|
|
317
317
|
catch (error) {
|
|
@@ -420,7 +420,7 @@ function ensureNativeRootCurrentLegacy(root, binding) {
|
|
|
420
420
|
__disposeResources(env_4);
|
|
421
421
|
}
|
|
422
422
|
}
|
|
423
|
-
function mkdirNativeRootChild(params) {
|
|
423
|
+
function mkdirNativeRootChild(params, mode) {
|
|
424
424
|
const env_5 = { stack: [], error: void 0, hasError: false };
|
|
425
425
|
try {
|
|
426
426
|
const binding = getNativeBinding("openBeneath", "mkdirChildBeneath");
|
|
@@ -430,19 +430,28 @@ function mkdirNativeRootChild(params) {
|
|
|
430
430
|
rootPath: params.root.rootReal, rootIdentity: params.root.rootIdentity,
|
|
431
431
|
}), false);
|
|
432
432
|
verifyMkdirDirectory(binding, rootOwner.fd, params.root.rootReal);
|
|
433
|
-
const flags = (nodeDirectorySearchOnlyFlags()?.flags ?? fs.constants.O_RDONLY) |
|
|
433
|
+
const flags = (mode === undefined ? nodeDirectorySearchOnlyFlags()?.flags ?? fs.constants.O_RDONLY : fs.constants.O_RDONLY) |
|
|
434
434
|
(fs.constants.O_DIRECTORY ?? 0) | (fs.constants.O_NOFOLLOW ?? 0);
|
|
435
435
|
const name = path.basename(params.target);
|
|
436
436
|
// The admitted Root is already this operation's immediate parent. Retain
|
|
437
437
|
// both handles through the same fresh pathname and canonical identity fences.
|
|
438
438
|
const child = binding.mkdirOpenChildBeneath
|
|
439
|
-
? binding.mkdirOpenChildBeneath(rootOwner.fd, name, 0o777, flags)
|
|
440
|
-
:
|
|
439
|
+
? binding.mkdirOpenChildBeneath(rootOwner.fd, name, mode ?? 0o777, flags)
|
|
440
|
+
: {
|
|
441
|
+
created: binding.mkdirChildBeneath(rootOwner.fd, name, mode ?? 0o777),
|
|
442
|
+
fd: binding.openBeneath(rootOwner.fd, name, flags).fd,
|
|
443
|
+
};
|
|
441
444
|
const close = captureNativeFdClose(binding);
|
|
442
|
-
const childOwner = __addDisposableResource(env_5, { [Symbol.dispose]() { close(child); } }, false);
|
|
445
|
+
const childOwner = __addDisposableResource(env_5, { [Symbol.dispose]() { close(child.fd); } }, false);
|
|
443
446
|
assertRootIdentityCurrentSync(params.root);
|
|
444
|
-
verifyMkdirDirectory(binding, child, params.target);
|
|
447
|
+
verifyMkdirDirectory(binding, child.fd, params.target);
|
|
445
448
|
verifyMkdirDirectory(binding, rootOwner.fd, params.root.rootReal);
|
|
449
|
+
if (mode !== undefined && child.created) {
|
|
450
|
+
finalizeCreatedDirectoryModeSync(child, mode);
|
|
451
|
+
verifyMkdirDirectory(binding, child.fd, params.target);
|
|
452
|
+
verifyMkdirDirectory(binding, rootOwner.fd, params.root.rootReal);
|
|
453
|
+
assertRootIdentityCurrentSync(params.root);
|
|
454
|
+
}
|
|
446
455
|
}
|
|
447
456
|
catch (e_5) {
|
|
448
457
|
env_5.error = e_5;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { FsSafeError, type FsSafeErrorDetails } from "./errors.js";
|
|
2
2
|
export declare function fileNotFoundError(cause?: unknown, details?: FsSafeErrorDetails): FsSafeError;
|
|
3
3
|
export declare function outsideWorkspaceError(): FsSafeError;
|
|
4
|
+
/** Classify raw traversal denials without disguising an established policy failure. */
|
|
5
|
+
export declare function pathTraversalPermissionError(error: unknown, targetPath: string): FsSafeError | undefined;
|
|
4
6
|
export declare function rootPathChangedError(cause?: Error): FsSafeError;
|
|
5
7
|
export declare function directoryComponentNotDirectoryError(cause?: unknown): FsSafeError;
|
|
6
8
|
export declare function hardlinkedPathNotAllowedError(): FsSafeError;
|
|
@@ -15,6 +15,15 @@ export function fileNotFoundError(cause, details) {
|
|
|
15
15
|
export function outsideWorkspaceError() {
|
|
16
16
|
return new FsSafeError("outside-workspace", "file is outside workspace root");
|
|
17
17
|
}
|
|
18
|
+
/** Classify raw traversal denials without disguising an established policy failure. */
|
|
19
|
+
export function pathTraversalPermissionError(error, targetPath) {
|
|
20
|
+
if (error instanceof FsSafeError)
|
|
21
|
+
return error.code === "permission-denied" ? error : undefined;
|
|
22
|
+
if (!hasNodeErrorCode(error, "EACCES") && !hasNodeErrorCode(error, "EPERM"))
|
|
23
|
+
return;
|
|
24
|
+
const deniedPath = isNodeError(error) && typeof error.path === "string" ? error.path : targetPath;
|
|
25
|
+
return new FsSafeError("permission-denied", `permission denied while resolving ${deniedPath}`, errorCauseOptions(error));
|
|
26
|
+
}
|
|
18
27
|
export function rootPathChangedError(cause) {
|
|
19
28
|
return new FsSafeError("path-mismatch", "root path changed during operation", { cause });
|
|
20
29
|
}
|
|
@@ -90,7 +90,7 @@ import { listDirectoryPath, openRootDirectoryListing } from "./root-directory-li
|
|
|
90
90
|
import { statResolvedPathInRoot } from "./root-path-stat.js";
|
|
91
91
|
import { entriesInRoot } from "./root-entries.js";
|
|
92
92
|
import { assertRootIdentityCurrent, assertRootIdentityCurrentSync, assertValidRootDestinationPath, assertValidRootRelativePath, createRootObservationGuard, ensureTrailingSep, expandRelativePathWithHome, resolvePathInRoot, resolveRootContext, rootRelativeReadPath, } from "./root-context.js";
|
|
93
|
-
import { errorCauseOptions, fileNotFoundError, hardlinkedPathNotAllowedError, isAlreadyExistsError, normalizePinnedPathError, normalizePinnedWriteError, outsideWorkspaceError, } from "./root-errors.js";
|
|
93
|
+
import { errorCauseOptions, fileNotFoundError, hardlinkedPathNotAllowedError, isAlreadyExistsError, normalizePinnedPathError, normalizePinnedWriteError, outsideWorkspaceError, pathTraversalPermissionError, } from "./root-errors.js";
|
|
94
94
|
import { getFsSafeTestHooks } from "./test-hooks.js";
|
|
95
95
|
import { stringifyJsonDocument } from "./json-stringify.js";
|
|
96
96
|
import { walkRoot } from "./root-walk.js";
|
|
@@ -1078,6 +1078,9 @@ async function resolvePinnedRootPathInRoot(root, params) {
|
|
|
1078
1078
|
resolved = await (params.removalReceipts ? resolveRootPathForRemoval(resolution, params.removalReceipts) : resolveRootPath(resolution));
|
|
1079
1079
|
}
|
|
1080
1080
|
catch (err) {
|
|
1081
|
+
const permissionError = pathTraversalPermissionError(err, params.relativePath);
|
|
1082
|
+
if (permissionError)
|
|
1083
|
+
throw permissionError;
|
|
1081
1084
|
if (err instanceof FsSafeError && err.code === "symlink")
|
|
1082
1085
|
throw err;
|
|
1083
1086
|
throw new FsSafeError("path-alias", "path alias escape blocked", { cause: err });
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type RootContext } from "./root-context.js";
|
|
2
|
-
export declare function tryMkdirNativeParents(root: RootContext, relativePath: string): boolean;
|
|
2
|
+
export declare function tryMkdirNativeParents(root: RootContext, relativePath: string, mode?: number): boolean;
|
|
@@ -53,7 +53,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
53
53
|
import fs from "node:fs";
|
|
54
54
|
import path from "node:path";
|
|
55
55
|
import { inspectDirectoryIdentitySync } from "./directory-guard.js";
|
|
56
|
-
import { nodeDirectorySearchOnlyFlags } from "./directory-mode-node.js";
|
|
56
|
+
import { finalizeCreatedDirectoryModeSync, nodeDirectorySearchOnlyFlags } from "./directory-mode-node.js";
|
|
57
57
|
import { FsSafeError } from "./errors.js";
|
|
58
58
|
import { getNativeBinding } from "./native.js";
|
|
59
59
|
import { captureNativeFdClose } from "./native-binding.js";
|
|
@@ -67,9 +67,9 @@ import { isSafePathSegment } from "./safe-path-segment.js";
|
|
|
67
67
|
import { inspectFileIdentitySync } from "./strict-file-identity.js";
|
|
68
68
|
import { getFsSafeTestHooks } from "./test-hooks.js";
|
|
69
69
|
import { pathForWindowsFilesystem } from "./windows-path-alias.js";
|
|
70
|
-
export function tryMkdirNativeParents(root, relativePath) {
|
|
70
|
+
export function tryMkdirNativeParents(root, relativePath, mode) {
|
|
71
71
|
try {
|
|
72
|
-
return mkdirOrdinaryNativeParents(root, relativePath);
|
|
72
|
+
return mkdirOrdinaryNativeParents(root, relativePath, mode);
|
|
73
73
|
}
|
|
74
74
|
catch (error) {
|
|
75
75
|
if (hasNodeErrorCode(error, "ENOTDIR"))
|
|
@@ -77,7 +77,7 @@ export function tryMkdirNativeParents(root, relativePath) {
|
|
|
77
77
|
throw error;
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
-
function mkdirOrdinaryNativeParents(root, relativePath) {
|
|
80
|
+
function mkdirOrdinaryNativeParents(root, relativePath, mode) {
|
|
81
81
|
if (getFsSafeTestHooks()?.beforeRootFallbackMutation)
|
|
82
82
|
return false;
|
|
83
83
|
const segments = relativePath.split(path.sep === "\\" ? /[\\/]/ : "/");
|
|
@@ -102,7 +102,7 @@ function mkdirOrdinaryNativeParents(root, relativePath) {
|
|
|
102
102
|
catch (error) {
|
|
103
103
|
// Reuse this exact Root snapshot and failed parent observation without an
|
|
104
104
|
// intervening await. All opened ancestors still receive fresh native fences.
|
|
105
|
-
return hasNodeErrorCode(error, "ENOENT") ? mkdirMissingParents(root, segments, rootStat) : false;
|
|
105
|
+
return hasNodeErrorCode(error, "ENOENT") ? mkdirMissingParents(root, segments, rootStat, mode) : false;
|
|
106
106
|
}
|
|
107
107
|
try {
|
|
108
108
|
if (realpathSync.native(pathForWindowsFilesystem(parentPath)) !== parentPath)
|
|
@@ -111,12 +111,12 @@ function mkdirOrdinaryNativeParents(root, relativePath) {
|
|
|
111
111
|
catch {
|
|
112
112
|
return false;
|
|
113
113
|
}
|
|
114
|
-
return mkdirExistingParent(root, segments, parentIdentity);
|
|
114
|
+
return mkdirExistingParent(root, segments, parentIdentity, mode);
|
|
115
115
|
}
|
|
116
116
|
/** Ordinary missing suffixes need no policy callbacks or repeated path resolution. */
|
|
117
|
-
function mkdirMissingParents(root, segments, rootStat) {
|
|
117
|
+
function mkdirMissingParents(root, segments, rootStat, mode) {
|
|
118
118
|
const binding = getNativeBinding("openBeneath", "mkdirChildBeneath");
|
|
119
|
-
if (!binding?.openBeneath || !binding.mkdirOpenChildBeneath)
|
|
119
|
+
if (!binding?.openBeneath || !binding.mkdirChildBeneath || (!binding.mkdirOpenChildBeneath && mode === undefined))
|
|
120
120
|
return false;
|
|
121
121
|
let parentDepth = segments.length - 2;
|
|
122
122
|
let parentPath;
|
|
@@ -156,7 +156,7 @@ function mkdirMissingParents(root, segments, rootStat) {
|
|
|
156
156
|
if (errors.length)
|
|
157
157
|
throw new AggregateError(errors, "mkdir directory close failed");
|
|
158
158
|
} }, false);
|
|
159
|
-
const flags = (nodeDirectorySearchOnlyFlags()?.flags ?? fs.constants.O_RDONLY) |
|
|
159
|
+
const flags = (mode === undefined ? nodeDirectorySearchOnlyFlags()?.flags ?? fs.constants.O_RDONLY : fs.constants.O_RDONLY) |
|
|
160
160
|
(fs.constants.O_DIRECTORY ?? 0) | (fs.constants.O_NOFOLLOW ?? 0);
|
|
161
161
|
let current = rootOwner.fd;
|
|
162
162
|
if (parentDepth > 0) {
|
|
@@ -172,12 +172,21 @@ function mkdirMissingParents(root, segments, rootStat) {
|
|
|
172
172
|
};
|
|
173
173
|
assertCurrent();
|
|
174
174
|
for (const segment of segments.slice(parentDepth)) {
|
|
175
|
-
const child = binding.mkdirOpenChildBeneath
|
|
175
|
+
const child = binding.mkdirOpenChildBeneath
|
|
176
|
+
? binding.mkdirOpenChildBeneath(current, segment, mode ?? 0o777, flags)
|
|
177
|
+
: {
|
|
178
|
+
created: binding.mkdirChildBeneath(current, segment, mode ?? 0o777),
|
|
179
|
+
fd: binding.openBeneath(current, segment, flags).fd,
|
|
180
|
+
};
|
|
176
181
|
parentPath = path.join(parentPath, segment);
|
|
177
182
|
directories.push({ fd: child.fd, pathname: parentPath });
|
|
178
183
|
// Retain every ancestor until the complete suffix is admitted. The
|
|
179
184
|
// post-create fence also precedes the next synchronous child mutation.
|
|
180
185
|
assertCurrent();
|
|
186
|
+
if (mode !== undefined && child.created) {
|
|
187
|
+
finalizeCreatedDirectoryModeSync(child, mode);
|
|
188
|
+
assertCurrent();
|
|
189
|
+
}
|
|
181
190
|
current = child.fd;
|
|
182
191
|
}
|
|
183
192
|
return true;
|
|
@@ -196,7 +205,7 @@ function mkdirMissingParents(root, segments, rootStat) {
|
|
|
196
205
|
throw error;
|
|
197
206
|
}
|
|
198
207
|
}
|
|
199
|
-
function mkdirExistingParent(root, segments, parentIdentity) {
|
|
208
|
+
function mkdirExistingParent(root, segments, parentIdentity, mode) {
|
|
200
209
|
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
201
210
|
try {
|
|
202
211
|
const target = path.join(root.rootReal, ...segments);
|
|
@@ -209,7 +218,7 @@ function mkdirExistingParent(root, segments, parentIdentity) {
|
|
|
209
218
|
rootPath: root.rootReal, rootIdentity: root.rootIdentity,
|
|
210
219
|
}), false);
|
|
211
220
|
verifyMkdirDirectory(binding, rootOwner.fd, root.rootReal);
|
|
212
|
-
const flags = (nodeDirectorySearchOnlyFlags()?.flags ?? fs.constants.O_RDONLY) |
|
|
221
|
+
const flags = (mode === undefined ? nodeDirectorySearchOnlyFlags()?.flags ?? fs.constants.O_RDONLY : fs.constants.O_RDONLY) |
|
|
213
222
|
(fs.constants.O_DIRECTORY ?? 0) | (fs.constants.O_NOFOLLOW ?? 0);
|
|
214
223
|
const close = captureNativeFdClose(binding);
|
|
215
224
|
const parent = binding.openBeneath(rootOwner.fd, segments.slice(0, -1).join("/"), flags).fd;
|
|
@@ -219,14 +228,24 @@ function mkdirExistingParent(root, segments, parentIdentity) {
|
|
|
219
228
|
assertRootIdentityCurrentSync(root);
|
|
220
229
|
const name = segments.at(-1);
|
|
221
230
|
const child = binding.mkdirOpenChildBeneath
|
|
222
|
-
? binding.mkdirOpenChildBeneath(parent, name, 0o777, flags)
|
|
223
|
-
:
|
|
224
|
-
|
|
231
|
+
? binding.mkdirOpenChildBeneath(parent, name, mode ?? 0o777, flags)
|
|
232
|
+
: {
|
|
233
|
+
created: binding.mkdirChildBeneath(parent, name, mode ?? 0o777),
|
|
234
|
+
fd: binding.openBeneath(parent, name, flags).fd,
|
|
235
|
+
};
|
|
236
|
+
const childOwner = __addDisposableResource(env_2, { [Symbol.dispose]() { close(child.fd); } }, false);
|
|
225
237
|
assertRootIdentityCurrentSync(root);
|
|
226
|
-
verifyMkdirDirectory(binding, child, target);
|
|
238
|
+
verifyMkdirDirectory(binding, child.fd, target);
|
|
227
239
|
inspectDirectoryIdentitySync(parentPath, parentIdentity);
|
|
228
240
|
verifyMkdirDirectory(binding, parent, parentPath);
|
|
229
241
|
verifyMkdirDirectory(binding, rootOwner.fd, root.rootReal);
|
|
242
|
+
if (mode !== undefined && child.created) {
|
|
243
|
+
finalizeCreatedDirectoryModeSync(child, mode);
|
|
244
|
+
verifyMkdirDirectory(binding, child.fd, target);
|
|
245
|
+
verifyMkdirDirectory(binding, parent, parentPath);
|
|
246
|
+
verifyMkdirDirectory(binding, rootOwner.fd, root.rootReal);
|
|
247
|
+
assertRootIdentityCurrentSync(root);
|
|
248
|
+
}
|
|
230
249
|
return true;
|
|
231
250
|
}
|
|
232
251
|
catch (e_2) {
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import { runAsync, runSync, type Procedure } from "./atomic-io.js";
|
|
1
2
|
import { type RootBoundaryIdentity } from "./root-boundary.js";
|
|
3
|
+
export declare const synchronousRootTraversal: boolean;
|
|
4
|
+
export declare const runRootTraversal: typeof runAsync | typeof runSync;
|
|
2
5
|
export declare function absolutePathWithRawSegments(candidate: string): string;
|
|
3
6
|
export declare function rawPathRelativeToCanonicalRoot(candidate: string, rootCanonicalPath: string, options?: {
|
|
4
7
|
rejectSymlinks?: boolean;
|
|
5
8
|
rejectFinalSymlink?: boolean;
|
|
6
9
|
rootIdentity?: RootBoundaryIdentity;
|
|
7
|
-
}): string | undefined
|
|
10
|
+
}, synchronous?: boolean): Procedure<string | undefined>;
|
|
8
11
|
export declare function resolvePathViaExistingAncestor(targetPath: string): Promise<string>;
|
|
9
12
|
export declare function resolvePathViaExistingAncestorSync(targetPath: string): string;
|
|
10
13
|
export type RootPathMetadataMode = "native" | "ordinary";
|
|
11
14
|
export declare function resolveExistingAncestor(targetPath: string, mode: RootPathMetadataMode, preserveRawSegments?: boolean, remainingHops?: number): string;
|
|
12
|
-
export declare function
|
|
15
|
+
export declare function resolveExistingAncestorProcedure(targetPath: string, mode: RootPathMetadataMode, synchronous: boolean, preserveRawSegments?: boolean, remainingHops?: number): Procedure<string>;
|
|
16
|
+
export declare function resolveSymlinkHopPath(symlinkPath: string, mode: RootPathMetadataMode, rejectUnresolved?: boolean, remainingHops?: number, synchronous?: boolean): Procedure<string>;
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
+
import asyncFs from "node:fs/promises";
|
|
2
3
|
import path from "node:path";
|
|
4
|
+
import { runAsync, runSync, wait } from "./atomic-io.js";
|
|
3
5
|
import { FsSafeError } from "./errors.js";
|
|
4
6
|
import { formatErrorDetail } from "./error-detail.js";
|
|
5
7
|
import { isNotFoundPathError, isPathInside, isSymlinkOpenError } from "./path.js";
|
|
6
|
-
import { realpathSync } from "./realpath.js";
|
|
8
|
+
import { realpathNative, realpathSync } from "./realpath.js";
|
|
7
9
|
import { assertNoWindowsPathAlias, isForeignWindowsShareOrDevicePath, pathForWindowsFilesystem, resolvePathFromBasePreservingWindowsRoot, resolvePathPreservingWindowsRoot, } from "./windows-path-alias.js";
|
|
8
10
|
import { admitPathInsideRoot } from "./root-boundary.js";
|
|
9
11
|
import { errorCauseOptions } from "./root-errors.js";
|
|
12
|
+
// Windows native realpath denies delete sharing. Preserve read/publication
|
|
13
|
+
// scheduling until canonicalization can safely overlap replacement.
|
|
14
|
+
export const synchronousRootTraversal = process.platform === "win32";
|
|
15
|
+
export const runRootTraversal = synchronousRootTraversal ? runSync : runAsync;
|
|
10
16
|
export function absolutePathWithRawSegments(candidate) {
|
|
11
17
|
if (path.sep !== "\\") {
|
|
12
18
|
if (path.isAbsolute(candidate))
|
|
@@ -24,7 +30,7 @@ export function absolutePathWithRawSegments(candidate) {
|
|
|
24
30
|
const base = drive ? path.resolve(drive) : process.cwd();
|
|
25
31
|
return `${base}${base.endsWith(path.sep) ? "" : path.sep}${raw.slice(drive.length)}`;
|
|
26
32
|
}
|
|
27
|
-
export function rawPathRelativeToCanonicalRoot(candidate, rootCanonicalPath, options = {}) {
|
|
33
|
+
export function* rawPathRelativeToCanonicalRoot(candidate, rootCanonicalPath, options = {}, synchronous = true) {
|
|
28
34
|
assertNoWindowsPathAlias(candidate);
|
|
29
35
|
assertNoWindowsPathAlias(rootCanonicalPath);
|
|
30
36
|
const absolute = absolutePathWithRawSegments(candidate);
|
|
@@ -43,7 +49,7 @@ export function rawPathRelativeToCanonicalRoot(candidate, rootCanonicalPath, opt
|
|
|
43
49
|
let isSymlink = false;
|
|
44
50
|
try {
|
|
45
51
|
const operationPath = pathForWindowsFilesystem(prefix);
|
|
46
|
-
const stat = fs.lstatSync(operationPath);
|
|
52
|
+
const stat = synchronous ? fs.lstatSync(operationPath) : yield* wait(asyncFs.lstat(operationPath));
|
|
47
53
|
isSymlink = stat.isSymbolicLink();
|
|
48
54
|
// Check the original leaf before canonicalization can erase an entry alias.
|
|
49
55
|
if (isSymlink && options.rejectFinalSymlink && index === finalComponentIndex) {
|
|
@@ -52,10 +58,11 @@ export function rawPathRelativeToCanonicalRoot(candidate, rootCanonicalPath, opt
|
|
|
52
58
|
if (!isSymlink && !stat.isDirectory() && index < segments.length - 1)
|
|
53
59
|
return undefined;
|
|
54
60
|
traversedSymlink ||= isSymlink;
|
|
55
|
-
canonical = realpathSync.native(operationPath);
|
|
61
|
+
canonical = synchronous ? realpathSync.native(operationPath) : yield* wait(realpathNative(operationPath));
|
|
56
62
|
assertNoWindowsPathAlias(canonical);
|
|
57
63
|
if (isSymlink && index < segments.length - 1 &&
|
|
58
|
-
!fs.statSync(pathForWindowsFilesystem(canonical))
|
|
64
|
+
!(synchronous ? fs.statSync(pathForWindowsFilesystem(canonical))
|
|
65
|
+
: yield* wait(asyncFs.stat(pathForWindowsFilesystem(canonical)))).isDirectory())
|
|
59
66
|
return undefined;
|
|
60
67
|
if (isSymlink && !isPathInside(rootCanonicalPath, canonical) && !isPathInside(canonical, rootCanonicalPath)) {
|
|
61
68
|
throw new FsSafeError("outside-workspace", `symlink prefix resolves outside the root ancestry: ${formatErrorDetail(candidate)}`);
|
|
@@ -84,9 +91,10 @@ export function rawPathRelativeToCanonicalRoot(candidate, rootCanonicalPath, opt
|
|
|
84
91
|
}
|
|
85
92
|
return undefined;
|
|
86
93
|
}
|
|
87
|
-
function pathExists(targetPath) {
|
|
94
|
+
function* pathExists(targetPath, synchronous) {
|
|
88
95
|
try {
|
|
89
|
-
return fs.lstatSync(pathForWindowsFilesystem(targetPath), { throwIfNoEntry: false })
|
|
96
|
+
return (synchronous ? fs.lstatSync(pathForWindowsFilesystem(targetPath), { throwIfNoEntry: false })
|
|
97
|
+
: yield* wait(asyncFs.lstat(pathForWindowsFilesystem(targetPath)))) !== undefined;
|
|
90
98
|
}
|
|
91
99
|
catch (error) {
|
|
92
100
|
if (isNotFoundPathError(error)) {
|
|
@@ -96,17 +104,20 @@ function pathExists(targetPath) {
|
|
|
96
104
|
}
|
|
97
105
|
}
|
|
98
106
|
export async function resolvePathViaExistingAncestor(targetPath) {
|
|
99
|
-
return
|
|
107
|
+
return runRootTraversal(resolveExistingAncestorProcedure(targetPath, "native", synchronousRootTraversal));
|
|
100
108
|
}
|
|
101
|
-
function
|
|
109
|
+
function* ordinaryExists(targetPath) {
|
|
102
110
|
return fs.existsSync(pathForWindowsFilesystem(targetPath));
|
|
103
111
|
}
|
|
104
112
|
export function resolvePathViaExistingAncestorSync(targetPath) {
|
|
105
113
|
return resolveExistingAncestor(targetPath, "ordinary");
|
|
106
114
|
}
|
|
107
115
|
export function resolveExistingAncestor(targetPath, mode, preserveRawSegments = false, remainingHops = 64) {
|
|
108
|
-
|
|
109
|
-
|
|
116
|
+
return runSync(resolveExistingAncestorProcedure(targetPath, mode, true, preserveRawSegments, remainingHops));
|
|
117
|
+
}
|
|
118
|
+
export function* resolveExistingAncestorProcedure(targetPath, mode, synchronous, preserveRawSegments = false, remainingHops = 64) {
|
|
119
|
+
const exists = (pathname) => mode === "native" || preserveRawSegments
|
|
120
|
+
? pathExists(pathname, synchronous) : ordinaryExists(pathname);
|
|
110
121
|
assertNoWindowsPathAlias(targetPath);
|
|
111
122
|
const normalized = resolvePathPreservingWindowsRoot(targetPath);
|
|
112
123
|
assertNoWindowsPathAlias(normalized);
|
|
@@ -114,22 +125,23 @@ export function resolveExistingAncestor(targetPath, mode, preserveRawSegments =
|
|
|
114
125
|
let cursor = candidate;
|
|
115
126
|
const filesystemRoot = path.parse(candidate).root;
|
|
116
127
|
while (cursor !== filesystemRoot &&
|
|
117
|
-
!exists(cursor)) {
|
|
128
|
+
!(yield* exists(cursor))) {
|
|
118
129
|
cursor = path.dirname(cursor);
|
|
119
130
|
}
|
|
120
|
-
if (!exists(cursor)) {
|
|
131
|
+
if (!(yield* exists(cursor))) {
|
|
121
132
|
return normalized;
|
|
122
133
|
}
|
|
123
134
|
let rawResolvedAncestor;
|
|
124
135
|
try {
|
|
125
|
-
rawResolvedAncestor =
|
|
136
|
+
rawResolvedAncestor = synchronous ? realpathSync.native(pathForWindowsFilesystem(cursor))
|
|
137
|
+
: yield* wait(realpathNative(pathForWindowsFilesystem(cursor)));
|
|
126
138
|
}
|
|
127
139
|
catch (error) {
|
|
128
140
|
if (!preserveRawSegments)
|
|
129
141
|
return normalized;
|
|
130
142
|
if (!isNotFoundPathError(error))
|
|
131
143
|
throw error;
|
|
132
|
-
rawResolvedAncestor = resolveSymlinkHopPath(cursor, mode, false, remainingHops);
|
|
144
|
+
rawResolvedAncestor = yield* resolveSymlinkHopPath(cursor, mode, false, remainingHops, synchronous);
|
|
133
145
|
}
|
|
134
146
|
assertNoWindowsPathAlias(rawResolvedAncestor);
|
|
135
147
|
const resolvedAncestor = resolvePathPreservingWindowsRoot(rawResolvedAncestor);
|
|
@@ -145,10 +157,10 @@ export function resolveExistingAncestor(targetPath, mode, preserveRawSegments =
|
|
|
145
157
|
assertNoWindowsPathAlias(resolved);
|
|
146
158
|
return resolved;
|
|
147
159
|
}
|
|
148
|
-
export function resolveSymlinkHopPath(symlinkPath, mode, rejectUnresolved, remainingHops = 64) {
|
|
160
|
+
export function* resolveSymlinkHopPath(symlinkPath, mode, rejectUnresolved, remainingHops = 64, synchronous = true) {
|
|
149
161
|
try {
|
|
150
|
-
const
|
|
151
|
-
|
|
162
|
+
const rawRealPath = synchronous ? realpathSync.native(symlinkPath)
|
|
163
|
+
: yield* wait(realpathNative(symlinkPath));
|
|
152
164
|
assertNoWindowsPathAlias(rawRealPath, "filesystem", "resolved symlink path uses a Windows filesystem namespace alias");
|
|
153
165
|
const realPath = resolvePathPreservingWindowsRoot(rawRealPath);
|
|
154
166
|
assertNoWindowsPathAlias(realPath, "filesystem", "resolved symlink path uses a Windows filesystem namespace alias");
|
|
@@ -162,14 +174,14 @@ export function resolveSymlinkHopPath(symlinkPath, mode, rejectUnresolved, remai
|
|
|
162
174
|
throw error;
|
|
163
175
|
if (remainingHops <= 0)
|
|
164
176
|
throw new FsSafeError("symlink", "too many unresolved symlink hops");
|
|
165
|
-
const linkTarget = fs.readlinkSync(symlinkPath);
|
|
177
|
+
const linkTarget = synchronous ? fs.readlinkSync(symlinkPath) : yield* wait(asyncFs.readlink(symlinkPath));
|
|
166
178
|
assertNoWindowsPathAlias(linkTarget, "filesystem", "symlink target uses a Windows filesystem namespace alias");
|
|
167
179
|
const linkDir = resolvePathPreservingWindowsRoot(path.dirname(symlinkPath));
|
|
168
180
|
// Keep parent segments until the kernel has resolved the existing prefix.
|
|
169
181
|
const targetPath = path.isAbsolute(linkTarget) ? linkTarget
|
|
170
182
|
: path.parse(linkTarget).root ? resolvePathFromBasePreservingWindowsRoot(linkDir, linkTarget)
|
|
171
183
|
: `${linkDir}${path.sep}${linkTarget}`;
|
|
172
|
-
const resolved =
|
|
184
|
+
const resolved = yield* resolveExistingAncestorProcedure(targetPath, mode, synchronous, true, remainingHops - 1);
|
|
173
185
|
assertNoWindowsPathAlias(resolved, "filesystem", "resolved symlink path uses a Windows filesystem namespace alias");
|
|
174
186
|
return resolved;
|
|
175
187
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import fs, {} from "node:fs";
|
|
2
|
+
import asyncFs from "node:fs/promises";
|
|
2
3
|
import path from "node:path";
|
|
4
|
+
import { runSync, wait } from "./atomic-io.js";
|
|
3
5
|
import { shortPath } from "./error-detail.js";
|
|
4
6
|
import { pathEscapeError, sanitizeRootPathError, symlinkEscapeError } from "./root-path-errors.js";
|
|
5
7
|
import { FsSafeError } from "./errors.js";
|
|
6
8
|
import { isNativeDirectoryObservationGuard } from "./native-directory-observation.js";
|
|
7
9
|
import { assertNoNulPathInput, isNotFoundPathError, isPathRelativeEscape, } from "./path.js";
|
|
8
|
-
import { absolutePathWithRawSegments, rawPathRelativeToCanonicalRoot,
|
|
10
|
+
import { absolutePathWithRawSegments, rawPathRelativeToCanonicalRoot, resolveExistingAncestorProcedure, resolveSymlinkHopPath, runRootTraversal, synchronousRootTraversal, } from "./root-path-existing.js";
|
|
9
11
|
import { admitPathInsideRoot, } from "./root-boundary.js";
|
|
10
12
|
import { RootPathObservationError, captureRootPathObservedDirectory, createRootPathTraversalObservation, inspectRootPathTraversalEntry, } from "./root-path-observation.js";
|
|
11
13
|
import { assertNoDriveRelativePathSegments } from "./safe-path-segment.js";
|
|
@@ -23,36 +25,38 @@ export const ROOT_PATH_ALIAS_POLICIES = {
|
|
|
23
25
|
}),
|
|
24
26
|
};
|
|
25
27
|
export async function resolveRootPath(params) {
|
|
26
|
-
return resolveRootPathInternal(params);
|
|
28
|
+
return runRootTraversal(resolveRootPathInternal(params));
|
|
27
29
|
}
|
|
28
30
|
export async function resolveRootPathWithCanonicalRootObservation(params, observeRoot) {
|
|
29
|
-
return resolveRootPathInternal(params, { observeRoot });
|
|
31
|
+
return runRootTraversal(resolveRootPathInternal(params, { observeRoot }));
|
|
30
32
|
}
|
|
31
33
|
export async function resolveRootPathWithObservation(params, request) {
|
|
32
34
|
const observation = { request };
|
|
33
|
-
const resolved =
|
|
35
|
+
const resolved = synchronousRootTraversal
|
|
36
|
+
? runSync(resolveRootPathInternal(params, { observation }))
|
|
37
|
+
: await runRootTraversal(resolveRootPathInternal(params, { observation }));
|
|
34
38
|
return observation.receipt ? { resolved, receipt: observation.receipt } : { resolved };
|
|
35
39
|
}
|
|
36
40
|
// Removal receipts are separate from metadata observations and canonical-root
|
|
37
|
-
// callbacks;
|
|
41
|
+
// callbacks; retain their synchronous admission and mutation-fence owner.
|
|
38
42
|
export async function resolveRootPathForRemoval(params, receipts) {
|
|
39
|
-
return resolveRootPathInternal(params, { removalReceipts: receipts });
|
|
43
|
+
return runSync(resolveRootPathInternal(params, { removalReceipts: receipts }, true));
|
|
40
44
|
}
|
|
41
45
|
export function resolveRootPathSync(params) {
|
|
42
|
-
return resolveRootPathInternal(params, { mode: "ordinary" });
|
|
46
|
+
return runSync(resolveRootPathInternal(params, { mode: "ordinary" }, true));
|
|
43
47
|
}
|
|
44
48
|
export function resolveRootPathSyncWithCanonicalRootObservation(params, observeRoot) {
|
|
45
|
-
return resolveRootPathInternal(params, { mode: "ordinary", observeRoot });
|
|
49
|
+
return runSync(resolveRootPathInternal(params, { mode: "ordinary", observeRoot }, true));
|
|
46
50
|
}
|
|
47
|
-
function resolveRootPathInternal(params, options = {}) {
|
|
51
|
+
function* resolveRootPathInternal(params, options = {}, synchronous = synchronousRootTraversal) {
|
|
48
52
|
try {
|
|
49
|
-
return traverseRootPath(params, options);
|
|
53
|
+
return yield* traverseRootPath(params, options, synchronous);
|
|
50
54
|
}
|
|
51
55
|
catch (error) {
|
|
52
56
|
throw sanitizeRootPathError(error);
|
|
53
57
|
}
|
|
54
58
|
}
|
|
55
|
-
function prepareRootTraversal(params, rootPath, rootCanonicalPath, absolutePath, rawAbsolutePath) {
|
|
59
|
+
function* prepareRootTraversal(params, rootPath, rootCanonicalPath, absolutePath, rawAbsolutePath, synchronous) {
|
|
56
60
|
let raw = rawAbsolutePath;
|
|
57
61
|
let trustedAbsolutePath = false;
|
|
58
62
|
// Even a metadata lookup on a foreign share contacts that host, including the
|
|
@@ -68,7 +72,7 @@ function prepareRootTraversal(params, rootPath, rootCanonicalPath, absolutePath,
|
|
|
68
72
|
else {
|
|
69
73
|
const canonical = admitRawPathInsideRoot(rootCanonicalPath, raw, params.rootIdentity);
|
|
70
74
|
const relative = canonical?.relativePath
|
|
71
|
-
?? rawPathRelativeToCanonicalRoot(raw, rootCanonicalPath, params);
|
|
75
|
+
?? (yield* rawPathRelativeToCanonicalRoot(raw, rootCanonicalPath, params, synchronous));
|
|
72
76
|
if (relative === undefined) {
|
|
73
77
|
throw pathEscapeError({ rootPath, absolutePath: raw, boundaryLabel: params.boundaryLabel });
|
|
74
78
|
}
|
|
@@ -249,27 +253,28 @@ function assertDirectoryBeforeMoreSegments(stat, pathname, isLast) {
|
|
|
249
253
|
throw Object.assign(new Error(`Path component is not a directory: ${pathname}`), { code: "ENOTDIR" });
|
|
250
254
|
}
|
|
251
255
|
}
|
|
252
|
-
function assertResolvedLinkDirectory(pathname, isLast) {
|
|
256
|
+
function* assertResolvedLinkDirectory(pathname, isLast, synchronous) {
|
|
253
257
|
if (isLast)
|
|
254
258
|
return;
|
|
255
|
-
const stat = fs.statSync(pathForWindowsFilesystem(pathname))
|
|
259
|
+
const stat = synchronous ? fs.statSync(pathForWindowsFilesystem(pathname))
|
|
260
|
+
: yield* wait(asyncFs.stat(pathForWindowsFilesystem(pathname)));
|
|
256
261
|
assertDirectoryBeforeMoreSegments(stat, pathname, isLast);
|
|
257
262
|
}
|
|
258
|
-
// Both
|
|
259
|
-
//
|
|
260
|
-
function traverseRootPath(params, { mode = "native", observation: observationOutput, observeRoot, removalReceipts }) {
|
|
263
|
+
// Both drivers share containment policy. Observation receipts and platform-specific
|
|
264
|
+
// native guards retain their existing synchronous owners.
|
|
265
|
+
function* traverseRootPath(params, { mode = "native", observation: observationOutput, observeRoot, removalReceipts }, synchronous) {
|
|
261
266
|
const input = captureValidRootPathInputs(params);
|
|
262
267
|
const rawAbsolutePath = absolutePathWithRawSegments(input.absolutePath);
|
|
263
268
|
const rootPath = resolvePathPreservingWindowsRoot(input.rootPath);
|
|
264
269
|
const absolutePath = resolvePathPreservingWindowsRoot(rawAbsolutePath);
|
|
265
270
|
const rootCanonicalPath = input.rootCanonicalPath
|
|
266
271
|
? resolvePathPreservingWindowsRoot(input.rootCanonicalPath)
|
|
267
|
-
:
|
|
272
|
+
: yield* resolveExistingAncestorProcedure(rootPath, mode, synchronous);
|
|
268
273
|
assertNoWindowsPathAlias(rootPath);
|
|
269
274
|
assertNoWindowsPathAlias(absolutePath);
|
|
270
275
|
assertNoWindowsPathAlias(rootCanonicalPath);
|
|
271
276
|
observeRoot?.(rootCanonicalPath);
|
|
272
|
-
const context = createLexicalTraversalContext(prepareRootTraversal(input, rootPath, rootCanonicalPath, absolutePath, rawAbsolutePath));
|
|
277
|
+
const context = createLexicalTraversalContext(yield* prepareRootTraversal(input, rootPath, rootCanonicalPath, absolutePath, rawAbsolutePath, synchronous));
|
|
273
278
|
const { state } = context;
|
|
274
279
|
const observation = createLexicalTraversalObservation(context, observationOutput?.request);
|
|
275
280
|
for (let idx = 0; idx < state.segments.length; idx += 1) {
|
|
@@ -306,7 +311,8 @@ function traverseRootPath(params, { mode = "native", observation: observationOut
|
|
|
306
311
|
}
|
|
307
312
|
stat = isNativeDirectoryObservationGuard(observed)
|
|
308
313
|
? undefined
|
|
309
|
-
: observed?.stat ?? fs.lstatSync(state.lexicalCursor)
|
|
314
|
+
: observed?.stat ?? (synchronous ? fs.lstatSync(state.lexicalCursor)
|
|
315
|
+
: yield* wait(asyncFs.lstat(state.lexicalCursor)));
|
|
310
316
|
}
|
|
311
317
|
}
|
|
312
318
|
catch (error) {
|
|
@@ -369,12 +375,12 @@ function traverseRootPath(params, { mode = "native", observation: observationOut
|
|
|
369
375
|
}
|
|
370
376
|
if (observation?.enabled)
|
|
371
377
|
disableLexicalTraversalObservation(context, observation);
|
|
372
|
-
const linkCanonical = resolveSymlinkHopPath(state.lexicalCursor, mode, context.resolveParams.rejectUnresolvedSymlinks);
|
|
378
|
+
const linkCanonical = yield* resolveSymlinkHopPath(state.lexicalCursor, mode, context.resolveParams.rejectUnresolvedSymlinks, 64, synchronous);
|
|
373
379
|
applyResolvedSymlinkHop(context, linkCanonical);
|
|
374
380
|
if (context.resolveParams.rejectSymlinks === true) {
|
|
375
381
|
throw new FsSafeError("symlink", "symlink path component not allowed");
|
|
376
382
|
}
|
|
377
|
-
assertResolvedLinkDirectory(linkCanonical, isLast);
|
|
383
|
+
yield* assertResolvedLinkDirectory(linkCanonical, isLast, synchronous);
|
|
378
384
|
}
|
|
379
385
|
const completeObservation = observation?.enabled === true && observation.directoryGuard !== undefined &&
|
|
380
386
|
observation.targetPath === state.canonicalCursor && observation.target !== undefined;
|
|
@@ -382,7 +388,7 @@ function traverseRootPath(params, { mode = "native", observation: observationOut
|
|
|
382
388
|
? isNativeDirectoryObservationGuard(observation.target)
|
|
383
389
|
? "directory"
|
|
384
390
|
: toResolvedKind(observation.target.stat)
|
|
385
|
-
:
|
|
391
|
+
: yield* getPathKind(state.canonicalCursor, state.preserveFinalSymlink, synchronous);
|
|
386
392
|
if (completeObservation && observationOutput) {
|
|
387
393
|
observationOutput.receipt = {
|
|
388
394
|
kind: observation.request.kind,
|
|
@@ -395,12 +401,12 @@ function traverseRootPath(params, { mode = "native", observation: observationOut
|
|
|
395
401
|
}
|
|
396
402
|
return finalizeLexicalResolution(context, kind);
|
|
397
403
|
}
|
|
398
|
-
function
|
|
404
|
+
function* getPathKind(absolutePath, preserveFinalSymlink, synchronous) {
|
|
399
405
|
try {
|
|
400
406
|
const operationPath = pathForWindowsFilesystem(absolutePath);
|
|
401
407
|
const stat = preserveFinalSymlink
|
|
402
|
-
? fs.lstatSync(operationPath)
|
|
403
|
-
: fs.statSync(operationPath);
|
|
408
|
+
? synchronous ? fs.lstatSync(operationPath) : yield* wait(asyncFs.lstat(operationPath))
|
|
409
|
+
: synchronous ? fs.statSync(operationPath) : yield* wait(asyncFs.stat(operationPath));
|
|
404
410
|
return toResolvedKind(stat);
|
|
405
411
|
}
|
|
406
412
|
catch (error) {
|
|
@@ -8,7 +8,7 @@ import { assertNoPathAliasEscape } from "./path-policy.js";
|
|
|
8
8
|
import { preparePinnedWriteMutationAdmission, snapshotPinnedMutationPolicy, } from "./pinned-mutation-admission.js";
|
|
9
9
|
import { admitPathInsideRoot, sameNormalizedPathSpelling } from "./root-boundary.js";
|
|
10
10
|
import { resolvePathInRoot } from "./root-context.js";
|
|
11
|
-
import { errorCauseOptions, hardlinkedPathNotAllowedError, outsideWorkspaceError } from "./root-errors.js";
|
|
11
|
+
import { errorCauseOptions, hardlinkedPathNotAllowedError, outsideWorkspaceError, pathTraversalPermissionError } from "./root-errors.js";
|
|
12
12
|
import { inheritWriteTargetMode } from "./root-write-mode.js";
|
|
13
13
|
import { mutationSymlinkResolution, } from "./root-symlink-policy.js";
|
|
14
14
|
import { inspectFileIdentitySync } from "./strict-file-identity.js";
|
|
@@ -179,6 +179,9 @@ export async function resolveGuardedWritePathInRoot(root, params) {
|
|
|
179
179
|
});
|
|
180
180
|
}
|
|
181
181
|
catch (error) {
|
|
182
|
+
const permissionError = pathTraversalPermissionError(error, resolvedPath.resolved);
|
|
183
|
+
if (permissionError)
|
|
184
|
+
throw permissionError;
|
|
182
185
|
throw new FsSafeError("path-alias", "path alias escape blocked", errorCauseOptions(error));
|
|
183
186
|
}
|
|
184
187
|
}
|