mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(core): Restrict read/write file paths access (#6582)
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
import type { Readable } from 'stream';
|
||||
|
||||
import { BINARY_ENCODING } from 'n8n-workflow';
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
import { BINARY_ENCODING } from 'n8n-workflow';
|
||||
|
||||
import { writeFile as fsWriteFile } from 'fs/promises';
|
||||
import type { Readable } from 'stream';
|
||||
|
||||
export class WriteBinaryFile implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -73,9 +72,10 @@ export class WriteBinaryFile implements INodeType {
|
||||
const dataPropertyName = this.getNodeParameter('dataPropertyName', itemIndex);
|
||||
|
||||
const fileName = this.getNodeParameter('fileName', itemIndex) as string;
|
||||
|
||||
const options = this.getNodeParameter('options', 0, {});
|
||||
|
||||
const flag = options.append ? 'a' : 'w';
|
||||
const flag: string = options.append ? 'a' : 'w';
|
||||
|
||||
item = items[itemIndex];
|
||||
|
||||
@@ -97,7 +97,8 @@ export class WriteBinaryFile implements INodeType {
|
||||
}
|
||||
|
||||
// Write the file to disk
|
||||
await fsWriteFile(fileName, fileContent, { encoding: 'binary', flag });
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
await this.helpers.writeContentToFile(fileName, fileContent, flag);
|
||||
|
||||
if (item.binary !== undefined) {
|
||||
// Create a shallow copy of the binary data so that the old
|
||||
@@ -116,7 +117,7 @@ export class WriteBinaryFile implements INodeType {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({
|
||||
json: {
|
||||
error: error.message,
|
||||
error: (error as Error).message,
|
||||
},
|
||||
pairedItem: {
|
||||
item: itemIndex,
|
||||
|
||||
Reference in New Issue
Block a user