




















@@ -12,6 +12,8 @@ import { normalizeOptionalLowercaseString } from "../../shared/string-coerce.js"
1212import { splitSandboxBindSpec } from "./bind-spec.js";
1313import { SANDBOX_AGENT_WORKSPACE_MOUNT } from "./constants.js";
1414import {
15+getSandboxHostPathPolicyKey,
16+isSandboxHostPathAbsolute,
1517normalizeSandboxHostPath,
1618resolveSandboxHostPathViaExistingAncestor,
1719} from "./host-paths.js";
@@ -101,6 +103,7 @@ function parseBindTargetPath(bind: string): string {
101103102104/**
103105 * Normalize a POSIX path: resolve `.`, `..`, collapse `//`, strip trailing `/`.
106+ * If it starts with the drive letter, convert it to the upper case.
104107 */
105108function normalizeHostPath(raw: string): string {
106109return normalizeSandboxHostPath(raw);
@@ -115,10 +118,9 @@ function normalizeHostPath(raw: string): string {
115118 */
116119export function getBlockedBindReason(bind: string): BlockedBindReason | null {
117120const sourceRaw = parseBindSourcePath(bind);
118-if (!sourceRaw.startsWith("/")) {
121+if (!isSandboxHostPathAbsolute(sourceRaw)) {
119122return { kind: "non_absolute", sourcePath: sourceRaw };
120123}
121-122124const normalized = normalizeHostPath(sourceRaw);
123125const blockedHostPaths = getBlockedHostPaths();
124126const directReason = getBlockedReasonForSourcePath(normalized, blockedHostPaths);
@@ -141,8 +143,10 @@ function getBlockedReasonForSourcePath(
141143if (sourceNormalized === "/") {
142144return { kind: "covers", blockedPath: "/" };
143145}
146+const sourceKey = getSandboxHostPathPolicyKey(sourceNormalized);
144147for (const blocked of blockedHostPaths) {
145-if (sourceNormalized === blocked || sourceNormalized.startsWith(blocked + "/")) {
148+const blockedKey = getSandboxHostPathPolicyKey(blocked);
149+if (sourceKey === blockedKey || sourceKey.startsWith(`${blockedKey}/`)) {
146150return { kind: "targets", blockedPath: blocked };
147151}
148152}
@@ -193,7 +197,7 @@ function normalizeAllowedRoots(roots: string[] | undefined): string[] {
193197}
194198const normalized = roots
195199.map((entry) => entry.trim())
196-.filter((entry) => entry.startsWith("/"))
200+.filter(isSandboxHostPathAbsolute)
197201.map(normalizeHostPath);
198202const expanded = new Set<string>();
199203for (const root of normalized) {
@@ -210,7 +214,9 @@ function isPathInsidePosix(root: string, target: string): boolean {
210214if (root === "/") {
211215return true;
212216}
213-return target === root || target.startsWith(`${root}/`);
217+const rootKey = getSandboxHostPathPolicyKey(root);
218+const targetKey = getSandboxHostPathPolicyKey(target);
219+return targetKey === rootKey || targetKey.startsWith(`${rootKey}/`);
214220}
215221216222function getOutsideAllowedRootsReason(
@@ -274,7 +280,7 @@ function formatBindBlockedError(params: { bind: string; reason: BlockedBindReaso
274280if (params.reason.kind === "non_absolute") {
275281return new Error(
276282`Sandbox security: bind mount "${params.bind}" uses a non-absolute source path ` +
277-`"${params.reason.sourcePath}". Only absolute POSIX paths are supported for sandbox binds.`,
283+`"${params.reason.sourcePath}". Only absolute POSIX or Windows drive-letter paths are supported for sandbox binds.`,
278284);
279285}
280286if (params.reason.kind === "outside_allowed_roots") {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。