mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-10 21:30:40 -07:00
fix(core): prevent infinite recursion in symlink resolution (#21750)
This commit is contained in:
@@ -484,6 +484,10 @@ describe('shortenPath', () => {
|
||||
});
|
||||
|
||||
describe('resolveToRealPath', () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
description:
|
||||
@@ -542,6 +546,28 @@ describe('resolveToRealPath', () => {
|
||||
|
||||
expect(resolveToRealPath(childPath)).toBe(expectedPath);
|
||||
});
|
||||
|
||||
it('should prevent infinite recursion on malicious symlink structures', () => {
|
||||
const maliciousPath = path.resolve('malicious', 'symlink');
|
||||
|
||||
vi.spyOn(fs, 'realpathSync').mockImplementation(() => {
|
||||
const err = new Error('ENOENT') as NodeJS.ErrnoException;
|
||||
err.code = 'ENOENT';
|
||||
throw err;
|
||||
});
|
||||
|
||||
vi.spyOn(fs, 'lstatSync').mockImplementation(
|
||||
() => ({ isSymbolicLink: () => true }) as fs.Stats,
|
||||
);
|
||||
|
||||
vi.spyOn(fs, 'readlinkSync').mockImplementation(() =>
|
||||
['..', 'malicious', 'symlink'].join(path.sep),
|
||||
);
|
||||
|
||||
expect(() => resolveToRealPath(maliciousPath)).toThrow(
|
||||
/Infinite recursion detected/,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('normalizePath', () => {
|
||||
|
||||
Reference in New Issue
Block a user