CVE-2019-1010200 (published 2019-07-23T18:15Z)

Voice Builder Prior to commit c145d4604df67e6fc625992412eef0bf9a85e26b and f6660e6d8f0d1d931359d591dbdec580fef36d36 is affected by: CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection'). The impact is: Remote code execution with the same privileges as the servers. The component is: Two web servers in the projects expose three vulnerable endpoints that can be accessed remotely. The endpoints are defined at: - /tts: https://github.com/google/voice-builder/blob/3a449a3e8d5100ff323161c89b897f6d5ccdb6f9/merlin_model_server/api.js#L34 - /alignment: https://github.com/google/voice-builder/blob/3a449a3e8d5100ff323161c89b897f6d5ccdb6f9/festival_model_server/api.js#L28 - /tts: https://github.com/google/voice-builder/blob/3a449a3e8d5100ff323161c89b897f6d5ccdb6f9/festival_model_server/api.js#L65. The attack vector is: Attacker sends a GET request to the vulnerable endpoint with a specially formatted query parameter. The fixed version is: After commit f6660e6d8f0d1d931359d591dbdec580fef36d36.

Severity: HIGH
CVSS v2 base score: 10.0 (AV:N/AC:L/Au:N/C:C/I:C/A:C)
CVSS v3 base score: 9.8, CRITICAL (CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-78
cwe_name: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
description: The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component.
extended_description: 
		   This weakness can lead to a vulnerability in environments in which the attacker does not have direct access to the operating system, such as in web applications. Alternately, if the weakness occurs in a privileged program, it could allow the attacker to specify commands that normally would not be accessible, or to call alternate commands with privileges that the attacker does not have. The problem is exacerbated if the compromised process does not follow the principle of least privilege, because the attacker-controlled commands may run with special system privileges that increases the amount of damage.
            There are at least two subtypes of OS command injection:
               
				 The application intends to execute a single, fixed program that is under its own control. It intends to use externally-supplied inputs as arguments to that program. For example, the program might use system("nslookup [HOSTNAME]") to run nslookup and allow the user to supply a HOSTNAME, which is used as an argument. Attackers cannot prevent nslookup from executing. However, if the program does not remove command separators from the HOSTNAME argument, attackers could place the separators into the arguments, which allows them to execute their own program after nslookup has finished executing.
				 The application accepts an input that it uses to fully select which program to run, as well as which commands to use. The application simply redirects this entire command to the operating system. For example, the program might use "exec([COMMAND])" to execute the [COMMAND] that was supplied by the user. If the COMMAND is under attacker control, then the attacker can execute arbitrary commands or programs. If the command is being executed using functions like exec() and CreateProcess(), the attacker might not be able to combine multiple commands together in the same line.
               
            From a weakness standpoint, these variants represent distinct programmer errors. In the first variant, the programmer clearly intends that input from untrusted parties will be part of the arguments in the command to be executed. In the second variant, the programmer does not intend for the command to be accessible to any untrusted party, but the programmer probably has not accounted for alternate ways in which malicious attackers can provide input.
         
         

Fix information:
repo_url: https://github.com/google/voice-builder
commit_details: repo_url: https://github.com/google/voice-builder
author: Pasindu De Silva
author_date: 2018-09-25 10:55:31+08:00
msg: Added function to replace characters with spaces and use it to sanitize text

Change-Id: I45ebf2da031f5526c202642cd8946b7202a44e53
repository: repo_url: https://github.com/google/voice-builder
repo_name: google/voice-builder
description: An opensource text-to-speech (TTS) voice building tool
repo_language: JavaScript
owner: google
file_changes: filename: api.js
change_type: ModificationType.MODIFY
diff: @@ -28,21 +28,22 @@ router.get('/healthz', (_req, res) => res.json('OK'));
 router.get('/alignment', (req, res) => {
   const { text } = req.query;
   // TODO(twattanavekin): Test Unicode text.
-  const escapedText = JSON.stringify(text).slice(1, -1);
+  const sanitizedText = utils.replaceCharactersWithSpaces(text);
 
   const { festvoxFile, voiceName, localFolder } = utils.getVoiceSettings();
 
   // Example command:
+  // read txt; TEXT=${txt};
   // ${FESTIVALDIR}/bin/festival
   // -b festvox/goog_vb_unison_cg.scm  -b "(voice_goog_vb_unison_cg)"
   // -b "(Parameter.set 'Audio_Method 'Audio_Command)"
   // -b "(Parameter.set 'Audio_Command \"\")"
-  // -b "(utt.relation.print (SayText \" hello \") 'Segment)"
+  // -b "(utt.relation.print (SayText \" ${TEXT} \") 'Segment)";
 
-  const cmd = `${FESTIVAL_BIN} -b ${festvoxFile}  -b "(${voiceName})" \
+  const cmd = `read txt; TEXT=\$\{txt\}; ${FESTIVAL_BIN} -b ${festvoxFile}  -b "(${voiceName})" \
   -b "(Parameter.set 'Audio_Method 'Audio_Command)" \
   -b "(Parameter.set 'Audio_Command \\"\\")" \
-  -b "(utt.relation.print (SayText \\" ${escapedText} \\") 'Segment)"`;
+  -b "(utt.relation.print (SayText \\" \$\{TEXT\} \\") 'Segment)";`;
 
   const options = {
     cwd: localFolder,
@@ -52,30 +53,31 @@ router.get('/alignment', (req, res) => {
 
   console.log(`Running command - \n${cmd}`);
 
-  exec(cmd, options, (err, stdout, stderr) => {
+  const child = exec(cmd, options, (err, stdout, stderr) => {
     const errMsg = utils.getExecErrorMessage(err, stderr);
     if (errMsg) {
       return res.status(500).send(errMsg);
     }
     return res.status(200).send(utils.getAlignmentData(stdout.toString()));
   });
+  child.stdin.write(sanitizedText);
+  child.stdin.end();
 });
 
 /** GET synthesize voice based on a voice model */
 router.get('/tts', (req, res) => {
   const { text, type } = req.query;
   // TODO(twattanavekin): Test Unicode text.
-  const escapedText = JSON.stringify(text).slice(1, -1);
+  const sanitizedText = utils.replaceCharactersWithSpaces(text);
+  console.log(`Synthesizing ${sanitizedText}`);
 
-  console.log(`Synthesize "${text}"`);
   const { festvoxFile, voiceName, localFolder } = utils.getVoiceSettings();
 
   // Example command:
-  // echo "Hello world" | festival/bin/text2wave \
+  // festival/bin/text2wave \
   //  -eval festvox/goog_vb_unison_cg.scm \
   //  -eval "(voice_vb_unison_cg)"
-  const cmd = `echo "${escapedText}" \
-              | ${TEXT_TO_WAV_BIN} -eval ${festvoxFile} -eval "(${voiceName})"`;
+  const cmd = `${TEXT_TO_WAV_BIN} -eval ${festvoxFile} -eval "(${voiceName})"`;
   console.log(`Running command - \n${cmd}`);
 
   const options = {
@@ -83,7 +85,8 @@ router.get('/tts', (req, res) => {
     timeout: 10000,
     encoding: 'buffer',
   };
-  exec(cmd, options, (err, stdout, stderr) => {
+
+  const child = exec(cmd, options, (err, stdout, stderr) => {
     const errMsg = utils.getExecErrorMessage(err, stderr);
     if (errMsg) {
       return res.status(500).send(errMsg);
@@ -93,6 +96,8 @@ router.get('/tts', (req, res) => {
     const data = type === 'base64' ? stdout.toString('base64') : stdout;
     return res.send(data);
   });
+  child.stdin.write(sanitizedText);
+  child.stdin.end();
 });
 
 module.exports = router;

programming_language: TypeScript
filename: settings.js
change_type: ModificationType.ADD
diff: @@ -0,0 +1,24 @@
+// Copyright 2018 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/**
+ * Module containing settings for merlin server.
+ */
+const settings = {
+  // Festival synthesis pipeline might not handle these characters as expected
+  // and also they are typically not needed during tts synthesis.
+  // Therefore we replace them with spaces.
+  CHARACTERS_TO_REPLACE_WITH_SPACES: '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~',
+};
+module.exports = settings;

programming_language: Go
filename: UtilsTests.js
change_type: ModificationType.MODIFY
diff: @@ -14,6 +14,34 @@
 
 const utils = require('../utils');
 
+describe('Testing utils replaceCharactersWithSpaces method', () => {
+  it('The function should return characters replaced with spaces and trim', () => {
+    const testData = [
+      ['`<text>`', 'text'],
+      ['`text`', 'text'],
+      ['$(text)', 'text'],
+      ['"\$(text\)', 'text'],
+      ['\"\$(text\)', 'text'],
+      ['${{{text}', 'text'],
+      ['\$\{text\}', 'text'],
+      ['\${text"}', 'text'],
+      ['"${{text"}', 'text'],
+      ['"${text"}', 'text'],
+      ["\"ශ්රී ලංකාව'\"", 'ශ්රී ලංකාව'],
+      ['"$text"', 'text'],
+      ['$text', 'text'],
+      [",./;'[]*\-=", ''],
+      ['echo `<text>`', 'echo   text'],
+      ['echo $("text")', 'echo    text'],
+      ['echo \$\{text\}', 'echo   text'],
+    ];
+
+    testData.forEach(function(entry) {
+      expect(utils.replaceCharactersWithSpaces(entry[0])).toEqual(entry[1]);
+    });
+  });
+});
+
 describe('Testing utils getAlignmentData method', () => {
   const generateTestData = () => {
     let testContent = '()\n'; // Alignment data starts with this.

programming_language: TypeScript
filename: utils.js
change_type: ModificationType.MODIFY
diff: @@ -12,6 +12,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+const settings = require('./settings');
+
 /**
  * Module containing util methods.
  */
@@ -87,8 +89,20 @@ const getVoiceSettings = () => ({
   localFolder: MODEL_LOCAL_PATH,
 });
 
+/**
+ * Returns the original string with characters
+ * specified in settings replaced with spaces.
+ * @text {String} text to be replaced.
+ */
+const replaceCharactersWithSpaces = (text) => {
+  const re = new RegExp(`[${settings.CHARACTERS_TO_REPLACE_WITH_SPACES}]`, 'g');
+  const newText = text.replace(re, ' ').trim();
+  return newText;
+};
+
 module.exports = {
   getAlignmentData,
   getExecErrorMessage,
   getVoiceSettings,
+  replaceCharactersWithSpaces,
 };

programming_language: TypeScript
repo_url: https://github.com/google/voice-builder
commit_details: repo_url: https://github.com/google/voice-builder
author: Pasindu De Silva
author_date: 2018-09-20 16:45:17+08:00
msg: Added function to replace characters with space and use it to sanitize text

Change-Id: I3d14230444fefa0ce739c498eee6d100bcfe276a
repository: repo_url: https://github.com/google/voice-builder
repo_name: google/voice-builder
description: An opensource text-to-speech (TTS) voice building tool
repo_language: JavaScript
owner: google
file_changes: filename: api.js
change_type: ModificationType.MODIFY
diff: @@ -33,14 +33,9 @@ router.get('/alignment', (req, res) => res.status(200).send([]));
 /** GET synthesize voice based on a voice model */
 router.get('/tts', (req, res) => {
   const { text, type } = req.query;
-  // TODO(twattanavekin): Test Unicode text.
-  const escapedText = JSON.stringify(text).slice(1, -1);
+  const sanitizedText = utils.replaceCharactersWithSpaces(text);
 
-  // Example command:
-  //  echo "hello" | ${SYNTH_SCRIPT}
-
-  const cmd = `echo "${escapedText}" | ${SYNTH_SCRIPT}`;
-  console.log(`Running command - \n${cmd}`);
+  console.log(`Synthesizing ${sanitizedText}`);
 
   const options = {
     maxBuffer: 1024 * 1000, // 1 mb buffer
@@ -49,7 +44,7 @@ router.get('/tts', (req, res) => {
     encoding: 'buffer',
   };
 
-  exec(cmd, options, (err, stdout, stderr) => {
+  const child = exec(SYNTH_SCRIPT, options, (err, stdout, stderr) => {
     const errMsg = utils.getExecErrorMessage(err, stderr);
     if (errMsg) {
       return res.status(500).send(errMsg);
@@ -59,6 +54,8 @@ router.get('/tts', (req, res) => {
     const data = type === 'base64' ? stdout.toString('base64') : stdout;
     return res.send(data);
   });
+  child.stdin.write(sanitizedText);
+  child.stdin.end();
 });
 
 module.exports = router;

programming_language: TypeScript
filename: jasmine.json
change_type: ModificationType.MODIFY
diff: @@ -1,6 +1,8 @@
 {
   "spec_dir": "tests",
-  "spec_files": [],
+  "spec_files": [
+    "UtilsTests.js"
+  ],
   "stopSpecOnExpectationFailure": false,
   "random": false
 }

programming_language: Ruby
filename: settings.js
change_type: ModificationType.ADD
diff: @@ -0,0 +1,24 @@
+// Copyright 2018 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/**
+ * Module containing settings for merlin server.
+ */
+const settings = {
+  // Merlin synthesis pipeline might not handle these characters as expected
+  // and also they are typically not needed during tts synthesis.
+  // Therefore we replace them with spaces.
+  CHARACTERS_TO_REPLACE_WITH_SPACES: '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~',
+};
+module.exports = settings;

programming_language: Go
filename: UtilsTests.js
change_type: ModificationType.ADD
diff: @@ -0,0 +1,43 @@
+// Copyright 2018 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+const utils = require('../utils');
+
+describe('Testing utils replaceCharactersWithSpaces method', () => {
+  it('The function should return characters replaced with spaces and trim', () => {
+    const testData = [
+      ['`<text>`', 'text'],
+      ['`text`', 'text'],
+      ['$(text)', 'text'],
+      ['"\$(text\)', 'text'],
+      ['\"\$(text\)', 'text'],
+      ['${{{text}', 'text'],
+      ['\$\{text\}', 'text'],
+      ['\${text"}', 'text'],
+      ['"${{text"}', 'text'],
+      ['"${text"}', 'text'],
+      ["\"ශ්රී ලංකාව'\"", 'ශ්රී ලංකාව'],
+      ['"$text"', 'text'],
+      ['$text', 'text'],
+      [",./;'[]*\-=", ''],
+      ['echo `<text>`', 'echo   text'],
+      ['echo $("text")', 'echo    text'],
+      ['echo \$\{text\}', 'echo   text'],
+    ];
+
+    testData.forEach(function(entry) {
+      expect(utils.replaceCharactersWithSpaces(entry[0])).toEqual(entry[1]);
+    });
+  });
+});

programming_language: JavaScript
filename: utils.js
change_type: ModificationType.MODIFY
diff: @@ -12,6 +12,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+const settings = require('./settings');
+
 /**
  * Returns a error message for the given parameters.
  * @param {String} err error from the exec call.
@@ -27,7 +29,18 @@ const getExecErrorMessage = (err, stderr) => {
   return errMsg;
 };
 
+/**
+ * Returns the original string with characters
+ * specified in settings replaced with spaces.
+ * @text {String} text to be replaced.
+ */
+const replaceCharactersWithSpaces = (text) => {
+  const re = new RegExp(`[${settings.CHARACTERS_TO_REPLACE_WITH_SPACES}]`, 'g');
+  const newText = text.replace(re, ' ').trim();
+  return newText;
+};
 
 module.exports = {
   getExecErrorMessage,
+  replaceCharactersWithSpaces,
 };

programming_language: TypeScript