I have a bash script which I'm kicking off via procmail. Procmail passes in the subject and from field from an email as arguments to the bash script. Since these values are unsanitized in any way, I'm trying to figure out if there are any injection vulnerabilities in bash that someone could take advantage of and if so what I can do to protect against these. Here is some sample code to illustrate what's going on :
#!/bin/bash
/usr/sbin/sendmail -t <<EOF
From: "myhost Administrator" <admin@myhost.example.com>
To: john_doe@gmail.com
Subject: An email subject
You've received a new email.
It has a subject of "$2"
It was sent from "$1".
EOF
This bash script would be called by procmail with a .procmailrc script like this :
:0
* ^From:\s*\/.*
{
FROM = "$MATCH"
}
:0
* ^Subject:\s*\/.*
{
SUBJECT = "$MATCH"
}
:0 c:
* ^To:.*@example.com
| /home/john_doe/examplescript.bash "$FROM" "$SUBJECT"
The two areas that I'm wondering about injection vulnerabilities for are in the instantiation of the script :
/home/john_doe/examplescript.bash "$FROM" "$SUBJECT"
and the usage of the variables in the script.
/usr/sbin/sendmail -t <<EOF
From: "myhost Administrator" <admin@myhost.example.com>
To: john_doe@gmail.com
Subject: An email subject
You've received a new email.
It has a subject of "$2"
It was sent from "$1".
EOF
If your curious, here is the actual use case that brought this question to my mind