Commit 178d09609414889ba37b21555f3c690f4b803b05

Authored by Adhidarma Hadiwinoto
1 parent 85a4549acb
Exists in master

Sanitize destination

Showing 1 changed file with 17 additions and 2 deletions Side-by-side Diff

... ... @@ -26,9 +26,24 @@ const send = async (partner, msg, callerXid) => {
26 26 '/sms/send',
27 27 );
28 28  
  29 + if (!partner || typeof partner !== 'string' || !partner.trim()) {
  30 + logger.verbose(`${MODULE_NAME} E5308BDD: Missing destination`);
  31 + return;
  32 + }
  33 +
  34 + if (!msg || typeof msg !== 'string' || !msg.trim()) {
  35 + logger.verbose(`${MODULE_NAME} EC8FF515: Missing msg`);
  36 + return;
  37 + }
  38 +
  39 + const destination = (partner || '')
  40 + .trim()
  41 + .replace(/^0/, '+62')
  42 + .replace(/^62/, '+62');
  43 +
29 44 const payload = {
30   - destination: partner,
31   - message: msg,
  45 + destination,
  46 + message: (msg || '').trim(),
32 47 };
33 48  
34 49 logger.verbose(`${MODULE_NAME} 8D4F8A3A: Sending message to modem apiserver`, {