mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 16:14:58 +00:00
refactor: unify boundary-safe reads for bootstrap and includes
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import {
|
||||
assertNoPathAliasEscape,
|
||||
PATH_ALIAS_POLICIES,
|
||||
type PathAliasPolicy,
|
||||
} from "../../infra/path-alias-guards.js";
|
||||
import fs from "node:fs";
|
||||
import { openBoundaryFile } from "../../infra/boundary-file-read.js";
|
||||
import { PATH_ALIAS_POLICIES, type PathAliasPolicy } from "../../infra/path-alias-guards.js";
|
||||
import { execDockerRaw, type ExecDockerRawResult } from "./docker.js";
|
||||
import {
|
||||
buildSandboxFsMounts,
|
||||
@@ -24,6 +22,7 @@ type PathSafetyOptions = {
|
||||
action: string;
|
||||
aliasPolicy?: PathAliasPolicy;
|
||||
requireWritable?: boolean;
|
||||
allowMissingTarget?: boolean;
|
||||
};
|
||||
|
||||
export type SandboxResolvedPath = {
|
||||
@@ -254,12 +253,23 @@ class SandboxFsBridgeImpl implements SandboxFsBridge {
|
||||
);
|
||||
}
|
||||
|
||||
await assertNoPathAliasEscape({
|
||||
const guarded = await openBoundaryFile({
|
||||
absolutePath: target.hostPath,
|
||||
rootPath: lexicalMount.hostRoot,
|
||||
boundaryLabel: "sandbox mount root",
|
||||
policy: options.aliasPolicy,
|
||||
aliasPolicy: options.aliasPolicy,
|
||||
});
|
||||
if (!guarded.ok) {
|
||||
if (guarded.reason !== "path" || options.allowMissingTarget === false) {
|
||||
throw guarded.error instanceof Error
|
||||
? guarded.error
|
||||
: new Error(
|
||||
`Sandbox boundary checks failed; cannot ${options.action}: ${target.containerPath}`,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
fs.closeSync(guarded.fd);
|
||||
}
|
||||
|
||||
const canonicalContainerPath = await this.resolveCanonicalContainerPath({
|
||||
containerPath: target.containerPath,
|
||||
|
||||
Reference in New Issue
Block a user