Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Commit a0fd61b

Browse files
author
Tom Bell
committed
Merge pull request #905 from nealpoole/master
Patch potential command injection in hubot-scripts/package/src/scripts/email.coffee
2 parents b621c53 + feee5ab commit a0fd61b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/scripts/email.coffee

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@
1818

1919
util = require 'util'
2020
child_process = require 'child_process'
21-
exec = child_process.exec
2221

2322
module.exports = (robot) ->
2423
emailTime = null
2524
sendEmail = (recipients, subject, msg, from) ->
26-
mailCommand = """echo '#{msg}' | mail -s '#{subject}' -r '#{from}' '#{recipients}'"""
27-
exec mailCommand, (error, stdout, stderr) ->
25+
mailArgs = ['-s', subject, '-a', "From: #{from}", '--']
26+
mailArgs = mailArgs.concat recipients
27+
p = child_process.execFile 'mail', mailArgs, {}, (error, stdout, stderr) ->
2828
util.print 'stdout: ' + stdout
2929
util.print 'stderr: ' + stderr
30+
p.stdin.write "#{msg}\n"
31+
p.stdin.end()
3032

3133
robot.respond /email (.*) -s (.*) -m (.*)/i, (msg) ->
32-
sendEmail msg.match[1], msg.match[2], msg.match[3], msg.message.user.id
34+
sendEmail msg.match[1].split(" "), msg.match[2], msg.match[3], msg.message.user.id
3335
msg.send "email sent"

0 commit comments

Comments
 (0)