From 3128cbf874bb6647063aea8613b572ff8e7f7894 Mon Sep 17 00:00:00 2001 From: pemontto Date: Thu, 9 Dec 2021 13:28:14 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20Add=20option=20to=20ignore=20re?= =?UTF-8?q?quests=20from=20bots?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/nodes-base/nodes/Wait/Wait.node.ts | 13 +++++++++++++ packages/nodes-base/nodes/Webhook/Webhook.node.ts | 14 ++++++++++++++ packages/nodes-base/package.json | 1 + 3 files changed, 28 insertions(+) diff --git a/packages/nodes-base/nodes/Wait/Wait.node.ts b/packages/nodes-base/nodes/Wait/Wait.node.ts index aa931c468c9..3176747badf 100644 --- a/packages/nodes-base/nodes/Wait/Wait.node.ts +++ b/packages/nodes-base/nodes/Wait/Wait.node.ts @@ -21,6 +21,7 @@ import * as fs from 'fs'; import * as formidable from 'formidable'; +import * as isbot from 'isbot'; function authorizationError(resp: Response, realm: string, responseCode: number, message?: string) { if (message === undefined) { @@ -627,6 +628,13 @@ export class Wait implements INodeType { placeholder: 'webhook', description: 'This suffix path will be appended to the restart URL. Helpful when using multiple wait nodes. Note: Does not support expressions.', }, + { + displayName: 'Ignore Bots', + name: 'ignoreBots', + type: 'boolean', + default: false, + description: 'Set to true to ignore requests from bots like link previewers and web crawlers', + }, // { // displayName: 'Raw Body', // name: 'rawBody', @@ -656,6 +664,11 @@ export class Wait implements INodeType { const headers = this.getHeaderData(); const realm = 'Webhook'; + const ignoreBots = options.ignoreBots as boolean; + if (ignoreBots && isbot((headers as IDataObject)['user-agent'] as string)) { + return authorizationError(resp, realm, 403); + } + if (incomingAuthentication === 'basicAuth') { // Basic authorization is needed to call webhook const httpBasicAuth = await this.getCredentials('httpBasicAuth'); diff --git a/packages/nodes-base/nodes/Webhook/Webhook.node.ts b/packages/nodes-base/nodes/Webhook/Webhook.node.ts index 7ce48004a5a..0f320a0f994 100644 --- a/packages/nodes-base/nodes/Webhook/Webhook.node.ts +++ b/packages/nodes-base/nodes/Webhook/Webhook.node.ts @@ -20,6 +20,8 @@ import * as fs from 'fs'; import * as formidable from 'formidable'; +import * as isbot from 'isbot'; + function authorizationError(resp: Response, realm: string, responseCode: number, message?: string) { if (message === undefined) { message = 'Authorization problem!'; @@ -379,6 +381,13 @@ export class Webhook implements INodeType { default: false, description: 'Raw body (binary)', }, + { + displayName: 'Ignore Bots', + name: 'ignoreBots', + type: 'boolean', + default: false, + description: 'Set to true to ignore requests from bots like link previewers and web crawlers', + }, ], }, ], @@ -392,6 +401,11 @@ export class Webhook implements INodeType { const headers = this.getHeaderData(); const realm = 'Webhook'; + const ignoreBots = options.ignoreBots as boolean; + if (ignoreBots && isbot((headers as IDataObject)['user-agent'] as string)) { + return authorizationError(resp, realm, 403); + } + if (authentication === 'basicAuth') { // Basic authorization is needed to call webhook const httpBasicAuth = await this.getCredentials('httpBasicAuth'); diff --git a/packages/nodes-base/package.json b/packages/nodes-base/package.json index 2da78b154af..6771c0ca1be 100644 --- a/packages/nodes-base/package.json +++ b/packages/nodes-base/package.json @@ -702,6 +702,7 @@ "iconv-lite": "^0.6.2", "ics": "^2.27.0", "imap-simple": "^4.3.0", + "isbot": "^3.3.4", "iso-639-1": "^2.1.3", "jsonwebtoken": "^8.5.1", "kafkajs": "^1.14.0", From 4cb52c710fa29c358fa651641a6119687f362a3d Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Sun, 2 Jan 2022 10:20:12 +0100 Subject: [PATCH 2/2] :zap: Fix parameter "Ignore Bots" parameter order --- package-lock.json | 37 +++---------------- packages/nodes-base/nodes/Wait/Wait.node.ts | 14 +++---- .../nodes-base/nodes/Webhook/Webhook.node.ts | 14 +++---- 3 files changed, 19 insertions(+), 46 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7feb7db3cbf..dfd286cdc53 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27204,6 +27204,11 @@ "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" }, + "isbot": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/isbot/-/isbot-3.4.0.tgz", + "integrity": "sha512-0WOb6bbJ6gtpWVHQ30r5MzqvSrCNbZ70wFXAJWdXt/0LulF59uvBQnPgA7IelbOXEpV+CtLWkDxLB4TU7f0+VA==" + }, "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -33267,38 +33272,6 @@ "thenify-all": "^1.0.0" } }, - "n8n-core": { - "version": "0.96.0", - "resolved": "https://registry.npmjs.org/n8n-core/-/n8n-core-0.96.0.tgz", - "integrity": "sha512-FwcLt9tYATP2FJkEkiGlbQCdzzdShTcXfpd6ba0RDeOAwvKK+IIoMvlnaU4ClhJX5og7wvLDouAOWRj9UjjdRQ==", - "requires": { - "axios": "^0.21.1", - "client-oauth2": "^4.2.5", - "cron": "~1.7.2", - "crypto-js": "~4.1.1", - "file-type": "^14.6.2", - "form-data": "^4.0.0", - "lodash.get": "^4.4.2", - "mime-types": "^2.1.27", - "n8n-workflow": "~0.79.0", - "oauth-1.0a": "^2.2.6", - "p-cancelable": "^2.0.0", - "qs": "^6.10.1", - "request": "^2.88.2", - "request-promise-native": "^1.0.7" - } - }, - "n8n-workflow": { - "version": "0.79.0", - "resolved": "https://registry.npmjs.org/n8n-workflow/-/n8n-workflow-0.79.0.tgz", - "integrity": "sha512-ylzM1l7M00gfAnCcQtdRn2DzYZ+7vyWu2gfVe5crpOJnuoLstYbUF+UgShXyrlugdMg6GV86w9mE0iRkgbMb/Q==", - "requires": { - "lodash.get": "^4.4.2", - "lodash.isequal": "^4.5.0", - "riot-tmpl": "^3.0.8", - "xml2js": "^0.4.23" - } - }, "named-placeholders": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.2.tgz", diff --git a/packages/nodes-base/nodes/Wait/Wait.node.ts b/packages/nodes-base/nodes/Wait/Wait.node.ts index 3176747badf..accc79f94d1 100644 --- a/packages/nodes-base/nodes/Wait/Wait.node.ts +++ b/packages/nodes-base/nodes/Wait/Wait.node.ts @@ -537,6 +537,13 @@ export class Wait implements INodeType { the received file. If the data gets received via "Form-Data Multipart" it will be the prefix and a number starting with 0 will be attached to it.`, }, + { + displayName: 'Ignore Bots', + name: 'ignoreBots', + type: 'boolean', + default: false, + description: 'Set to true to ignore requests from bots like link previewers and web crawlers', + }, { displayName: 'Response Data', name: 'responseData', @@ -628,13 +635,6 @@ export class Wait implements INodeType { placeholder: 'webhook', description: 'This suffix path will be appended to the restart URL. Helpful when using multiple wait nodes. Note: Does not support expressions.', }, - { - displayName: 'Ignore Bots', - name: 'ignoreBots', - type: 'boolean', - default: false, - description: 'Set to true to ignore requests from bots like link previewers and web crawlers', - }, // { // displayName: 'Raw Body', // name: 'rawBody', diff --git a/packages/nodes-base/nodes/Webhook/Webhook.node.ts b/packages/nodes-base/nodes/Webhook/Webhook.node.ts index efd6c5d4931..ad6b6cc2801 100644 --- a/packages/nodes-base/nodes/Webhook/Webhook.node.ts +++ b/packages/nodes-base/nodes/Webhook/Webhook.node.ts @@ -283,6 +283,13 @@ export class Webhook implements INodeType { the received file to. If the data gets received via "Form-Data Multipart" it will be the prefix and a number starting with 0 will be attached to it.`, }, + { + displayName: 'Ignore Bots', + name: 'ignoreBots', + type: 'boolean', + default: false, + description: 'Set to true to ignore requests from bots like link previewers and web crawlers', + }, { displayName: 'Response Data', name: 'responseData', @@ -380,13 +387,6 @@ export class Webhook implements INodeType { default: false, description: 'Raw body (binary)', }, - { - displayName: 'Ignore Bots', - name: 'ignoreBots', - type: 'boolean', - default: false, - description: 'Set to true to ignore requests from bots like link previewers and web crawlers', - }, ], }, ],