mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
feat(core): Use WebCrypto to generate all random numbers and strings (#9786)
This commit is contained in:
committed by
GitHub
parent
cfc4db00e3
commit
65c5609ab5
@@ -7,6 +7,7 @@ import type {
|
||||
INodeTypeDescription,
|
||||
IWebhookResponseData,
|
||||
} from 'n8n-workflow';
|
||||
import { randomString } from 'n8n-workflow';
|
||||
|
||||
import { helpscoutApiRequest, helpscoutApiRequestAllItems } from './GenericFunctions';
|
||||
|
||||
@@ -140,7 +141,7 @@ export class HelpScoutTrigger implements INodeType {
|
||||
const body = {
|
||||
url: webhookUrl,
|
||||
events,
|
||||
secret: Math.random().toString(36).substring(2, 15),
|
||||
secret: randomString(10).toLowerCase(),
|
||||
};
|
||||
|
||||
const responseData = await helpscoutApiRequest.call(
|
||||
|
||||
@@ -7,7 +7,7 @@ import type {
|
||||
INodeTypeBaseDescription,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
import { NodeOperationError, randomInt } from 'n8n-workflow';
|
||||
|
||||
import get from 'lodash/get';
|
||||
import isEmpty from 'lodash/isEmpty';
|
||||
@@ -52,7 +52,7 @@ const flattenKeys = (obj: IDataObject, path: string[] = []): IDataObject => {
|
||||
|
||||
const shuffleArray = (array: any[]) => {
|
||||
for (let i = array.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
const j = randomInt(i + 1);
|
||||
[array[i], array[j]] = [array[j], array[i]];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@ import type {
|
||||
INodeTypeDescription,
|
||||
IPairedItemData,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeOperationError, deepCopy } from 'n8n-workflow';
|
||||
import { NodeOperationError, deepCopy, randomInt } from 'n8n-workflow';
|
||||
|
||||
import get from 'lodash/get';
|
||||
import isEmpty from 'lodash/isEmpty';
|
||||
@@ -53,7 +53,7 @@ const flattenKeys = (obj: IDataObject, path: string[] = []): IDataObject => {
|
||||
|
||||
const shuffleArray = (array: any[]) => {
|
||||
for (let i = array.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
const j = randomInt(i + 1);
|
||||
[array[i], array[j]] = [array[j], array[i]];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -7,7 +7,7 @@ import type {
|
||||
INodeExecutionData,
|
||||
GenericValue,
|
||||
} from 'n8n-workflow';
|
||||
import { ApplicationError, NodeOperationError } from 'n8n-workflow';
|
||||
import { ApplicationError, NodeOperationError, randomInt } from 'n8n-workflow';
|
||||
|
||||
import get from 'lodash/get';
|
||||
import isEqual from 'lodash/isEqual';
|
||||
@@ -47,7 +47,7 @@ export const flattenKeys = (obj: IDataObject, path: string[] = []): IDataObject
|
||||
|
||||
export const shuffleArray = (array: any[]) => {
|
||||
for (let i = array.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
const j = randomInt(i + 1);
|
||||
[array[i], array[j]] = [array[j], array[i]];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@ import type {
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
import { randomString } from 'n8n-workflow';
|
||||
|
||||
import * as mqtt from 'mqtt';
|
||||
import { formatPrivateKey } from '@utils/utilities';
|
||||
@@ -116,7 +117,7 @@ export class Mqtt implements INodeType {
|
||||
const brokerUrl = `${protocol}://${host}`;
|
||||
const port = (credentials.port as number) || 1883;
|
||||
const clientId =
|
||||
(credentials.clientId as string) || `mqttjs_${Math.random().toString(16).substr(2, 8)}`;
|
||||
(credentials.clientId as string) || `mqttjs_${randomString(8).toLowerCase()}`;
|
||||
const clean = credentials.clean as boolean;
|
||||
const ssl = credentials.ssl as boolean;
|
||||
const ca = formatPrivateKey(credentials.ca as string);
|
||||
@@ -189,8 +190,7 @@ export class Mqtt implements INodeType {
|
||||
const host = credentials.host as string;
|
||||
const brokerUrl = `${protocol}://${host}`;
|
||||
const port = (credentials.port as number) || 1883;
|
||||
const clientId =
|
||||
(credentials.clientId as string) || `mqttjs_${Math.random().toString(16).substr(2, 8)}`;
|
||||
const clientId = (credentials.clientId as string) || `mqttjs_${randomString(8).toLowerCase()}`;
|
||||
const clean = credentials.clean as boolean;
|
||||
const ssl = credentials.ssl as boolean;
|
||||
const ca = credentials.ca as string;
|
||||
|
||||
@@ -7,7 +7,7 @@ import type {
|
||||
IDeferredPromise,
|
||||
IRun,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
import { NodeOperationError, randomString } from 'n8n-workflow';
|
||||
|
||||
import * as mqtt from 'mqtt';
|
||||
import { formatPrivateKey } from '@utils/utilities';
|
||||
@@ -109,8 +109,7 @@ export class MqttTrigger implements INodeType {
|
||||
const host = credentials.host as string;
|
||||
const brokerUrl = `${protocol}://${host}`;
|
||||
const port = (credentials.port as number) || 1883;
|
||||
const clientId =
|
||||
(credentials.clientId as string) || `mqttjs_${Math.random().toString(16).substr(2, 8)}`;
|
||||
const clientId = (credentials.clientId as string) || `mqttjs_${randomString(8).toLowerCase()}`;
|
||||
const clean = credentials.clean as boolean;
|
||||
const ssl = credentials.ssl as boolean;
|
||||
const ca = formatPrivateKey(credentials.ca as string);
|
||||
|
||||
@@ -6,7 +6,7 @@ import type {
|
||||
JsonObject,
|
||||
IRequestOptions,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError } from 'n8n-workflow';
|
||||
import { NodeApiError, randomInt } from 'n8n-workflow';
|
||||
|
||||
const serviceJSONRPC = 'object';
|
||||
const methodJSONRPC = 'execute';
|
||||
@@ -65,7 +65,7 @@ export interface IOdooNameValueFields {
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface IOdooResponceFields {
|
||||
export interface IOdooResponseFields {
|
||||
fields: Array<{
|
||||
field: string;
|
||||
fromList?: boolean;
|
||||
@@ -97,8 +97,8 @@ export function processNameValueFields(value: IDataObject) {
|
||||
}, {});
|
||||
}
|
||||
|
||||
// function processResponceFields(value: IDataObject) {
|
||||
// const data = value as unknown as IOdooResponceFields;
|
||||
// function processResponseFields(value: IDataObject) {
|
||||
// const data = value as unknown as IOdooResponseFields;
|
||||
// return data?.fields?.map((entry) => entry.field);
|
||||
// }
|
||||
|
||||
@@ -121,13 +121,13 @@ export async function odooJSONRPCRequest(
|
||||
json: true,
|
||||
};
|
||||
|
||||
const responce = await this.helpers.request(options);
|
||||
if (responce.error) {
|
||||
throw new NodeApiError(this.getNode(), responce.error.data as JsonObject, {
|
||||
message: responce.error.data.message,
|
||||
const response = await this.helpers.request(options);
|
||||
if (response.error) {
|
||||
throw new NodeApiError(this.getNode(), response.error.data as JsonObject, {
|
||||
message: response.error.data.message,
|
||||
});
|
||||
}
|
||||
return responce.result;
|
||||
return response.result;
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
}
|
||||
@@ -158,7 +158,7 @@ export async function odooGetModelFields(
|
||||
['string', 'type', 'help', 'required', 'name'],
|
||||
],
|
||||
},
|
||||
id: Math.floor(Math.random() * 100),
|
||||
id: randomInt(100),
|
||||
};
|
||||
|
||||
const result = await odooJSONRPCRequest.call(this, body, url);
|
||||
@@ -194,7 +194,7 @@ export async function odooCreate(
|
||||
newItem || {},
|
||||
],
|
||||
},
|
||||
id: Math.floor(Math.random() * 100),
|
||||
id: randomInt(100),
|
||||
};
|
||||
|
||||
const result = await odooJSONRPCRequest.call(this, body, url);
|
||||
@@ -238,7 +238,7 @@ export async function odooGet(
|
||||
fieldsToReturn || [],
|
||||
],
|
||||
},
|
||||
id: Math.floor(Math.random() * 100),
|
||||
id: randomInt(100),
|
||||
};
|
||||
|
||||
const result = await odooJSONRPCRequest.call(this, body, url);
|
||||
@@ -279,7 +279,7 @@ export async function odooGetAll(
|
||||
limit,
|
||||
],
|
||||
},
|
||||
id: Math.floor(Math.random() * 100),
|
||||
id: randomInt(100),
|
||||
};
|
||||
|
||||
const result = await odooJSONRPCRequest.call(this, body, url);
|
||||
@@ -329,7 +329,7 @@ export async function odooUpdate(
|
||||
fieldsToUpdate,
|
||||
],
|
||||
},
|
||||
id: Math.floor(Math.random() * 100),
|
||||
id: randomInt(100),
|
||||
};
|
||||
|
||||
await odooJSONRPCRequest.call(this, body, url);
|
||||
@@ -371,7 +371,7 @@ export async function odooDelete(
|
||||
itemsID ? [+itemsID] : [],
|
||||
],
|
||||
},
|
||||
id: Math.floor(Math.random() * 100),
|
||||
id: randomInt(100),
|
||||
};
|
||||
|
||||
await odooJSONRPCRequest.call(this, body, url);
|
||||
@@ -397,7 +397,7 @@ export async function odooGetUserID(
|
||||
method: 'login',
|
||||
args: [db, username, password],
|
||||
},
|
||||
id: Math.floor(Math.random() * 100),
|
||||
id: randomInt(100),
|
||||
};
|
||||
const loginResult = await odooJSONRPCRequest.call(this, body, url);
|
||||
return loginResult as unknown as number;
|
||||
@@ -419,7 +419,7 @@ export async function odooGetServerVersion(
|
||||
method: 'version',
|
||||
args: [],
|
||||
},
|
||||
id: Math.floor(Math.random() * 100),
|
||||
id: randomInt(100),
|
||||
};
|
||||
const result = await odooJSONRPCRequest.call(this, body, url);
|
||||
return result;
|
||||
|
||||
@@ -11,7 +11,7 @@ import type {
|
||||
INodeTypeDescription,
|
||||
IRequestOptions,
|
||||
} from 'n8n-workflow';
|
||||
import { deepCopy } from 'n8n-workflow';
|
||||
import { deepCopy, randomInt } from 'n8n-workflow';
|
||||
|
||||
import { capitalCase } from 'change-case';
|
||||
import {
|
||||
@@ -115,8 +115,8 @@ export class Odoo implements INodeType {
|
||||
const db = odooGetDBName(credentials.db as string, url);
|
||||
const userID = await odooGetUserID.call(this, db, username, password, url);
|
||||
|
||||
const responce = await odooGetModelFields.call(this, db, userID, password, resource, url);
|
||||
const options = Object.values(responce).map((field) => {
|
||||
const response = await odooGetModelFields.call(this, db, userID, password, resource, url);
|
||||
const options = Object.values(response).map((field) => {
|
||||
const optionField = field as { [key: string]: string };
|
||||
let name = '';
|
||||
try {
|
||||
@@ -158,12 +158,12 @@ export class Odoo implements INodeType {
|
||||
['name', 'model', 'modules'],
|
||||
],
|
||||
},
|
||||
id: Math.floor(Math.random() * 100),
|
||||
id: randomInt(100),
|
||||
};
|
||||
|
||||
const responce = (await odooJSONRPCRequest.call(this, body, url)) as IDataObject[];
|
||||
const response = (await odooJSONRPCRequest.call(this, body, url)) as IDataObject[];
|
||||
|
||||
const options = responce.map((model) => {
|
||||
const options = response.map((model) => {
|
||||
return {
|
||||
name: model.name,
|
||||
value: model.model,
|
||||
@@ -188,12 +188,12 @@ export class Odoo implements INodeType {
|
||||
method: 'execute',
|
||||
args: [db, userID, password, 'res.country.state', 'search_read', [], ['id', 'name']],
|
||||
},
|
||||
id: Math.floor(Math.random() * 100),
|
||||
id: randomInt(100),
|
||||
};
|
||||
|
||||
const responce = (await odooJSONRPCRequest.call(this, body, url)) as IDataObject[];
|
||||
const response = (await odooJSONRPCRequest.call(this, body, url)) as IDataObject[];
|
||||
|
||||
const options = responce.map((state) => {
|
||||
const options = response.map((state) => {
|
||||
return {
|
||||
name: state.name as string,
|
||||
value: state.id,
|
||||
@@ -217,12 +217,12 @@ export class Odoo implements INodeType {
|
||||
method: 'execute',
|
||||
args: [db, userID, password, 'res.country', 'search_read', [], ['id', 'name']],
|
||||
},
|
||||
id: Math.floor(Math.random() * 100),
|
||||
id: randomInt(100),
|
||||
};
|
||||
|
||||
const responce = (await odooJSONRPCRequest.call(this, body, url)) as IDataObject[];
|
||||
const response = (await odooJSONRPCRequest.call(this, body, url)) as IDataObject[];
|
||||
|
||||
const options = responce.map((country) => {
|
||||
const options = response.map((country) => {
|
||||
return {
|
||||
name: country.name as string,
|
||||
value: country.id,
|
||||
@@ -252,7 +252,7 @@ export class Odoo implements INodeType {
|
||||
credentials?.password,
|
||||
],
|
||||
},
|
||||
id: Math.floor(Math.random() * 100),
|
||||
id: randomInt(100),
|
||||
};
|
||||
|
||||
const options: IRequestOptions = {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { NodeVM } from '@n8n/vm2';
|
||||
import { type IExecuteFunctions, type INodeExecutionData, NodeOperationError } from 'n8n-workflow';
|
||||
import type { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
|
||||
import { NodeOperationError, randomInt } from 'n8n-workflow';
|
||||
|
||||
export const shuffleArray = (array: any[]) => {
|
||||
for (let i = array.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
const j = randomInt(i + 1);
|
||||
[array[i], array[j]] = [array[j], array[i]];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -10,7 +10,7 @@ import type {
|
||||
IWebhookResponseData,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError } from 'n8n-workflow';
|
||||
import { NodeApiError, randomString } from 'n8n-workflow';
|
||||
|
||||
import type {
|
||||
ITypeformAnswer,
|
||||
@@ -177,7 +177,7 @@ export class TypeformTrigger implements INodeType {
|
||||
const webhookUrl = this.getNodeWebhookUrl('default');
|
||||
|
||||
const formId = this.getNodeParameter('formId') as string;
|
||||
const webhookId = 'n8n-' + Math.random().toString(36).substring(2, 15);
|
||||
const webhookId = 'n8n-' + randomString(10).toLowerCase();
|
||||
|
||||
const endpoint = `forms/${formId}/webhooks/${webhookId}`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user