我有一个简单的脚本,它从 STDIN(管道电子邮件)获取主题行和返回路径,并使用主题运行自定义 curl 查询:
#!/usr/bin/env bash
# Check for the sender email address and subject.
# Assign them to variables for use later.
while read -r key value; do
case $key in
Subject:) subject=$value;;
Return-Path:) return_path=$value;;
esac
done
# Run a curl query utilizing a modified version of the subject (replacing spaces with plus symbols)
curl "https://foo.com/&q="${subject// /+}"" >> foo.txt
但我担心的是,这会为恶意(或意外)使用有问题的主题标头留下一个漏洞,例如:主题:测试 123;rm -fr /;
有没有一种简单的方法可以防止这种情况发生?
如果这是一个模糊的问题,我深表歉意。我对脚本非常陌生,所以我对脚本强化/清理的了解非常少。如果有初学者对此的参考,请告诉我。
更新。这是修改后的脚本:
#!/usr/bin/env bash
# Check for the sender email address and subject.
# Assign them to variables for use later.
while read -r key value; do
case $key in
Subject:) subject="$value";;
Return-Path:) return_path="$value";;
esac
done
# Run a curl query utilizing a modified version of the subject (replacing spaces with plus symbols)
curl "https://foo.com/&q=\"${subject// /+}\"" >> foo.txt