fix(core): Remove temporary uploaded files from webhook calls (#18128)

Co-authored-by: Danny Martini <danny@n8n.io>
This commit is contained in:
Guillaume Jacquart
2025-08-08 20:37:35 +02:00
committed by GitHub
parent 11dcef36df
commit c610c3af3e
2 changed files with 10 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
/* eslint-disable n8n-nodes-base/node-execute-block-wrong-error-thrown */
import { createWriteStream } from 'fs';
import { stat } from 'fs/promises';
import { rm, stat } from 'fs/promises';
import isbot from 'isbot';
import type {
IWebhookFunctions,
@@ -363,6 +363,9 @@ export class Webhook extends Node {
file.mimetype,
);
// Delete original file to prevent tmp directory from growing too large
await rm(file.filepath, { force: true });
count += 1;
}
}

View File

@@ -1,10 +1,14 @@
import { NodeTestHarness } from '@nodes-testing/node-test-harness';
import type { Request, Response } from 'express';
import fs from 'fs/promises';
import { mock } from 'jest-mock-extended';
import type { IWebhookFunctions } from 'n8n-workflow';
import { Webhook } from '../Webhook.node';
jest.mock('fs/promises');
const mockFs = jest.mocked(fs);
describe('Test Webhook Node', () => {
new NodeTestHarness().setupTests();
@@ -33,11 +37,12 @@ describe('Test Webhook Node', () => {
it('should handle when files are present', async () => {
req.body = {
files: { file1: {} },
files: { file1: { filepath: '/tmp/test.txt' } },
};
const returnData = await node.webhook(context);
expect(returnData.workflowData?.[0][0].binary).not.toBeUndefined();
expect(context.nodeHelpers.copyBinaryFile).toHaveBeenCalled();
expect(mockFs.rm).toHaveBeenCalledWith('/tmp/test.txt', { force: true });
});
});