我目前正在开发一个网站,用户可以在这个网站上撰写几种格式的文章(如粗体,斜体,列表......)。我正在使用一个框架:CodeIgniter。
我是初学者,我听说过一些关于XSS的东西。我想知道您对我的实施情况有何看法。我读了这个主题: What's the best method for sanitizing user input with PHP?
1)用户写他的文章,用BBCode格式化。我正在使用SCEditor。
2)将数据保存到数据库时,我使用htmlspecialchars()过滤任何可疑的HTML标记。我在保存数据或显示数据时应该这样做吗?
3)当我想在网站上显示文章时(例如用于其他用途),我将BBCode标签转换为HTML标签。
这是一种正确的方法吗?我是否在避免使用XSS?
我显然愿意接受建议和建议。
感谢您的回答
答案 0 :(得分:2)
用于验证的Codeigniter具有属性xss,它将执行所有这些工作人员
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[5]|max_length[12]|xss_clean');
签出表单验证Codeigniter:
http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html
答案 1 :(得分:2)
我使用PHP“查找并替换”,但我认为这不是最有效的方法。
<?php
$malicious = "<script>alert(1)</script>";
$malicious = str_ireplace("<", "", $malicious);
$malicious = str_ireplace(">", "", $malicious);
echo $malicious;
?>
答案 2 :(得分:0)
<?php
$malicious = "<script>alert(1)</script>";
$malicious = strip_tags($malicious);
$malicious = htmlentities($malicious, ENT_QUOTES);
echo $malicious;
?>