PHP安全设置一则

来源:互联网 发布:js下拉菜单代码 编辑:程序博客网 时间:2024/04/29 19:57
  1. 不要为 SQL 语句使用 PDO 参数传值,以防止 SQL injection.

  2. 务必使用 htmlspecialchars/htmlentities 和/或者 strip_tags 转义 html 和JavaScript 来防止 XSS(交叉站点脚本) 攻击.

  3. 务必使用 sessions 和安全套接字来防止 session 被劫持,采用 md5 校验和来验证 session ids. 在 session 里存储一个特殊的令牌 md5(uniqueid(rand(),time)) 放到一个隐含的表单提交项里:eg. $_SESSION["token"]===$FORM["token"].

  4. 务必使用 escapeshellarg/escapeshellcmd 调用外部命令防止命令行注入

  5. 务必从进入的http头删除分行符以防止http头提早终止 Do remove linebreaks from incoming headers to prevent early header termination and injection. Fixed >PHP5.1
    采用 md5 校验和来序列化参数值和 sessionid来验证一致性

  6. 使用 === 来验证输入值以保证类型一致

  7. 在任何用户特权提升的应用中,采用 session_regenerate
    在商务交易中采用安全套接字

  8. 设置以下参数来提高安全性:
  • ini_set("display_errors",false);

  • ini_set("log_errors",true);

  • ini_set("error_log","path/to/php.log");

  • ini_set("session.save_path","path/above/www"); 或者session放到数据库

  • php.ini expose_php=off

  • php.ini register_globals=off

  • Apache servertokens=prod

原创粉丝点击