11 Star 63 Fork 19

简言/rageframe3

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
php-safety.md 1.08 KB
一键复制 编辑 原始数据 按行查看 历史
简言Pro 提交于 2022-02-28 10:40 . 初始化

安全防范

  • XSS攻击防范
  • CSRF攻击防范
  • SQL注入
  • Nginx指定目录禁止运行PHP

XSS攻击

直接显示的数据加上,防止XSS攻击

// 页面直接输出
\common\helpers\Html::encode($title) // 纯文本
\common\helpers\HtmlPurifier::process($content) // html显示的文本 HtmlPurifier帮助类的处理过程较为费时,建议增加缓存

// json输出
\yii\helpers\Json::htmlEncode($content);

CSRF攻击防范

如果不用Yii2自带的表单组件可在form表单加入这个开启csrf防范

\common\helpers\Html::csrfMetaTags()

SQL注入

请用Yii2自带的AR或者DB操作类来防范SQL注入

Nginx指定目录禁止运行PHP

这段配置文件一定要放在匹配 .php 的规则前面才可以生效,防止上传可执行文件攻击

// 单个目录
location ~* ^/attachment/.*\.(php|php5)$ 
{
    deny all;
}

// 多个目录
location ~* ^/(attachment|uploads)/.*\.(php|php5)$ 
{
    deny all; 
}

其他

# deny accessing php files for the /assets directory
location ~ ^/assets/.*\.php$ {
    deny all;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/jianyan94/rageframe3.git
git@gitee.com:jianyan94/rageframe3.git
jianyan94
rageframe3
rageframe3
master

搜索帮助

A270a887 8829481 3d7a4017 8829481