mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 11:11:23 +00:00
fix(sandbox): reject hardlinked tmp media aliases
This commit is contained in:
committed by
Peter Steinberger
parent
a01849e163
commit
22689b9dc9
@@ -187,9 +187,30 @@ async function resolveAllowedTmpMediaPath(params: {
|
||||
return undefined;
|
||||
}
|
||||
await assertNoSymlinkEscape(path.relative(openClawTmpDir, resolved), openClawTmpDir);
|
||||
await assertNoHardlinkedFinalPath(resolved, openClawTmpDir);
|
||||
return resolved;
|
||||
}
|
||||
|
||||
async function assertNoHardlinkedFinalPath(filePath: string, root: string): Promise<void> {
|
||||
let stat: Awaited<ReturnType<typeof fs.stat>>;
|
||||
try {
|
||||
stat = await fs.stat(filePath);
|
||||
} catch (err) {
|
||||
if (isNotFoundPathError(err)) {
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
if (!stat.isFile()) {
|
||||
return;
|
||||
}
|
||||
if (stat.nlink > 1) {
|
||||
throw new Error(
|
||||
`Hardlinked tmp media path is not allowed under sandbox root (${shortPath(root)}): ${shortPath(filePath)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function assertNoSymlinkEscape(
|
||||
relative: string,
|
||||
root: string,
|
||||
|
||||
Reference in New Issue
Block a user