fix(core): Do not send credentials to browser console (#5031)

This commit is contained in:
Jan Oberhauser
2022-12-23 16:25:59 -06:00
committed by GitHub
parent a229788d4b
commit afc529799d
4 changed files with 67 additions and 30 deletions

View File

@@ -13,7 +13,7 @@ import {
} from 'n8n-workflow';
import { OptionsWithUri } from 'request';
import { replaceNullValues } from '../GenericFunctions';
import { IAuthDataSanitizeKeys, replaceNullValues, sanitizeUiMessage } from '../GenericFunctions';
interface OptionData {
name: string;
@@ -914,21 +914,26 @@ export class HttpRequestV1 implements INodeType {
requestOptions.headers['Content-Type'] = options.bodyContentCustomMimeType;
}
const authDataKeys: IAuthDataSanitizeKeys = {};
// Add credentials if any are set
if (httpBasicAuth !== undefined) {
requestOptions.auth = {
user: httpBasicAuth.user as string,
pass: httpBasicAuth.password as string,
};
authDataKeys.auth = ['pass'];
}
if (httpHeaderAuth !== undefined) {
requestOptions.headers![httpHeaderAuth.name as string] = httpHeaderAuth.value;
authDataKeys.headers = [httpHeaderAuth.name as string];
}
if (httpQueryAuth !== undefined) {
if (!requestOptions.qs) {
requestOptions.qs = {};
}
requestOptions.qs[httpQueryAuth.name as string] = httpQueryAuth.value;
authDataKeys.qs = [httpQueryAuth.name as string];
}
if (httpDigestAuth !== undefined) {
requestOptions.auth = {
@@ -936,6 +941,7 @@ export class HttpRequestV1 implements INodeType {
pass: httpDigestAuth.password as string,
sendImmediately: false,
};
authDataKeys.auth = ['pass'];
}
if (requestOptions.headers!.accept === undefined) {
@@ -951,15 +957,7 @@ export class HttpRequestV1 implements INodeType {
}
try {
let sendRequest: any = requestOptions;
// Protect browser from sending large binary data
if (Buffer.isBuffer(sendRequest.body) && sendRequest.body.length > 250000) {
sendRequest = {
...requestOptions,
body: `Binary data got replaced with this text. Original was a Buffer with a size of ${requestOptions.body.length} byte.`,
};
}
this.sendMessageToUI(sendRequest);
this.sendMessageToUI(sanitizeUiMessage(requestOptions, authDataKeys));
} catch (e) {}
if (oAuth1Api) {