fix(AWS SNS Trigger Node): add missing jsonParse import (#4463)

* fix(AwsSnsTrigger): add missing jsonParse import

* add clear typings for req.rawBody and getHeaderData()
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2022-10-28 11:24:11 +02:00 committed by GitHub
parent d9a41ea9d7
commit e6ec134cf3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 17 additions and 30 deletions

View file

@ -622,7 +622,6 @@ class App {
// Make sure that each request has the "parsedUrl" parameter
this.app.use((req: express.Request, res: express.Response, next: express.NextFunction) => {
(req as ICustomRequest).parsedUrl = parseUrl(req);
// @ts-ignore
req.rawBody = Buffer.from('', 'base64');
next();
});
@ -632,7 +631,6 @@ class App {
bodyParser.json({
limit: `${this.payloadSizeMax}mb`,
verify: (req, res, buf) => {
// @ts-ignore
req.rawBody = buf;
},
}),
@ -649,7 +647,6 @@ class App {
explicitArray: false, // Only put properties in array if length > 1
},
verify: (req: express.Request, res: any, buf: any) => {
// @ts-ignore
req.rawBody = buf;
},
}),
@ -659,7 +656,6 @@ class App {
bodyParser.text({
limit: `${this.payloadSizeMax}mb`,
verify: (req, res, buf) => {
// @ts-ignore
req.rawBody = buf;
},
}),
@ -685,7 +681,6 @@ class App {
limit: `${this.payloadSizeMax}mb`,
extended: false,
verify: (req, res, buf) => {
// @ts-ignore
req.rawBody = buf;
},
}),

View file

@ -236,7 +236,6 @@ class App {
// Make sure that each request has the "parsedUrl" parameter
this.app.use((req: express.Request, res: express.Response, next: express.NextFunction) => {
(req as ICustomRequest).parsedUrl = parseUrl(req);
// @ts-ignore
req.rawBody = Buffer.from('', 'base64');
next();
});
@ -246,7 +245,6 @@ class App {
bodyParser.json({
limit: '16mb',
verify: (req, res, buf) => {
// @ts-ignore
req.rawBody = buf;
},
}),
@ -269,7 +267,6 @@ class App {
bodyParser.text({
limit: '16mb',
verify: (req, res, buf) => {
// @ts-ignore
req.rawBody = buf;
},
}),
@ -280,7 +277,6 @@ class App {
bodyParser.urlencoded({
extended: false,
verify: (req, res, buf) => {
// @ts-ignore
req.rawBody = buf;
},
}),

View file

@ -74,7 +74,7 @@ import crypto, { createHmac } from 'crypto';
// eslint-disable-next-line import/no-extraneous-dependencies
import { get } from 'lodash';
// eslint-disable-next-line import/no-extraneous-dependencies
import express from 'express';
import type { Request, Response } from 'express';
import FormData from 'form-data';
import path from 'path';
import { OptionsWithUri, OptionsWithUrl } from 'request';
@ -103,6 +103,7 @@ import {
} from '.';
import { extractValue } from './ExtractValue';
import { getClientCredentialsToken } from './OAuth2Helper';
import { IncomingHttpHeaders } from 'http';
axios.defaults.timeout = 300000;
// Prevent axios from adding x-form-www-urlencoded headers by default
@ -2937,7 +2938,7 @@ export function getExecuteWebhookFunctions(
async getCredentials(type: string): Promise<ICredentialDataDecryptedObject> {
return getCredentials(workflow, node, type, additionalData, mode);
},
getHeaderData(): object {
getHeaderData(): IncomingHttpHeaders {
if (additionalData.httpRequest === undefined) {
throw new Error('Request is missing!');
}
@ -2987,13 +2988,13 @@ export function getExecuteWebhookFunctions(
}
return additionalData.httpRequest.query;
},
getRequestObject(): express.Request {
getRequestObject(): Request {
if (additionalData.httpRequest === undefined) {
throw new Error('Request is missing!');
}
return additionalData.httpRequest;
},
getResponseObject(): express.Response {
getResponseObject(): Response {
if (additionalData.httpResponse === undefined) {
throw new Error('Response is missing!');
}

View file

@ -19,3 +19,9 @@ export * from './LoadNodeListSearch';
export * from './NodeExecuteFunctions';
export * from './WorkflowExecute';
export { NodeExecuteFunctions, UserSettings };
declare module 'http' {
export interface IncomingMessage {
rawBody: Buffer;
}
}

View file

@ -6,7 +6,7 @@ import {
INodeType,
INodeTypeDescription,
IWebhookResponseData,
NodeApiError,
jsonParse,
NodeOperationError,
} from 'n8n-workflow';
@ -177,8 +177,9 @@ export class AwsSnsTrigger implements INodeType {
const req = this.getRequestObject();
const topic = this.getNodeParameter('topic') as string;
// @ts-ignore
const body = jsonParse(req.rawBody.toString());
const body = jsonParse<{ Type: string; TopicArn: string; Token: string }>(
req.rawBody.toString(),
);
if (body.Type === 'SubscriptionConfirmation' && body.TopicArn === topic) {
const { Token } = body;

View file

@ -587,7 +587,6 @@ export class CiscoWebexTrigger implements INodeType {
//@ts-ignore
const computedSignature = createHmac('sha1', webhookData.secret)
//@ts-ignore
.update(req.rawBody)
.digest('hex');
if (headers['x-spark-signature'] !== computedSignature) {

View file

@ -268,7 +268,6 @@ export class FacebookTrigger implements INodeType {
// validate signature if app secret is set
if (credentials.appSecret !== '') {
const computedSignature = createHmac('sha1', credentials.appSecret as string)
//@ts-ignore
.update(req.rawBody)
.digest('hex');
if (headerData['x-hub-signature'] !== `sha1=${computedSignature}`) {

View file

@ -189,7 +189,6 @@ export class HelpScoutTrigger implements INodeType {
}
const computedSignature = createHmac('sha1', webhookData.secret as string)
//@ts-ignore
.update(req.rawBody)
.digest('base64');
if (headerData['x-helpscout-signature'] !== computedSignature) {

View file

@ -157,7 +157,6 @@ export class JotFormTrigger implements INodeType {
},
};
//@ts-ignore
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
const req = this.getRequestObject();
const formId = this.getNodeParameter('form') as string;

View file

@ -119,7 +119,6 @@ export class MailjetTrigger implements INodeType {
},
};
//@ts-ignore
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
const req = this.getRequestObject();
return {

View file

@ -412,7 +412,6 @@ export class ShopifyTrigger implements INodeType {
headerData['x-shopify-shop-domain'] !== undefined &&
headerData['x-shopify-api-version'] !== undefined
) {
// @ts-ignore
const computedSignature = createHmac('sha256', secret).update(req.rawBody).digest('base64');
if (headerData['x-shopify-hmac-sha256'] !== computedSignature) {

View file

@ -781,7 +781,6 @@ export class Wait implements INodeType {
if (options.rawBody) {
response.binary = {
data: {
// @ts-ignore
data: req.rawBody.toString(BINARY_ENCODING),
mimeType,
},

View file

@ -593,7 +593,6 @@ export class Webhook implements INodeType {
if (options.rawBody) {
response.binary = {
data: {
// @ts-ignore
data: req.rawBody.toString(BINARY_ENCODING),
mimeType,
},

View file

@ -182,7 +182,6 @@ export class WiseTrigger implements INodeType {
const publicKey =
credentials.environment === 'test' ? testPublicKey : (livePublicKey as string);
//@ts-ignore
const sig = createVerify('RSA-SHA1').update(req.rawBody);
const verified = sig.verify(publicKey, signature, 'base64');

View file

@ -156,21 +156,17 @@ export class WooCommerceTrigger implements INodeType {
},
};
//@ts-ignore
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
const req = this.getRequestObject();
const headerData = this.getHeaderData();
const webhookData = this.getWorkflowStaticData('node');
//@ts-ignore
if (headerData['x-wc-webhook-id'] === undefined) {
return {};
}
const computedSignature = createHmac('sha256', webhookData.secret as string)
//@ts-ignore
.update(req.rawBody)
.digest('base64');
//@ts-ignore
if (headerData['x-wc-webhook-signature'] !== computedSignature) {
// Signature is not valid so ignore call
return {};

View file

@ -4,6 +4,7 @@
// eslint-disable-next-line max-classes-per-file
import * as express from 'express';
import * as FormData from 'form-data';
import type { IncomingHttpHeaders } from 'http';
import type { URLSearchParams } from 'url';
import type { IDeferredPromise } from './DeferredPromise';
import type { Workflow } from './Workflow';
@ -784,7 +785,7 @@ export interface ITriggerFunctions {
export interface IWebhookFunctions {
getBodyData(): IDataObject;
getCredentials(type: string): Promise<ICredentialDataDecryptedObject>;
getHeaderData(): object;
getHeaderData(): IncomingHttpHeaders;
getMode(): WorkflowExecuteMode;
getNode(): INode;
getNodeParameter(