Strict HTML Validation and Filtering in PHP

前端 未结 4 803
刺人心
刺人心 2020-12-08 03:04

I\'m looking for best practices for performing strict (whitelist) validation/filtering of user-submitted HTML.

Main purpose is to filter out XSS and similar nasties

4条回答
  •  眼角桃花
    2020-12-08 03:48

    The W3C has a big open-source package for validating HTML available here:

    http://validator.w3.org/

    You can download the package for yourself and probably implement whatever they're doing. Unfortunately, it seems like a lot of DOM parsers seem to be willing to bend the rules to allot for HTML code "in the wild" as it were, so it's a good idea to let the masters tell you what's wrong and not leave it to a more practical tool--there are a lot of websites out there that aren't perfect, compliant HTML but that we still use every day.

提交回复
热议问题