Skip to content

Commit 7195795

Browse files
committed
fix(apple-runner): refuse cleanup through symlink overrides
1 parent 2579b76 commit 7195795

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎packages/apple-runner/src/runner-cache.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,15 @@ export function assertSafeDerivedCleanup(
316316
function isPathInsideProjectTmp(targetPath: string, projectRoot: string): boolean {
317317
const projectTmpRoot = path.resolve(projectRoot, '.tmp');
318318
const relativePath = path.relative(projectTmpRoot, path.resolve(targetPath));
319-
return relativePath !== '' && !relativePath.startsWith('..') && !path.isAbsolute(relativePath);
319+
if (relativePath === '' || relativePath.startsWith('..') || path.isAbsolute(relativePath)) {
320+
return false;
321+
}
322+
let candidate = projectTmpRoot;
323+
for (const segment of ['', ...relativePath.split(path.sep)]) {
324+
candidate = path.join(candidate, segment);
325+
if (fs.lstatSync(candidate, { throwIfNoEntry: false })?.isSymbolicLink()) return false;
326+
}
327+
return true;
320328
}
321329

322330
export async function evaluateExistingXctestrun(options: {

‎scripts/__tests__/runner-isolation-diagnostics.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,24 @@ describe('scripts/build-xcuitest-apple.sh cleanup', () => {
255255
}
256256
});
257257
});
258+
259+
for (const [name, suffix] of [
260+
['derived root', ''],
261+
['ancestor', 'nested'],
262+
] as const) {
263+
test(`cleanup refuses a symlink at the ${name} and preserves its target`, () => {
264+
const outside = mkdtempForTestSync('runner-clean-outside-');
265+
fs.mkdirSync(path.join(repoRoot, '.tmp'), { recursive: true });
266+
const scratch = fs.mkdtempSync(path.join(repoRoot, '.tmp', 'runner-clean-link-'));
267+
const link = path.join(scratch, 'link');
268+
fs.symlinkSync(outside, link, 'dir');
269+
try {
270+
const result = runBuildScript('', 65, { clean: true, derived: path.join(link, suffix) });
271+
expect(fs.readFileSync(path.join(outside, suffix, 'Build', 'sentinel'), 'utf8')).toBe('keep');
272+
expect(result.status).toBe(1);
273+
expect(fs.existsSync(result.xcodebuildArgs)).toBe(false);
274+
} finally {
275+
fs.rmSync(scratch, { recursive: true, force: true });
276+
}
277+
});
278+
}

0 commit comments

Comments
 (0)