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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -268,7 +268,6 @@ export class FacebookTrigger implements INodeType {
// validate signature if app secret is set // validate signature if app secret is set
if (credentials.appSecret !== '') { if (credentials.appSecret !== '') {
const computedSignature = createHmac('sha1', credentials.appSecret as string) const computedSignature = createHmac('sha1', credentials.appSecret as string)
//@ts-ignore
.update(req.rawBody) .update(req.rawBody)
.digest('hex'); .digest('hex');
if (headerData['x-hub-signature'] !== `sha1=${computedSignature}`) { 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) const computedSignature = createHmac('sha1', webhookData.secret as string)
//@ts-ignore
.update(req.rawBody) .update(req.rawBody)
.digest('base64'); .digest('base64');
if (headerData['x-helpscout-signature'] !== computedSignature) { 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> { async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
const req = this.getRequestObject(); const req = this.getRequestObject();
const formId = this.getNodeParameter('form') as string; 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> { async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
const req = this.getRequestObject(); const req = this.getRequestObject();
return { return {

View file

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

View file

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

View file

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

View file

@ -182,7 +182,6 @@ export class WiseTrigger implements INodeType {
const publicKey = const publicKey =
credentials.environment === 'test' ? testPublicKey : (livePublicKey as string); credentials.environment === 'test' ? testPublicKey : (livePublicKey as string);
//@ts-ignore
const sig = createVerify('RSA-SHA1').update(req.rawBody); const sig = createVerify('RSA-SHA1').update(req.rawBody);
const verified = sig.verify(publicKey, signature, 'base64'); 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> { async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
const req = this.getRequestObject(); const req = this.getRequestObject();
const headerData = this.getHeaderData(); const headerData = this.getHeaderData();
const webhookData = this.getWorkflowStaticData('node'); const webhookData = this.getWorkflowStaticData('node');
//@ts-ignore
if (headerData['x-wc-webhook-id'] === undefined) { if (headerData['x-wc-webhook-id'] === undefined) {
return {}; return {};
} }
const computedSignature = createHmac('sha256', webhookData.secret as string) const computedSignature = createHmac('sha256', webhookData.secret as string)
//@ts-ignore
.update(req.rawBody) .update(req.rawBody)
.digest('base64'); .digest('base64');
//@ts-ignore
if (headerData['x-wc-webhook-signature'] !== computedSignature) { if (headerData['x-wc-webhook-signature'] !== computedSignature) {
// Signature is not valid so ignore call // Signature is not valid so ignore call
return {}; return {};

View file

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