Skip to content

Commit af28131

Browse files
committed
fix(security): block Windows USERPROFILE credential binds
1 parent 5abb4b1 commit af28131

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎src/agents/sandbox/validate-sandbox-security.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ describe("getBlockedBindReason", () => {
6868
expect(reason?.blockedPath).toBe("/home/tester/.gnupg");
6969
});
7070

71+
it("blocks Windows USERPROFILE credential paths when HOME points elsewhere", () => {
72+
vi.stubEnv("HOME", "D:\\Users\\shell-home");
73+
vi.stubEnv("USERPROFILE", "C:\\Users\\tester");
74+
75+
const reason = expectBlockedTargetReason(
76+
"C:\\Users\\tester\\.docker\\config.json:/mnt/docker:ro",
77+
);
78+
expect(reason?.blockedPath).toBe("C:/Users/tester/.docker");
79+
});
80+
7181
it("blocks canonical OS-home aliases for credential paths", () => {
7282
if (process.platform === "win32") {
7383
return;

‎src/agents/sandbox/validate-sandbox-security.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ function getBlockedHostPaths(): string[] {
159159
home: process.env.HOME,
160160
openclawHome: process.env.OPENCLAW_HOME,
161161
osHome: os.homedir(),
162+
userProfile: process.env.USERPROFILE,
162163
});
163164
if (blockedHostPathsCache?.key === cacheKey) {
164165
return blockedHostPathsCache.paths;
@@ -176,9 +177,15 @@ function getBlockedHostPaths(): string[] {
176177
function getBlockedHomeRoots(): string[] {
177178
const roots = new Set<string>();
178179
for (const candidate of [
180+
process.env.OPENCLAW_HOME,
181+
process.env.HOME,
182+
process.env.USERPROFILE,
179183
resolveRequiredHomeDir(process.env, os.homedir),
180184
resolveRequiredOsHomeDir(process.env, os.homedir),
181185
]) {
186+
if (!candidate) {
187+
continue;
188+
}
182189
const normalized = normalizeHostPath(candidate);
183190
if (normalized !== "/") {
184191
roots.add(normalized);

0 commit comments

Comments
 (0)