Sanitize user defined CSS in PHP

前端 未结 4 1819
长发绾君心
长发绾君心 2020-12-08 08:23

I want to allow users to use their own stylesheets for thei profiles on my forum, but I\'m afraid of possible security vulnerabilities. Does anyone have any tips for sanitiz

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-08 09:21

    This probably won't fix all sorts of hacks but probably most automated hacks at least:

    $css = strip_tags($css);
    $css = htmlspecialchars($css, ENT_HTML5 | ENT_NOQUOTES | ENT_SUBSTITUTE, 'utf-8');
    

    Depends on how many users are allowed to use this feature and how big of a threat it could be due to that..

提交回复
热议问题