[FIX] Change way emails are validated on livechat registerGuest method (#23089)

* Change way emails are validated on livechat registerGuest method

* Apply MR comments
pull/22489/head
Kevin Aleman 4 years ago committed by GitHub
parent 995c55831c
commit cc9902b736
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/lib/server/lib/validateEmailDomain.js
  2. 8
      app/livechat/server/lib/Helper.js
  3. 5
      app/livechat/server/lib/Livechat.js

@ -6,6 +6,7 @@ import { emailDomainDefaultBlackList } from './defaultBlockedDomainsList';
import { settings } from '../../../settings/server';
const dnsResolveMx = Meteor.wrapAsync(dns.resolveMx);
const emailValidationRegex = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
let emailDomainBlackList = [];
let emailDomainWhiteList = [];
@ -14,6 +15,7 @@ let useDNSDomainCheck = false;
settings.get('Accounts_BlockedDomainsList', function(key, value) {
if (!value) {
emailDomainBlackList = [];
return;
}
@ -21,6 +23,7 @@ settings.get('Accounts_BlockedDomainsList', function(key, value) {
});
settings.get('Accounts_AllowedDomainsList', function(key, value) {
if (!value) {
emailDomainWhiteList = [];
return;
}
@ -34,8 +37,7 @@ settings.get('Accounts_UseDNSDomainCheck', function(key, value) {
});
export const validateEmailDomain = function(email) {
const emailValidation = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
if (!emailValidation.test(email)) {
if (!emailValidationRegex.test(email)) {
throw new Meteor.Error('error-invalid-email', `Invalid email ${ email }`, { function: 'RocketChat.validateEmailDomain', email });
}

@ -17,6 +17,7 @@ import { sendMessage } from '../../../lib/server/functions/sendMessage';
import { queueInquiry, saveQueueInquiry } from './QueueManager';
const logger = new Logger('LivechatHelper');
const emailValidationRegex = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
export const allowAgentSkipQueue = (agent) => {
check(agent, Match.ObjectIncluding({
@ -535,3 +536,10 @@ export const updateDepartmentAgents = (departmentId, agents, departmentEnabled)
return true;
};
export const validateEmail = (email) => {
if (!emailValidationRegex.test(email)) {
throw new Meteor.Error('error-invalid-email', `Invalid email ${ email }`, { function: 'Livechat.validateEmail', email });
}
return true;
};

@ -36,11 +36,10 @@ import { sendMessage } from '../../../lib/server/functions/sendMessage';
import { updateMessage } from '../../../lib/server/functions/updateMessage';
import { deleteMessage } from '../../../lib/server/functions/deleteMessage';
import { FileUpload } from '../../../file-upload/server';
import { normalizeTransferredByData, parseAgentCustomFields, updateDepartmentAgents } from './Helper';
import { normalizeTransferredByData, parseAgentCustomFields, updateDepartmentAgents, validateEmail } from './Helper';
import { Apps, AppEvents } from '../../../apps/server';
import { businessHourManager } from '../business-hour';
import notifications from '../../../notifications/server/lib/Notifications';
import { validateEmailDomain } from '../../../lib/server';
const dnsResolveMx = Meteor.wrapAsync(dns.resolveMx);
@ -261,7 +260,7 @@ export const Livechat = {
if (email) {
email = email.trim();
validateEmailDomain(email);
validateEmail(email);
updateUser.$set.visitorEmails = [
{ address: email },
];

Loading…
Cancel
Save