Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Proxy settings being ignored #25022

Merged
merged 12 commits into from Apr 7, 2022
1 change: 1 addition & 0 deletions .meteor/packages
Expand Up @@ -88,3 +88,4 @@ rocketchat:i18n
rocketchat:postcss
dandv:caret-position
facts-base@1.0.1
url
22 changes: 11 additions & 11 deletions app/apps/server/bridges/http.ts
@@ -1,10 +1,9 @@
import { fetch } from 'meteor/fetch';
import { HttpBridge } from '@rocket.chat/apps-engine/server/bridges/HttpBridge';
import { IHttpResponse } from '@rocket.chat/apps-engine/definition/accessors';
import { IHttpBridgeRequestInfo } from '@rocket.chat/apps-engine/server/bridges';

import { AppServerOrchestrator } from '../orchestrator';
import { getUnsafeAgent } from '../../../../server/lib/getUnsafeAgent';
import { fetch } from '../../../../server/lib/http/fetch';

const isGetOrHead = (method: string): boolean => ['GET', 'HEAD'].includes(method.toUpperCase());

Expand Down Expand Up @@ -70,15 +69,16 @@ export class AppHttpBridge extends HttpBridge {
this.orch.debugLog(`The App ${info.appId} is requesting from the outter webs:`, info);

try {
const response = await fetch(url.href, {
method,
body: content,
headers,
...(((request.hasOwnProperty('strictSSL') && !request.strictSSL) ||
(request.hasOwnProperty('rejectUnauthorized') && request.rejectUnauthorized)) && {
agent: getUnsafeAgent(url.protocol === 'https:' ? 'https:' : 'http:'),
}),
});
const response = await fetch(
url.href,
{
method,
body: content,
headers,
},
(request.hasOwnProperty('strictSSL') && !request.strictSSL) ||
(request.hasOwnProperty('rejectUnauthorized') && request.rejectUnauthorized),
);

const result: IHttpResponse = {
url: info.url,
Expand Down
2 changes: 1 addition & 1 deletion app/apps/server/communication/rest.js
@@ -1,6 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { HTTP } from 'meteor/http';
import { fetch } from 'meteor/fetch';

import { API } from '../../../api/server';
import { getUploadFormData } from '../../../api/server/lib/getUploadFormData';
Expand All @@ -12,6 +11,7 @@ import { Settings } from '../../../models/server/raw';
import { Apps } from '../orchestrator';
import { formatAppInstanceForRest } from '../../lib/misc/formatAppInstanceForRest';
import { actionButtonsHandler } from './endpoints/actionButtonsHandler';
import { fetch } from '../../../../server/lib/http/fetch';

const appsEngineVersionForMarketplace = Info.marketplaceApiVersion.replace(/-.*/g, '');
const getDefaultHeaders = () => ({
Expand Down
20 changes: 10 additions & 10 deletions app/integrations/server/lib/triggerHandler.js
Expand Up @@ -2,7 +2,6 @@ import vm from 'vm';

import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
import { fetch } from 'meteor/fetch';
import { HTTP } from 'meteor/http';
import _ from 'underscore';
import s from 'underscore.string';
Expand All @@ -16,7 +15,7 @@ import { settings } from '../../../settings/server';
import { getRoomByNameOrIdWithOptionToJoin, processWebhookMessage } from '../../../lib/server';
import { outgoingLogger } from '../logger';
import { integrations } from '../../lib/rocketchat';
import { getUnsafeAgent } from '../../../../server/lib/getUnsafeAgent';
import { fetch } from '../../../../server/lib/http/fetch';

export class RocketChatIntegrationHandler {
constructor() {
Expand Down Expand Up @@ -771,14 +770,15 @@ export class RocketChatIntegrationHandler {
opts.headers['Content-Type'] = 'application/json';
}

fetch(opts.url, {
method: opts.method,
headers: opts.headers,
...(settings.get('Allow_Invalid_SelfSigned_Certs') && {
agent: getUnsafeAgent(opts.url.startsWith('https:') ? 'https:' : 'http:'),
}),
...(opts.data && { body: JSON.stringify(opts.data) }),
})
fetch(
opts.url,
{
method: opts.method,
headers: opts.headers,
...(opts.data && { body: JSON.stringify(opts.data) }),
},
settings.get('Allow_Invalid_SelfSigned_Certs'),
)
.then(async (res) => {
const content = await res.text();
if (!content) {
Expand Down
4 changes: 2 additions & 2 deletions app/lib/server/functions/getAvatarSuggestionForUser.js
@@ -1,9 +1,9 @@
import { check } from 'meteor/check';
import { fetch } from 'meteor/fetch';
import { Gravatar } from 'meteor/jparker:gravatar';
import { ServiceConfiguration } from 'meteor/service-configuration';

import { settings } from '../../../settings';
import { settings } from '../../../settings/server';
import { fetch } from '../../../../server/lib/http/fetch';

const avatarProviders = {
facebook(user) {
Expand Down
2 changes: 1 addition & 1 deletion app/lib/server/functions/setUserAvatar.ts
@@ -1,11 +1,11 @@
import { Meteor } from 'meteor/meteor';
import { fetch } from 'meteor/fetch';

import { RocketChatFile } from '../../../file/server';
import { FileUpload } from '../../../file-upload/server';
import { Users } from '../../../models/server';
import { SystemLogger } from '../../../../server/lib/logger/system';
import { api } from '../../../../server/sdk/api';
import { fetch } from '../../../../server/lib/http/fetch';
import { IUser } from '../../../../definition/IUser';

export const setUserAvatar = function (
Expand Down
2 changes: 1 addition & 1 deletion app/livechat/imports/server/rest/sms.js
@@ -1,10 +1,10 @@
import { fetch } from 'meteor/fetch';
import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';

import { FileUpload } from '../../../../file-upload/server';
import { LivechatRooms, LivechatVisitors, LivechatDepartment } from '../../../../models/server';
import { API } from '../../../../api/server';
import { fetch } from '../../../../../server/lib/http/fetch';
import { SMS } from '../../../../sms';
import { Livechat } from '../../../server/lib/Livechat';
import { OmnichannelSourceType } from '../../../../../definition/IRoom';
Expand Down
4 changes: 3 additions & 1 deletion app/models/server/raw/IntegrationHistory.ts
@@ -1,7 +1,9 @@
import { BaseRaw } from './BaseRaw';
import { BaseRaw, IndexSpecification } from './BaseRaw';
import { IIntegrationHistory } from '../../../../definition/IIntegrationHistory';

export class IntegrationHistoryRaw extends BaseRaw<IIntegrationHistory> {
protected indexes: IndexSpecification[] = [{ key: { 'integration._id': 1, 'integration._createdBy._id': 1 } }];

removeByIntegrationId(integrationId: string): ReturnType<BaseRaw<IIntegrationHistory>['deleteMany']> {
return this.deleteMany({ 'integration._id': integrationId });
}
Expand Down
26 changes: 13 additions & 13 deletions app/oembed/server/server.js
@@ -1,7 +1,6 @@
import URL from 'url';
import querystring from 'querystring';

import { fetch } from 'meteor/fetch';
import { camelCase } from 'change-case';
import _ from 'underscore';
import iconv from 'iconv-lite';
Expand All @@ -16,7 +15,7 @@ import { settings } from '../../settings/server';
import { isURL } from '../../utils/lib/isURL';
import { SystemLogger } from '../../../server/lib/logger/system';
import { Info } from '../../utils/server';
import { getUnsafeAgent } from '../../../server/lib/getUnsafeAgent';
import { fetch } from '../../../server/lib/http/fetch';

const OEmbed = {};

Expand Down Expand Up @@ -101,18 +100,19 @@ const getUrlContent = async function (urlObj, redirectCount = 5) {

const sizeLimit = 250000;

const response = await fetch(url, {
compress: true,
follow: redirectCount,
headers: {
'User-Agent': `${settings.get('API_Embed_UserAgent')} Rocket.Chat/${Info.version}`,
'Accept-Language': settings.get('Language') || 'en',
const response = await fetch(
url,
{
compress: true,
follow: redirectCount,
headers: {
'User-Agent': `${settings.get('API_Embed_UserAgent')} Rocket.Chat/${Info.version}`,
'Accept-Language': settings.get('Language') || 'en',
},
size: sizeLimit, // max size of the response body, this was not working as expected so I'm also manually verifying that on the iterator
},
size: sizeLimit, // max size of the response body, this was not working as expected so I'm also manually verifying that on the iterator
...(settings.get('Allow_Invalid_SelfSigned_Certs') && {
agent: getUnsafeAgent(parsedUrl.protocol),
}),
});
settings.get('Allow_Invalid_SelfSigned_Certs'),
);

let totalSize = 0;
const chunks = [];
Expand Down
6 changes: 6 additions & 0 deletions definition/externals/meteor/url.d.ts
@@ -0,0 +1,6 @@
declare module 'meteor/url' {
export const URL: typeof window.URL & {
_constructUrl(url: string, query?: string, paramsForUrl?: Record<string, string>): string;
};
export const URLSearchParams: typeof window.URLSearchParams;
}
21 changes: 21 additions & 0 deletions lib/utils/stringUtils.tests.ts
@@ -0,0 +1,21 @@
import { expect } from 'chai';

import { truncate } from './stringUtils';

describe('String utils', () => {
it('should return an empty string when the specified string is empty', () => {
expect(truncate('', 10)).to.be.equal('');
});

it('should truncate a larger string', () => {
expect(truncate('this text has a few words', 9)).to.be.equal('this t...');
});

it('should not truncate a smaller string', () => {
expect(truncate('this', 9)).to.be.equal('this');
});

it('should not truncate a string with the exact length', () => {
expect(truncate('this', 4)).to.be.equal('this');
});
});
3 changes: 3 additions & 0 deletions lib/utils/stringUtils.ts
@@ -0,0 +1,3 @@
export function truncate(str: string, length: number): string {
return str.length > length ? `${str.slice(0, length - 3)}...` : str;
}
96 changes: 65 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.