@openclaw/fs-safe 0.18.0 → 0.18.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/CHANGELOG.md +18 -0
- package/dist/advanced.d.ts +4 -2
- package/dist/advanced.js +1 -1
- package/dist/archive-durability.d.ts +1 -1
- package/dist/archive-merge.js +0 -1
- package/dist/archive-parser.wasm +0 -0
- package/dist/archive-plan.d.ts +64 -3
- package/dist/archive-plan.js +55 -1
- package/dist/archive-staging.d.ts +1 -2
- package/dist/archive-staging.js +0 -2
- package/dist/archive-tar-wasm.d.ts +1 -1
- package/dist/archive-zip-directory.d.ts +1 -1
- package/dist/archive-zip-entry.d.ts +1 -1
- package/dist/archive-zip-entry.js +1 -1
- package/dist/archive-zip-preflight.d.ts +0 -2
- package/dist/archive-zip-preflight.js +0 -1
- package/dist/archive.d.ts +14 -8
- package/dist/archive.js +127 -12
- package/dist/atomic.d.ts +3 -1
- package/dist/copy-publication.d.ts +1 -1
- package/dist/create.d.ts +16 -2
- package/dist/create.js +388 -2
- package/dist/creation-boundary.d.ts +60 -0
- package/dist/creation-boundary.js +371 -0
- package/dist/directory-guard.d.ts +0 -1
- package/dist/directory-guard.js +0 -3
- package/dist/directory-mode-node.d.ts +20 -2
- package/dist/directory-mode-node.js +89 -3
- package/dist/durability.d.ts +2 -1
- package/dist/file-lock-sync-acquisition.js +3 -3
- package/dist/file-lock-sync-root-acquire.js +2 -6
- package/dist/file-lock-sync-root-options.d.ts +2 -10
- package/dist/file-lock-sync-root.d.ts +2 -1
- package/dist/file-lock-sync-stale-admission.js +3 -10
- package/dist/file-lock-sync.d.ts +4 -21
- package/dist/file-store-boundary.d.ts +7 -0
- package/dist/file-store-boundary.js +58 -1
- package/dist/file-store-sync-write.js +2 -3
- package/dist/file-store.js +1 -6
- package/dist/guarded-mkdir.d.ts +1 -1
- package/dist/index.d.ts +9 -6
- package/dist/json-durable-queue-ownership.d.ts +1 -5
- package/dist/json-durable-queue-read.js +7 -3
- package/dist/json-durable-queue.d.ts +0 -1
- package/dist/json-durable-queue.js +1 -3
- package/dist/json-store.js +1 -2
- package/dist/json.js +1 -2
- package/dist/move-path.js +1 -2
- package/dist/native-operations.js +0 -1
- package/dist/native-pinned-write-windows.d.ts +1 -1
- package/dist/native-pinned-write-windows.js +1 -1
- package/dist/native-pinned-write.d.ts +1 -1
- package/dist/native-pinned-write.js +3 -6
- package/dist/native-policy-parent-windows.d.ts +1 -1
- package/dist/native-staged-file.d.ts +2 -2
- package/dist/native-staged-file.js +1 -2
- package/dist/permission-exec.d.ts +6 -0
- package/dist/permissions-public.d.ts +2 -1
- package/dist/permissions-windows.d.ts +3 -6
- package/dist/permissions.d.ts +3 -10
- package/dist/permissions.js +0 -1
- package/dist/pinned-mutation-admission.d.ts +1 -1
- package/dist/pinned-open.d.ts +1 -0
- package/dist/pinned-open.js +7 -2
- package/dist/pinned-operation.d.ts +1 -1
- package/dist/pinned-operation.js +3 -16
- package/dist/pinned-write-mode.js +1 -1
- package/dist/pinned-write-staged.js +1 -2
- package/dist/pinned-write.d.ts +0 -1
- package/dist/pinned-write.js +3 -5
- package/dist/private-producer-handoff-sync.d.ts +2 -12
- package/dist/private-producer-handoff-sync.js +1 -1
- package/dist/private-producer-handoff.d.ts +3 -3
- package/dist/private-temp-workspace.js +1 -2
- package/dist/publish-copy-stage.d.ts +1 -1
- package/dist/publish-file.d.ts +0 -1
- package/dist/publish-file.js +1 -2
- package/dist/replace-directory.js +6 -19
- package/dist/replace-file-copy-fallback.d.ts +1 -8
- package/dist/replace-file-descriptor.d.ts +3 -11
- package/dist/replace-file-descriptor.js +1 -1
- package/dist/replace-file-rename-policy.d.ts +1 -2
- package/dist/replace-file.d.ts +3 -3
- package/dist/replace-file.js +1 -1
- package/dist/retained-directory-replacement.d.ts +1 -0
- package/dist/retained-directory-replacement.js +1 -1
- package/dist/root-context.js +3 -7
- package/dist/root-create-input.d.ts +1 -1
- package/dist/root-directory-creation.d.ts +1 -1
- package/dist/root-directory-creation.js +1 -1
- package/dist/root-directory-list.js +3 -7
- package/dist/root-entries.js +2 -2
- package/dist/root-errors.d.ts +4 -0
- package/dist/root-errors.js +5 -3
- package/dist/root-file-final-admission.d.ts +1 -1
- package/dist/root-file-final-admission.js +1 -6
- package/dist/root-file.js +2 -5
- package/dist/root-impl.d.ts +0 -5
- package/dist/root-impl.js +22 -21
- package/dist/root-move-noreplace.js +4 -10
- package/dist/root-observed-path.js +2 -4
- package/dist/root-options.d.ts +1 -1
- package/dist/root-path-existing.js +2 -3
- package/dist/root-path-stat.js +2 -4
- package/dist/root-public-types.d.ts +11 -0
- package/dist/root-remove-identity.js +2 -4
- package/dist/root-remove.js +2 -4
- package/dist/root-write-admission.d.ts +1 -1
- package/dist/root-write-admission.js +3 -7
- package/dist/root-write-complete-parent.js +2 -3
- package/dist/root-write-verification.d.ts +1 -1
- package/dist/root.d.ts +2 -6
- package/dist/secret-file.js +11 -17
- package/dist/secret-read-policy.js +1 -1
- package/dist/secure-file-windows.js +4 -9
- package/dist/secure-temp-dir.js +2 -7
- package/dist/secure-temp-repair.js +5 -1
- package/dist/sidecar-lock-acquire.js +8 -11
- package/dist/sidecar-lock-policy.d.ts +1 -0
- package/dist/sidecar-lock-policy.js +7 -0
- package/dist/sidecar-lock-reclaim.js +5 -6
- package/dist/sidecar-lock-stale-admission.js +2 -6
- package/dist/sidecar-lock-types.d.ts +22 -16
- package/dist/stat-observation.js +3 -10
- package/dist/strict-file-identity.d.ts +2 -0
- package/dist/strict-file-identity.js +6 -6
- package/dist/temp-target.js +3 -8
- package/dist/temp-workspace-admission.js +7 -15
- package/dist/temp-workspace-child-admission.d.ts +16 -2
- package/dist/temp-workspace-child-admission.js +65 -3
- package/dist/temp-workspace-descriptor.d.ts +1 -1
- package/dist/temp-workspace-descriptor.js +2 -4
- package/dist/text-atomic.js +1 -1
- package/dist/windows-owner.d.ts +3 -6
- package/dist/windows-owner.js +1 -1
- package/dist/windows-path-alias.d.ts +1 -0
- package/dist/windows-path-alias.js +5 -0
- package/dist/windows-security-bridge.cs +0 -2
- package/docs/advanced.md +3 -1
- package/docs/secret-file.md +13 -0
- package/docs/sidecar-lock.md +6 -0
- package/docs/store.md +6 -0
- package/docs/temp.md +8 -1
- package/docs/writing.md +5 -0
- package/package.json +8 -8
- package/dist/archive-native.d.ts +0 -10
- package/dist/archive-native.js +0 -73
- package/dist/archive-options.d.ts +0 -30
- package/dist/archive-policy.d.ts +0 -21
- package/dist/archive-policy.js +0 -38
- package/dist/archive-tar-inspect.d.ts +0 -6
- package/dist/archive-tar-inspect.js +0 -62
- package/dist/archive-tar.d.ts +0 -18
- package/dist/archive-tar.js +0 -21
- package/dist/create-directory.d.ts +0 -18
- package/dist/create-directory.js +0 -111
- package/dist/create-file-async.d.ts +0 -6
- package/dist/create-file-async.js +0 -121
- package/dist/create-file.d.ts +0 -7
- package/dist/create-file.js +0 -179
- package/dist/creation-darwin.d.ts +0 -5
- package/dist/creation-darwin.js +0 -70
- package/dist/creation-file-state.d.ts +0 -18
- package/dist/creation-file-state.js +0 -118
- package/dist/creation-path.d.ts +0 -22
- package/dist/creation-path.js +0 -83
- package/dist/creation-permissions.d.ts +0 -18
- package/dist/creation-permissions.js +0 -115
- package/dist/directory-mode-owner.d.ts +0 -20
- package/dist/directory-mode-owner.js +0 -78
- package/dist/file-store-copy-source.d.ts +0 -4
- package/dist/file-store-copy-source.js +0 -31
- package/dist/file-store-limit.d.ts +0 -1
- package/dist/file-store-limit.js +0 -7
- package/dist/file-store-path.d.ts +0 -2
- package/dist/file-store-path.js +0 -30
- package/dist/standalone-publication-path.d.ts +0 -1
- package/dist/standalone-publication-path.js +0 -6
- package/dist/temp-workspace-identity.d.ts +0 -14
- package/dist/temp-workspace-identity.js +0 -41
- package/dist/temp-workspace-permissions.d.ts +0 -3
- package/dist/temp-workspace-permissions.js +0 -32
- /package/dist/{archive-options.js → root-public-types.js} +0 -0
package/dist/creation-darwin.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import fs, {} from "node:fs";
|
|
2
|
-
import { inspectDirectoryIdentitySync } from "./directory-guard.js";
|
|
3
|
-
import { nodeDarwinDirectoryMetadataFlags, nodeDirectorySearchOnlyFlags } from "./directory-mode-node.js";
|
|
4
|
-
import { FsSafeError } from "./errors.js";
|
|
5
|
-
import { getNativeBinding } from "./native.js";
|
|
6
|
-
import { inspectFileIdentitySync } from "./strict-file-identity.js";
|
|
7
|
-
function inspector() {
|
|
8
|
-
const native = getNativeBinding();
|
|
9
|
-
if (typeof native?.inspectDarwinAcl !== "function") {
|
|
10
|
-
throw new FsSafeError("helper-unavailable", "private Darwin creation requires native descriptor ACL inspection");
|
|
11
|
-
}
|
|
12
|
-
return native.inspectDarwinAcl.bind(native);
|
|
13
|
-
}
|
|
14
|
-
export function assertDarwinPrivateCreationAvailable() {
|
|
15
|
-
if (process.platform === "darwin")
|
|
16
|
-
inspector();
|
|
17
|
-
}
|
|
18
|
-
export function assertDarwinPrivateDirectoryMode(mode) {
|
|
19
|
-
if (process.platform === "darwin" && ((mode & ~process.umask()) & 0o500) === 0) {
|
|
20
|
-
throw new FsSafeError("helper-unavailable", "private Darwin directory ACL inspection requires owner read or search permission");
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
export function assertDarwinCreationAcl(fd, inheritanceTarget) {
|
|
24
|
-
if (process.platform !== "darwin")
|
|
25
|
-
return;
|
|
26
|
-
const inspect = inspector();
|
|
27
|
-
const state = inspect(fd, inheritanceTarget)?.state;
|
|
28
|
-
if (state === "present") {
|
|
29
|
-
throw new FsSafeError("insecure-permissions", inheritanceTarget
|
|
30
|
-
? "private creation parent has inheritable Darwin ACL entries"
|
|
31
|
-
: "private creation object has Darwin ACL entries");
|
|
32
|
-
}
|
|
33
|
-
if (state !== "absent" && state !== "empty") {
|
|
34
|
-
throw new FsSafeError("helper-unavailable", "native Darwin ACL inspection returned incomplete facts");
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
export function assertDarwinCreationDirectoryAcl(pathname, expected, inheritanceTarget) {
|
|
38
|
-
if (process.platform !== "darwin")
|
|
39
|
-
return;
|
|
40
|
-
assertDarwinPrivateCreationAvailable();
|
|
41
|
-
let fd;
|
|
42
|
-
try {
|
|
43
|
-
fd = fs.openSync(pathname, nodeDarwinDirectoryMetadataFlags());
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
if (error.code !== "EACCES")
|
|
47
|
-
throw error;
|
|
48
|
-
const search = nodeDirectorySearchOnlyFlags();
|
|
49
|
-
if (!search)
|
|
50
|
-
throw error;
|
|
51
|
-
try {
|
|
52
|
-
fd = fs.openSync(pathname, search.flags | fs.constants.O_DIRECTORY | fs.constants.O_NOFOLLOW | fs.constants.O_NONBLOCK);
|
|
53
|
-
}
|
|
54
|
-
catch (cause) {
|
|
55
|
-
if (cause.code !== "EACCES")
|
|
56
|
-
throw cause;
|
|
57
|
-
throw new FsSafeError("helper-unavailable", "private Darwin directory ACL inspection requires owner read or search permission", { cause });
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
try {
|
|
61
|
-
const opened = inspectFileIdentitySync(() => fs.fstatSync(fd, { bigint: true }), expected);
|
|
62
|
-
if (!opened.isDirectory())
|
|
63
|
-
throw new FsSafeError("path-mismatch", "ACL target is not the admitted directory");
|
|
64
|
-
assertDarwinCreationAcl(fd, inheritanceTarget);
|
|
65
|
-
inspectDirectoryIdentitySync(pathname, expected);
|
|
66
|
-
}
|
|
67
|
-
finally {
|
|
68
|
-
fs.closeSync(fd);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type BigIntStats } from "node:fs";
|
|
2
|
-
import { FsSafeError } from "./errors.js";
|
|
3
|
-
export type CreationPublicationStatus = "not-published" | "published" | "indeterminate";
|
|
4
|
-
export declare function assertCreationFile(fd: number, pathname: string, expected?: BigIntStats): BigIntStats;
|
|
5
|
-
export declare function assertPrivateCreationFile(stat: BigIntStats, fd: number): void;
|
|
6
|
-
export declare function removeRecordedCreationFileSync(pathname: string, identity: BigIntStats, assertParent: () => void): void;
|
|
7
|
-
export declare function removeRecordedCreationFile(pathname: string, identity: BigIntStats, assertParent: () => void): Promise<void>;
|
|
8
|
-
export declare function creationPublicationAfterFailure(error: unknown, recorded: CreationPublicationStatus): CreationPublicationStatus;
|
|
9
|
-
export declare function hasPreservedCreationArtifacts(error: unknown): boolean;
|
|
10
|
-
export declare function rethrowPrivateStageCreationFailure(error: unknown, path: string, stageDirectory: string): never;
|
|
11
|
-
export declare function privateFileSettlementFailure(params: {
|
|
12
|
-
primary: unknown;
|
|
13
|
-
cleanup: readonly unknown[];
|
|
14
|
-
publication: CreationPublicationStatus;
|
|
15
|
-
path: string;
|
|
16
|
-
stageDirectory: string;
|
|
17
|
-
preserved?: boolean;
|
|
18
|
-
}): FsSafeError;
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import fs, {} from "node:fs";
|
|
2
|
-
import fsAsync from "node:fs/promises";
|
|
3
|
-
import { FsSafeError } from "./errors.js";
|
|
4
|
-
import { sameFileIdentityForCleanup } from "./file-identity.js";
|
|
5
|
-
import { inspectFileIdentitySync } from "./strict-file-identity.js";
|
|
6
|
-
import { hasUnsettledWindowsSecurityCommand } from "./windows-security-command.js";
|
|
7
|
-
import { assertDarwinCreationAcl } from "./creation-darwin.js";
|
|
8
|
-
export function assertCreationFile(fd, pathname, expected) {
|
|
9
|
-
const opened = inspectFileIdentitySync(() => fs.fstatSync(fd, { bigint: true }), expected);
|
|
10
|
-
const named = inspectFileIdentitySync(() => fs.lstatSync(pathname, { bigint: true }), opened);
|
|
11
|
-
if (!opened.isFile() || !named.isFile() || named.isSymbolicLink() || opened.nlink !== 1n || named.nlink !== 1n) {
|
|
12
|
-
throw new FsSafeError("path-mismatch", "created file is not the expected single-linked regular file");
|
|
13
|
-
}
|
|
14
|
-
return opened;
|
|
15
|
-
}
|
|
16
|
-
export function assertPrivateCreationFile(stat, fd) {
|
|
17
|
-
if (process.platform === "win32")
|
|
18
|
-
return;
|
|
19
|
-
if (typeof process.getuid !== "function" || stat.uid !== BigInt(process.getuid())) {
|
|
20
|
-
throw new FsSafeError("not-owned", "created private file must belong to the current user");
|
|
21
|
-
}
|
|
22
|
-
if ((stat.mode & 3647n) !== 0n) {
|
|
23
|
-
throw new FsSafeError("insecure-permissions", "created private file is not owner-only");
|
|
24
|
-
}
|
|
25
|
-
assertDarwinCreationAcl(fd);
|
|
26
|
-
}
|
|
27
|
-
function assertRecordedFile(current, identity) {
|
|
28
|
-
if (!current.isFile() || current.isSymbolicLink() || !sameFileIdentityForCleanup(current, identity)) {
|
|
29
|
-
throw new FsSafeError("path-mismatch", "created file cleanup preserved a replacement");
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
export function removeRecordedCreationFileSync(pathname, identity, assertParent) {
|
|
33
|
-
assertParent();
|
|
34
|
-
let current;
|
|
35
|
-
try {
|
|
36
|
-
current = fs.lstatSync(pathname, { bigint: true });
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
if (error?.code === "ENOENT")
|
|
40
|
-
return;
|
|
41
|
-
throw error;
|
|
42
|
-
}
|
|
43
|
-
assertRecordedFile(current, identity);
|
|
44
|
-
fs.unlinkSync(pathname);
|
|
45
|
-
}
|
|
46
|
-
export async function removeRecordedCreationFile(pathname, identity, assertParent) {
|
|
47
|
-
assertParent();
|
|
48
|
-
let current;
|
|
49
|
-
try {
|
|
50
|
-
current = await fsAsync.lstat(pathname, { bigint: true });
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
if (error?.code === "ENOENT")
|
|
54
|
-
return;
|
|
55
|
-
throw error;
|
|
56
|
-
}
|
|
57
|
-
assertParent();
|
|
58
|
-
assertRecordedFile(current, identity);
|
|
59
|
-
// Recheck after the awaited observation before dispatching the unlink.
|
|
60
|
-
assertRecordedFile(fs.lstatSync(pathname, { bigint: true }), identity);
|
|
61
|
-
await fsAsync.unlink(pathname);
|
|
62
|
-
}
|
|
63
|
-
export function creationPublicationAfterFailure(error, recorded) {
|
|
64
|
-
if (error instanceof FsSafeError) {
|
|
65
|
-
const publication = error.details?.publication;
|
|
66
|
-
if (publication && typeof publication === "object" && "status" in publication &&
|
|
67
|
-
publication.status === "indeterminate")
|
|
68
|
-
return "indeterminate";
|
|
69
|
-
}
|
|
70
|
-
return recorded;
|
|
71
|
-
}
|
|
72
|
-
export function hasPreservedCreationArtifacts(error) {
|
|
73
|
-
if (!(error instanceof FsSafeError))
|
|
74
|
-
return false;
|
|
75
|
-
if (error.details?.cleanup === "preserved" || error.details?.cleanup === "failed")
|
|
76
|
-
return true;
|
|
77
|
-
const publication = error.details?.publication;
|
|
78
|
-
return publication !== null && typeof publication === "object" && "status" in publication &&
|
|
79
|
-
(publication.status === "published" || publication.status === "indeterminate");
|
|
80
|
-
}
|
|
81
|
-
export function rethrowPrivateStageCreationFailure(error, path, stageDirectory) {
|
|
82
|
-
if (error instanceof FsSafeError && error.code === "already-exists") {
|
|
83
|
-
throw new FsSafeError("helper-failed", "private file staging path already exists", {
|
|
84
|
-
cause: error, details: { publication: { status: "not-published" }, path, stageDirectory },
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
const publication = error instanceof FsSafeError ? error.details?.publication : undefined;
|
|
88
|
-
const created = error instanceof FsSafeError && error.details?.path === stageDirectory &&
|
|
89
|
-
publication !== null && typeof publication === "object" && "status" in publication &&
|
|
90
|
-
publication.status === "published";
|
|
91
|
-
let unconfirmed = hasUnsettledWindowsSecurityCommand(error);
|
|
92
|
-
if (error !== null && (typeof error === "object" || typeof error === "function")) {
|
|
93
|
-
try {
|
|
94
|
-
const outcome = Object.getOwnPropertyDescriptor(error, "creationOutcome");
|
|
95
|
-
unconfirmed ||= Boolean(outcome && "value" in outcome && outcome.value === "unconfirmed");
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
98
|
-
unconfirmed = true;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (created || unconfirmed) {
|
|
102
|
-
throw privateFileSettlementFailure({
|
|
103
|
-
primary: error, cleanup: [], publication: "not-published", path, stageDirectory, preserved: true,
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
throw error;
|
|
107
|
-
}
|
|
108
|
-
export function privateFileSettlementFailure(params) {
|
|
109
|
-
return new FsSafeError("helper-failed", "file creation or staging settlement failed", {
|
|
110
|
-
cause: params.cleanup.length
|
|
111
|
-
? new AggregateError([params.primary, ...params.cleanup], "file creation and cleanup failed")
|
|
112
|
-
: params.primary,
|
|
113
|
-
details: {
|
|
114
|
-
publication: { status: params.publication }, path: params.path, stageDirectory: params.stageDirectory,
|
|
115
|
-
cleanup: params.preserved || params.publication === "indeterminate" ? "preserved" : params.cleanup.length ? "failed" : "removed",
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
}
|
package/dist/creation-path.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { type BigIntStats } from "node:fs";
|
|
2
|
-
import { type AsyncDirectoryGuard, type AnyAsyncDirectoryGuard } from "./directory-guard.js";
|
|
3
|
-
import type { CreationPermissions } from "./creation-permissions.js";
|
|
4
|
-
export type CreationParentIdentity = Readonly<{
|
|
5
|
-
dev: bigint;
|
|
6
|
-
ino: bigint;
|
|
7
|
-
realPath?: string;
|
|
8
|
-
}>;
|
|
9
|
-
export type CreationPath = {
|
|
10
|
-
target: string;
|
|
11
|
-
parent: AsyncDirectoryGuard<BigIntStats>;
|
|
12
|
-
assertParent(): void;
|
|
13
|
-
};
|
|
14
|
-
export declare function assertBeforeCreation(selected: CreationPath, permissions: CreationPermissions, assertion: (() => void) | undefined, kind: "file" | "directory"): void;
|
|
15
|
-
export declare function creationAdmissionFromParent(parent: AnyAsyncDirectoryGuard): {
|
|
16
|
-
expectedParentIdentity: CreationParentIdentity;
|
|
17
|
-
};
|
|
18
|
-
export declare function prepareCreationPath(input: string, expectedParent?: CreationParentIdentity): CreationPath;
|
|
19
|
-
export declare function creationCollision(error: unknown): unknown;
|
|
20
|
-
/** Remove only the recorded empty stage; never traverse a replaced directory. */
|
|
21
|
-
export declare function removeCreationDirectory(directory: string, identity: BigIntStats, assertParent: () => void): void;
|
|
22
|
-
export declare function removeCreationDirectoryAsync(directory: string, identity: BigIntStats, assertParent: () => void): Promise<void>;
|
package/dist/creation-path.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import fs, {} from "node:fs";
|
|
2
|
-
import fsAsync from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { assertDirectoryIdentitySync, inspectDirectoryIdentitySync, } from "./directory-guard.js";
|
|
5
|
-
import { FsSafeError } from "./errors.js";
|
|
6
|
-
import { assertDarwinCreationDirectoryAcl, assertDarwinPrivateDirectoryMode } from "./creation-darwin.js";
|
|
7
|
-
import { assertSynchronousCallbackResult } from "./mutation-authority.js";
|
|
8
|
-
import { assertNoNulPathInput } from "./path.js";
|
|
9
|
-
import { realpathSync } from "./realpath.js";
|
|
10
|
-
import { assertNoWindowsPathAlias, resolvePathPreservingWindowsRoot } from "./windows-path-alias.js";
|
|
11
|
-
export function assertBeforeCreation(selected, permissions, assertion, kind) {
|
|
12
|
-
if (permissions.private)
|
|
13
|
-
assertDarwinCreationDirectoryAcl(selected.parent.dir, selected.parent.stat, kind);
|
|
14
|
-
assertSynchronousCallbackResult(assertion?.(), "assertBeforeMutation");
|
|
15
|
-
selected.assertParent();
|
|
16
|
-
if (permissions.private && kind === "directory")
|
|
17
|
-
assertDarwinPrivateDirectoryMode(permissions.mode);
|
|
18
|
-
if (permissions.private)
|
|
19
|
-
assertDarwinCreationDirectoryAcl(selected.parent.dir, selected.parent.stat, kind);
|
|
20
|
-
}
|
|
21
|
-
export function creationAdmissionFromParent(parent) {
|
|
22
|
-
const { dev, ino } = parent.stat;
|
|
23
|
-
if (typeof dev !== "bigint" || typeof ino !== "bigint") {
|
|
24
|
-
throw new FsSafeError("path-mismatch", "private creation requires an exact parent identity");
|
|
25
|
-
}
|
|
26
|
-
const identity = inspectDirectoryIdentitySync(parent.dir, { dev, ino });
|
|
27
|
-
return { expectedParentIdentity: { dev: identity.dev, ino: identity.ino, realPath: parent.realPath } };
|
|
28
|
-
}
|
|
29
|
-
export function prepareCreationPath(input, expectedParent) {
|
|
30
|
-
expectedParent = expectedParent && { dev: expectedParent.dev, ino: expectedParent.ino, realPath: expectedParent.realPath };
|
|
31
|
-
assertNoNulPathInput(input);
|
|
32
|
-
assertNoWindowsPathAlias(input, "filesystem");
|
|
33
|
-
if (process.platform === "win32" && input.replaceAll("/", "\\").split("\\")
|
|
34
|
-
.some(component => component.endsWith(".") || component.endsWith(" "))) {
|
|
35
|
-
throw new FsSafeError("invalid-path", "creation path contains an ambiguous Windows component");
|
|
36
|
-
}
|
|
37
|
-
const target = resolvePathPreservingWindowsRoot(input);
|
|
38
|
-
const directory = path.dirname(target);
|
|
39
|
-
if (target === directory || input.length === 0) {
|
|
40
|
-
throw new FsSafeError("invalid-path", "creation requires a child name");
|
|
41
|
-
}
|
|
42
|
-
if (expectedParent)
|
|
43
|
-
assertDirectoryIdentitySync(directory, expectedParent);
|
|
44
|
-
const stat = inspectDirectoryIdentitySync(directory);
|
|
45
|
-
const realPath = realpathSync.native(directory);
|
|
46
|
-
const parent = { dir: directory, realPath, stat };
|
|
47
|
-
const assertParent = () => {
|
|
48
|
-
assertDirectoryIdentitySync(directory, { dev: stat.dev, ino: stat.ino, realPath });
|
|
49
|
-
if (expectedParent)
|
|
50
|
-
assertDirectoryIdentitySync(directory, expectedParent);
|
|
51
|
-
};
|
|
52
|
-
assertParent();
|
|
53
|
-
return { target, parent, assertParent };
|
|
54
|
-
}
|
|
55
|
-
export function creationCollision(error) {
|
|
56
|
-
if (error?.code === "EEXIST") {
|
|
57
|
-
return new FsSafeError("already-exists", "creation target already exists", { cause: error });
|
|
58
|
-
}
|
|
59
|
-
return error;
|
|
60
|
-
}
|
|
61
|
-
/** Remove only the recorded empty stage; never traverse a replaced directory. */
|
|
62
|
-
export function removeCreationDirectory(directory, identity, assertParent) {
|
|
63
|
-
assertParent();
|
|
64
|
-
try {
|
|
65
|
-
assertDirectoryIdentitySync(directory, identity);
|
|
66
|
-
fs.rmdirSync(directory);
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
if (error?.code !== "ENOENT")
|
|
70
|
-
throw error;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
export async function removeCreationDirectoryAsync(directory, identity, assertParent) {
|
|
74
|
-
assertParent();
|
|
75
|
-
try {
|
|
76
|
-
assertDirectoryIdentitySync(directory, identity);
|
|
77
|
-
await fsAsync.rmdir(directory);
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
if (error?.code !== "ENOENT")
|
|
81
|
-
throw error;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export type CreationPermissions = {
|
|
2
|
-
private?: boolean;
|
|
3
|
-
mode?: number;
|
|
4
|
-
};
|
|
5
|
-
export declare function resolveCreationPermissions(options: CreationPermissions, directory: boolean): {
|
|
6
|
-
private: boolean;
|
|
7
|
-
mode: number | undefined;
|
|
8
|
-
};
|
|
9
|
-
export declare function assertPrivateFileCreationAvailable(): void;
|
|
10
|
-
/** Full Windows identity, with security validation when requested; no repairs. */
|
|
11
|
-
export declare function inspectCreationDirectorySync(targetPath: string, privatePath: boolean): string;
|
|
12
|
-
export declare function inspectCreationDirectory(targetPath: string, privatePath: boolean): Promise<string>;
|
|
13
|
-
export declare function assertPrivateDirectorySync(targetPath: string): void;
|
|
14
|
-
export declare function assertPrivateDirectory(targetPath: string): Promise<void>;
|
|
15
|
-
export declare function protectCreatedFileSync(fd: number, targetPath: string, parentIdentity: string): string;
|
|
16
|
-
export declare function protectCreatedFile(fd: number, targetPath: string, parentIdentity: string): Promise<string>;
|
|
17
|
-
export declare function verifyCreatedFileSync(fd: number, targetPath: string, identity: string, parentIdentity: string, links?: number): void;
|
|
18
|
-
export declare function verifyCreatedFile(fd: number, targetPath: string, identity: string, parentIdentity: string, links?: number): Promise<void>;
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { inspectDirectoryIdentitySync } from "./directory-guard.js";
|
|
2
|
-
import { FsSafeError } from "./errors.js";
|
|
3
|
-
import { getNativeBinding } from "./native.js";
|
|
4
|
-
import { getFsSafeNativeConfig } from "./native-config.js";
|
|
5
|
-
import { warnNativeFallback } from "./native-fallback-warning.js";
|
|
6
|
-
import { inspectWindowsDirectoryCommand, inspectWindowsDirectoryCommandSync, protectPrivateWindowsFileCommand, protectPrivateWindowsFileCommandSync, verifyPrivateWindowsFileCommand, verifyPrivateWindowsFileCommandSync, } from "./windows-security-command.js";
|
|
7
|
-
import { assertNoWindowsPathAlias } from "./windows-path-alias.js";
|
|
8
|
-
import { assertDarwinCreationDirectoryAcl, assertDarwinPrivateCreationAvailable, assertDarwinPrivateDirectoryMode } from "./creation-darwin.js";
|
|
9
|
-
export function resolveCreationPermissions(options, directory) {
|
|
10
|
-
const privatePath = options.private;
|
|
11
|
-
const mode = options.mode;
|
|
12
|
-
if (privatePath !== undefined && typeof privatePath !== "boolean") {
|
|
13
|
-
throw new TypeError("private must be a boolean");
|
|
14
|
-
}
|
|
15
|
-
if (mode !== undefined && (!Number.isInteger(mode) || mode < 0 || mode > 0o7777)) {
|
|
16
|
-
throw new RangeError("mode must contain only permission bits");
|
|
17
|
-
}
|
|
18
|
-
if (privatePath && mode !== undefined && (mode & 0o7077) !== 0) {
|
|
19
|
-
throw new FsSafeError("insecure-permissions", "private creation requires owner-only permission bits");
|
|
20
|
-
}
|
|
21
|
-
if (privatePath)
|
|
22
|
-
assertDarwinPrivateCreationAvailable();
|
|
23
|
-
if (privatePath && directory)
|
|
24
|
-
assertDarwinPrivateDirectoryMode(mode ?? 0o700);
|
|
25
|
-
return { private: privatePath === true, mode: mode ?? (privatePath ? directory ? 0o700 : 0o600 : undefined) };
|
|
26
|
-
}
|
|
27
|
-
function assertPrivatePosixDirectory(stat) {
|
|
28
|
-
if (typeof process.getuid !== "function" || stat.uid !== BigInt(process.getuid())) {
|
|
29
|
-
throw new FsSafeError("not-owned", "private directory must belong to the current user");
|
|
30
|
-
}
|
|
31
|
-
if ((stat.mode & 3647n) !== 0n) {
|
|
32
|
-
throw new FsSafeError("insecure-permissions", "existing directory is not private");
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function unavailable() {
|
|
36
|
-
throw new FsSafeError("helper-unavailable", "private Windows creation requires an up-to-date native helper");
|
|
37
|
-
}
|
|
38
|
-
export function assertPrivateFileCreationAvailable() {
|
|
39
|
-
const native = getNativeBinding();
|
|
40
|
-
if (process.platform !== "win32" || getFsSafeNativeConfig().mode !== "require")
|
|
41
|
-
return;
|
|
42
|
-
if (typeof native?.createPrivateDirectoryWithParentIdentity !== "function" ||
|
|
43
|
-
typeof native.inspectWindowsDirectory !== "function" ||
|
|
44
|
-
typeof native.protectPrivateWindowsFile !== "function" ||
|
|
45
|
-
typeof native.verifyPrivateWindowsFile !== "function")
|
|
46
|
-
unavailable();
|
|
47
|
-
}
|
|
48
|
-
function commandFallback() {
|
|
49
|
-
if (getFsSafeNativeConfig().mode === "require")
|
|
50
|
-
unavailable();
|
|
51
|
-
warnNativeFallback("windows-private-creation", "Private Windows creation uses a slower built-in system command.");
|
|
52
|
-
}
|
|
53
|
-
function creationOperation(name) {
|
|
54
|
-
const native = getNativeBinding();
|
|
55
|
-
const operation = native?.[name];
|
|
56
|
-
if (typeof operation === "function")
|
|
57
|
-
return operation.bind(native);
|
|
58
|
-
commandFallback();
|
|
59
|
-
return undefined;
|
|
60
|
-
}
|
|
61
|
-
/** Full Windows identity, with security validation when requested; no repairs. */
|
|
62
|
-
export function inspectCreationDirectorySync(targetPath, privatePath) {
|
|
63
|
-
assertNoWindowsPathAlias(targetPath, "filesystem");
|
|
64
|
-
const inspect = creationOperation("inspectWindowsDirectory");
|
|
65
|
-
return (inspect ? inspect(targetPath, privatePath) : inspectWindowsDirectoryCommandSync(targetPath, privatePath)).identity;
|
|
66
|
-
}
|
|
67
|
-
export async function inspectCreationDirectory(targetPath, privatePath) {
|
|
68
|
-
assertNoWindowsPathAlias(targetPath, "filesystem");
|
|
69
|
-
const inspect = creationOperation("inspectWindowsDirectory");
|
|
70
|
-
return (inspect ? inspect(targetPath, privatePath) : await inspectWindowsDirectoryCommand(targetPath, privatePath)).identity;
|
|
71
|
-
}
|
|
72
|
-
export function assertPrivateDirectorySync(targetPath) {
|
|
73
|
-
const stat = inspectDirectoryIdentitySync(targetPath);
|
|
74
|
-
if (process.platform === "win32")
|
|
75
|
-
inspectCreationDirectorySync(targetPath, true);
|
|
76
|
-
else {
|
|
77
|
-
assertPrivatePosixDirectory(stat);
|
|
78
|
-
assertDarwinCreationDirectoryAcl(targetPath, stat);
|
|
79
|
-
}
|
|
80
|
-
inspectDirectoryIdentitySync(targetPath, stat);
|
|
81
|
-
}
|
|
82
|
-
export async function assertPrivateDirectory(targetPath) {
|
|
83
|
-
const stat = inspectDirectoryIdentitySync(targetPath);
|
|
84
|
-
if (process.platform === "win32")
|
|
85
|
-
await inspectCreationDirectory(targetPath, true);
|
|
86
|
-
else {
|
|
87
|
-
assertPrivatePosixDirectory(stat);
|
|
88
|
-
assertDarwinCreationDirectoryAcl(targetPath, stat);
|
|
89
|
-
}
|
|
90
|
-
inspectDirectoryIdentitySync(targetPath, stat);
|
|
91
|
-
}
|
|
92
|
-
export function protectCreatedFileSync(fd, targetPath, parentIdentity) {
|
|
93
|
-
const protect = creationOperation("protectPrivateWindowsFile");
|
|
94
|
-
return (protect ? protect(fd, targetPath, parentIdentity)
|
|
95
|
-
: protectPrivateWindowsFileCommandSync(fd, targetPath, parentIdentity)).identity;
|
|
96
|
-
}
|
|
97
|
-
export async function protectCreatedFile(fd, targetPath, parentIdentity) {
|
|
98
|
-
const protect = creationOperation("protectPrivateWindowsFile");
|
|
99
|
-
return (protect ? protect(fd, targetPath, parentIdentity)
|
|
100
|
-
: await protectPrivateWindowsFileCommand(fd, targetPath, parentIdentity)).identity;
|
|
101
|
-
}
|
|
102
|
-
export function verifyCreatedFileSync(fd, targetPath, identity, parentIdentity, links = 1) {
|
|
103
|
-
const verify = creationOperation("verifyPrivateWindowsFile");
|
|
104
|
-
if (verify)
|
|
105
|
-
verify(fd, targetPath, identity, parentIdentity, links);
|
|
106
|
-
else
|
|
107
|
-
verifyPrivateWindowsFileCommandSync(fd, targetPath, identity, parentIdentity, links);
|
|
108
|
-
}
|
|
109
|
-
export async function verifyCreatedFile(fd, targetPath, identity, parentIdentity, links = 1) {
|
|
110
|
-
const verify = creationOperation("verifyPrivateWindowsFile");
|
|
111
|
-
if (verify)
|
|
112
|
-
verify(fd, targetPath, identity, parentIdentity, links);
|
|
113
|
-
else
|
|
114
|
-
await verifyPrivateWindowsFileCommand(fd, targetPath, identity, parentIdentity, links);
|
|
115
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { BigIntStats, Stats } from "node:fs";
|
|
2
|
-
export type DirectoryModeChecks = {
|
|
3
|
-
check?: () => void;
|
|
4
|
-
beforeChmod?: () => Promise<void>;
|
|
5
|
-
};
|
|
6
|
-
export type DirectoryModeOwner = {
|
|
7
|
-
verify(check?: () => void): Promise<void>;
|
|
8
|
-
apply(mode: number, checks?: DirectoryModeChecks): Promise<void>;
|
|
9
|
-
close(): Promise<void>;
|
|
10
|
-
};
|
|
11
|
-
export declare function assertOwnedDirectory(expected: Stats | BigIntStats, actual: Stats | BigIntStats): void;
|
|
12
|
-
/** Serializes use and close: even a queued path-based fd operation retains its descriptor. */
|
|
13
|
-
export declare function ownDirectoryMode(params: {
|
|
14
|
-
inspect: () => Promise<number>;
|
|
15
|
-
chmod: (mode: number) => Promise<void>;
|
|
16
|
-
prepareChmod?: () => Promise<void>;
|
|
17
|
-
verifyChmod?: () => Promise<void>;
|
|
18
|
-
close: () => Promise<void>;
|
|
19
|
-
ignoreChmodError?: boolean;
|
|
20
|
-
}): DirectoryModeOwner;
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { FsSafeError } from "./errors.js";
|
|
2
|
-
import { sameFileIdentityForCleanup } from "./file-identity.js";
|
|
3
|
-
export function assertOwnedDirectory(expected, actual) {
|
|
4
|
-
if (actual.isSymbolicLink() || !actual.isDirectory()) {
|
|
5
|
-
throw new FsSafeError("not-file", "directory mode target must be a real directory");
|
|
6
|
-
}
|
|
7
|
-
if (!sameFileIdentityForCleanup(expected, actual)) {
|
|
8
|
-
throw new FsSafeError("path-mismatch", "directory changed before its mode could be applied");
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
/** Serializes use and close: even a queued path-based fd operation retains its descriptor. */
|
|
12
|
-
export function ownDirectoryMode(params) {
|
|
13
|
-
let pending = Promise.resolve();
|
|
14
|
-
let closing;
|
|
15
|
-
const enqueue = (run) => {
|
|
16
|
-
if (closing)
|
|
17
|
-
return Promise.reject(new FsSafeError("path-mismatch", "directory mode owner is closed"));
|
|
18
|
-
const operation = pending.then(run);
|
|
19
|
-
pending = operation.catch(() => undefined);
|
|
20
|
-
return operation;
|
|
21
|
-
};
|
|
22
|
-
return {
|
|
23
|
-
verify: (check) => enqueue(async () => {
|
|
24
|
-
check?.();
|
|
25
|
-
await params.inspect();
|
|
26
|
-
check?.();
|
|
27
|
-
}),
|
|
28
|
-
apply: (mode, checks = {}) => enqueue(async () => {
|
|
29
|
-
// inspect() reports permission bits only; chmod ignores file-type bits,
|
|
30
|
-
// so tolerate raw stat modes (e.g. S_IFDIR | 0o755) by masking up front.
|
|
31
|
-
mode &= 0o7777;
|
|
32
|
-
checks.check?.();
|
|
33
|
-
const currentMode = await params.inspect();
|
|
34
|
-
checks.check?.();
|
|
35
|
-
if (currentMode === mode && !checks.beforeChmod && !checks.check)
|
|
36
|
-
return;
|
|
37
|
-
if (currentMode !== mode) {
|
|
38
|
-
await params.prepareChmod?.();
|
|
39
|
-
checks.check?.();
|
|
40
|
-
}
|
|
41
|
-
await checks.beforeChmod?.();
|
|
42
|
-
checks.check?.();
|
|
43
|
-
// Hooks/ancestor checks can yield; recheck the original named association.
|
|
44
|
-
await params.inspect();
|
|
45
|
-
checks.check?.();
|
|
46
|
-
let dispatchDeadlineFailure;
|
|
47
|
-
if (currentMode !== mode) {
|
|
48
|
-
checks.check?.();
|
|
49
|
-
try {
|
|
50
|
-
await params.chmod(mode);
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
if (!params.ignoreChmodError)
|
|
54
|
-
throw error;
|
|
55
|
-
}
|
|
56
|
-
// Expiry cannot release the fd while post-dispatch verification is pending.
|
|
57
|
-
try {
|
|
58
|
-
checks.check?.();
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
dispatchDeadlineFailure = { error };
|
|
62
|
-
}
|
|
63
|
-
await params.verifyChmod?.();
|
|
64
|
-
}
|
|
65
|
-
const finalMode = await params.inspect();
|
|
66
|
-
if (dispatchDeadlineFailure)
|
|
67
|
-
throw dispatchDeadlineFailure.error;
|
|
68
|
-
checks.check?.();
|
|
69
|
-
if (!params.ignoreChmodError && finalMode !== mode) {
|
|
70
|
-
throw new FsSafeError("path-mismatch", "directory final mode could not be verified");
|
|
71
|
-
}
|
|
72
|
-
}),
|
|
73
|
-
close() {
|
|
74
|
-
closing ??= pending.then(params.close);
|
|
75
|
-
return closing;
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import { FsSafeError } from "./errors.js";
|
|
3
|
-
import { assertFileStoreMaxBytes } from "./file-store-limit.js";
|
|
4
|
-
import { readRegularFile } from "./regular-file.js";
|
|
5
|
-
import { assertNoWindowsPathAlias } from "./windows-path-alias.js";
|
|
6
|
-
export async function readFileStoreCopySource(params) {
|
|
7
|
-
assertNoWindowsPathAlias(params.sourcePath, "filesystem", "source path uses a Windows filesystem namespace alias");
|
|
8
|
-
const sourceStat = fs.lstatSync(params.sourcePath);
|
|
9
|
-
if (sourceStat.isSymbolicLink() || !sourceStat.isFile()) {
|
|
10
|
-
throw new FsSafeError("not-file", "source path is not a file");
|
|
11
|
-
}
|
|
12
|
-
assertFileStoreMaxBytes(sourceStat.size, params.maxBytes);
|
|
13
|
-
try {
|
|
14
|
-
return (await readRegularFile({ filePath: params.sourcePath, maxBytes: params.maxBytes }))
|
|
15
|
-
.buffer;
|
|
16
|
-
}
|
|
17
|
-
catch (error) {
|
|
18
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
19
|
-
if (message.includes("regular file") || message.includes("not a regular file")) {
|
|
20
|
-
throw new FsSafeError("not-file", "source path is not a file", {
|
|
21
|
-
cause: error instanceof Error ? error : undefined,
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
if (message.includes(`exceeds ${params.maxBytes} bytes`)) {
|
|
25
|
-
throw new FsSafeError("too-large", `file exceeds maximum size of ${params.maxBytes} bytes`, {
|
|
26
|
-
cause: error instanceof Error ? error : undefined,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
throw error;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function assertFileStoreMaxBytes(size: number, limit: number | undefined): void;
|
package/dist/file-store-limit.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { FsSafeError } from "./errors.js";
|
|
2
|
-
// Store operation boundaries admit the primitive limit before reaching this helper.
|
|
3
|
-
export function assertFileStoreMaxBytes(size, limit) {
|
|
4
|
-
if (limit !== undefined && size > limit) {
|
|
5
|
-
throw new FsSafeError("too-large", `file exceeds maximum size of ${limit} bytes`);
|
|
6
|
-
}
|
|
7
|
-
}
|
package/dist/file-store-path.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { FsSafeError } from "./errors.js";
|
|
3
|
-
import { isPathInside, splitSafeRelativePath } from "./path.js";
|
|
4
|
-
export function assertRelativePath(relativePath) {
|
|
5
|
-
const raw = relativePath.trim();
|
|
6
|
-
if (!raw || raw !== relativePath) {
|
|
7
|
-
throw new FsSafeError("invalid-path", "store key must be non-empty and unpadded");
|
|
8
|
-
}
|
|
9
|
-
const segments = splitSafeRelativePath(raw);
|
|
10
|
-
if (segments.length === 0 ||
|
|
11
|
-
segments.join("/") !== raw ||
|
|
12
|
-
raw.normalize("NFC") !== raw ||
|
|
13
|
-
segments.some((segment) => /[ .]$/u.test(segment))) {
|
|
14
|
-
throw new FsSafeError("invalid-path", "store key must use one canonical relative spelling");
|
|
15
|
-
}
|
|
16
|
-
return raw;
|
|
17
|
-
}
|
|
18
|
-
export function resolveStorePath(rootDir, relativePath) {
|
|
19
|
-
const key = assertRelativePath(relativePath);
|
|
20
|
-
// FileStore constructors snapshot an absolute root before this helper runs.
|
|
21
|
-
// Do not re-resolve it: Node drops the trailing separator from an exact
|
|
22
|
-
// Windows namespace drive root such as `\\?\C:\`.
|
|
23
|
-
const root = path.isAbsolute(rootDir) ? rootDir : path.resolve(rootDir);
|
|
24
|
-
// The immutable key already passed segment validation; keep the containment check.
|
|
25
|
-
const target = path.resolve(root, key);
|
|
26
|
-
if (!isPathInside(root, target)) {
|
|
27
|
-
throw new FsSafeError("outside-workspace", "relative path escapes root");
|
|
28
|
-
}
|
|
29
|
-
return target;
|
|
30
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function admitStandalonePublicationPath(value: string, message?: string): string;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { anchorWindowsDriveRelativePath, assertNoWindowsPathAlias, } from "./windows-path-alias.js";
|
|
2
|
-
export function admitStandalonePublicationPath(value, message) {
|
|
3
|
-
const admittedPath = anchorWindowsDriveRelativePath(value);
|
|
4
|
-
assertNoWindowsPathAlias(admittedPath, "filesystem", message);
|
|
5
|
-
return admittedPath;
|
|
6
|
-
}
|