联系表单的 php 邮件标头注入清理

发布于 2024-12-25 03:22:09 字数 792 浏览 4 评论 0原文

我想出了以下脚本来清理我的 php 邮件联系表单。想知道是否还有其他建议我应该放在这里。这只是代码片段,因为我还对每个字段进行了预匹配,以仅允许允许的字符,但就从一开始就清理注入而言,有什么关于更改的建议吗?

我意识到我没有包含 /r、/n、%0a 和 %0d,但是当我这样做时,它会在我向自身发布内容并在这些字段上包含“错误”和“无效”注释时产生表单问题有错误,包括原始错误,因此可以更正它们,而且无论如何,我想允许在表单的注释“文本区域”中输入新行。

// remove any possible inections
foreach($values as $key => $input){
    $values[$key] = cleaninjections($input);
}

// perform on each field of the form
function cleaninjections($test)
{
 // Remove injected headers
 $find = array("/bcc\:/i", 
               "/content\-type\:/i", 
               "/mime\-version\:/i", 
               "/cc\:/i", 
               "/from\:/i",
               "/to\:/i",
               "/content\-transfer\-encoding\:/i");
$ret = preg_replace($find, "", stripslashes($test));
return $ret;
}

I came up with the following script to clean my php mail contact forms. Was wondering if there is anything else that is recommended I should put in here. This is just a snippet of the code as I also pregmatch each field to only allow characters allowed, but as far as cleaning injections from the get go - any recommendations on changes?

I realize I have not included /r, /n, %0a, and %0d, but when I do so it creates an issue with the form as I post to itself and include 'error' and 'invalid' comments on those fields which have errors including the original so they can be corrected plus I want to allow enter and new lines in the comments 'text area' of the form anyways.

// remove any possible inections
foreach($values as $key => $input){
    $values[$key] = cleaninjections($input);
}

// perform on each field of the form
function cleaninjections($test)
{
 // Remove injected headers
 $find = array("/bcc\:/i", 
               "/content\-type\:/i", 
               "/mime\-version\:/i", 
               "/cc\:/i", 
               "/from\:/i",
               "/to\:/i",
               "/content\-transfer\-encoding\:/i");
$ret = preg_replace($find, "", stripslashes($test));
return $ret;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文