mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 12:57:29 -08:00
✨ Add option to ignore requests from bots
This commit is contained in:
parent
6453996de3
commit
3128cbf874
|
@ -21,6 +21,7 @@ import * as fs from 'fs';
|
||||||
|
|
||||||
import * as formidable from 'formidable';
|
import * as formidable from 'formidable';
|
||||||
|
|
||||||
|
import * as isbot from 'isbot';
|
||||||
|
|
||||||
function authorizationError(resp: Response, realm: string, responseCode: number, message?: string) {
|
function authorizationError(resp: Response, realm: string, responseCode: number, message?: string) {
|
||||||
if (message === undefined) {
|
if (message === undefined) {
|
||||||
|
@ -627,6 +628,13 @@ export class Wait implements INodeType {
|
||||||
placeholder: 'webhook',
|
placeholder: 'webhook',
|
||||||
description: 'This suffix path will be appended to the restart URL. Helpful when using multiple wait nodes. Note: Does not support expressions.',
|
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',
|
// displayName: 'Raw Body',
|
||||||
// name: 'rawBody',
|
// name: 'rawBody',
|
||||||
|
@ -656,6 +664,11 @@ export class Wait implements INodeType {
|
||||||
const headers = this.getHeaderData();
|
const headers = this.getHeaderData();
|
||||||
const realm = 'Webhook';
|
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') {
|
if (incomingAuthentication === 'basicAuth') {
|
||||||
// Basic authorization is needed to call webhook
|
// Basic authorization is needed to call webhook
|
||||||
const httpBasicAuth = await this.getCredentials('httpBasicAuth');
|
const httpBasicAuth = await this.getCredentials('httpBasicAuth');
|
||||||
|
|
|
@ -20,6 +20,8 @@ import * as fs from 'fs';
|
||||||
|
|
||||||
import * as formidable from 'formidable';
|
import * as formidable from 'formidable';
|
||||||
|
|
||||||
|
import * as isbot from 'isbot';
|
||||||
|
|
||||||
function authorizationError(resp: Response, realm: string, responseCode: number, message?: string) {
|
function authorizationError(resp: Response, realm: string, responseCode: number, message?: string) {
|
||||||
if (message === undefined) {
|
if (message === undefined) {
|
||||||
message = 'Authorization problem!';
|
message = 'Authorization problem!';
|
||||||
|
@ -379,6 +381,13 @@ export class Webhook implements INodeType {
|
||||||
default: false,
|
default: false,
|
||||||
description: 'Raw body (binary)',
|
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 headers = this.getHeaderData();
|
||||||
const realm = 'Webhook';
|
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') {
|
if (authentication === 'basicAuth') {
|
||||||
// Basic authorization is needed to call webhook
|
// Basic authorization is needed to call webhook
|
||||||
const httpBasicAuth = await this.getCredentials('httpBasicAuth');
|
const httpBasicAuth = await this.getCredentials('httpBasicAuth');
|
||||||
|
|
|
@ -702,6 +702,7 @@
|
||||||
"iconv-lite": "^0.6.2",
|
"iconv-lite": "^0.6.2",
|
||||||
"ics": "^2.27.0",
|
"ics": "^2.27.0",
|
||||||
"imap-simple": "^4.3.0",
|
"imap-simple": "^4.3.0",
|
||||||
|
"isbot": "^3.3.4",
|
||||||
"iso-639-1": "^2.1.3",
|
"iso-639-1": "^2.1.3",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"kafkajs": "^1.14.0",
|
"kafkajs": "^1.14.0",
|
||||||
|
|
Loading…
Reference in a new issue