Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ export const getFileSystemHelperFunctions = (node: INode): FileSystemHelperFunct
}
return await fsWriteFile(filePath, content, { encoding: 'binary', flag });
},

isFilePathBlocked,
});

/**
Expand Down
15 changes: 14 additions & 1 deletion packages/nodes-base/nodes/Git/Git.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import type {
INodeType,
INodeTypeDescription,
} from 'n8n-workflow';
import { NodeConnectionTypes, assertParamIsBoolean, assertParamIsString } from 'n8n-workflow';
import {
NodeConnectionTypes,
NodeOperationError,
assertParamIsBoolean,
assertParamIsString,
} from 'n8n-workflow';
import type { LogOptions, SimpleGit, SimpleGitOptions } from 'simple-git';
import simpleGit from 'simple-git';
import { URL } from 'url';
Expand Down Expand Up @@ -282,6 +287,14 @@ export class Git implements INodeType {
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
try {
const repositoryPath = this.getNodeParameter('repositoryPath', itemIndex, '') as string;
const isFilePathBlocked = await this.helpers.isFilePathBlocked(repositoryPath);
if (isFilePathBlocked) {
throw new NodeOperationError(
this.getNode(),
'Access to the repository path is not allowed',
);
}

const options = this.getNodeParameter('options', itemIndex, {});

if (operation === 'clone') {
Expand Down
11 changes: 11 additions & 0 deletions packages/nodes-base/nodes/Git/__test__/Git.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('Git Node', () => {
getInputData: jest.fn().mockReturnValue([{ json: {} }]),
getNodeParameter: jest.fn(),
helpers: {
isFilePathBlocked: jest.fn(),
returnJsonArray: jest
.fn()
.mockImplementation((data: unknown[]) => data.map((item: unknown) => ({ json: item }))),
Expand Down Expand Up @@ -141,4 +142,14 @@ describe('Git Node', () => {
);
});
});

describe('Restricted file paths', () => {
it('should throw an error if the repository path is blocked', async () => {
(executeFunctions.helpers.isFilePathBlocked as jest.Mock).mockResolvedValue(true);

await expect(gitNode.execute.call(executeFunctions)).rejects.toThrow(
'Access to the repository path is not allowed',
);
});
});
});
1 change: 1 addition & 0 deletions packages/workflow/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ export interface BaseHelperFunctions {
}

export interface FileSystemHelperFunctions {
isFilePathBlocked(filePath: string): Promise<boolean>;
createReadStream(path: PathLike): Promise<Readable>;
getStoragePath(): string;
writeContentToFile(
Expand Down
Loading