这是处理表单PHP的最安全方法 [英] Is this the safest way to handle a form PHP

查看:56
本文介绍了这是处理表单PHP的最安全方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道这是否是处理表单提交的最安全,最好的方法,我正在尝试寻找最安全"的代码视图,并提供给我,

I was just wondering if this is the safest and best way to handle a form submission, i am trying to find the most "safest" and presented for my coding views,

PHP

<?php
if(isset($_POST['submit'])) {
 //Handle the form here with many $_POST['namehere']
}
?>

HTML

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<label>Email</label>
     <input name="email" type="text">
<label>Password</label>     
     <input type="password" name="password">
<label>Submit</label>     
     <input type="submit" name="submit">
</form>

这是否被视为这样做的唯一途径和最安全的方法?

Would this be deemed as the only way possible to do this and the most secure ?

推荐答案

您所拥有的只是一种形式.它既不安全也不安全.定义表单是否安全的是如何将数据传输到服务器以及如何处理服务器端的输入.

What you have there is just a form. It's neither secure nor insecure. What defines whether or not a form is secure is how you transmit the data to the server and how you handle the input on the server side.

安全的登录表单...

A secure login form...

  • 通过HTTPS(SSL)将其内容发布到服务器
  • 对所有输入服务器端进行正确的验证
  • 不允许进行SQL注入
  • 使用带有正确验证的反CSRF令牌的隐藏字段
  • 使用具有经过强化的Apache/PHP安装的服务器

关于 PHP_SELF XSS漏洞:

  • Jack在其评论中的链接建议一个实际上不起作用的字符串
  • 在某些情况下*可能会发生这种XSS攻击,问题是,它有多容易被利用?该漏洞是客户端的,因此不能直接利用,您需要对其进行一些设计(反映出攻击),说出一个假冒的电子邮件操作,我假装成您的网站,并提供一个登录链接,让您发布您的凭据到我的网站.还是存储式攻击,但如果我能够做到,那么您的网站就会比PHP_SELF XSS更大.
  • 当然,最好的办法就是以防万一,避免使用PHP_SELF并以 htmlspecialchars($ _ SERVER ['SCRIPT_NAME'])代替.

*情况

  • 该漏洞利用方法不适用于大多数现代PHP框架,即使它们没有保护并真正使用 PHP_SELF ,因为包含攻击字符串的URL与任何允许的URL路由都不匹配./li>
  • 浏览器已开始实施XSS保护.例如.该漏洞在Chrome/WebKit和IE8 +中不起作用,但在撰写本文时在Firefox中有效.
  • 小型私人站点不太可能成为此类攻击的目标,因为需要花一些精力来设计一个.目标通常是社交网络和类似网站.
  • The exploit doesn't work with most modern PHP frameworks, even if they're not protecting and really using PHP_SELF, because the url including the attack string would not match any allowed url route.
  • Browsers have started implementing XSS protection. E.g. the exploit doesn't work in Chrome/WebKit and IE8+ but it works in Firefox, at the time of writing.
  • Small, private sites are very very unlikely to be a target of such an attack, since it takes some effort to engineer one. Targets are usually social networks and similar sites.

这篇关于这是处理表单PHP的最安全方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆