tgalopin/html-sanitizer
最新稳定版本:1.5.0
Composer 安装命令:
composer require tgalopin/html-sanitizer
包简介
Sanitize untrustworthy HTML user input
README 文档
README
This library is deprecated as it was merged into Symfony as the HtmlSanitizer component in Symfony 6.1: https://symfony.com/doc/current/html_sanitizer.html
html-sanitizer is a library aiming at handling, cleaning and sanitizing HTML sent by external users (who you cannot trust), allowing you to store it and display it safely. It has sensible defaults to provide a great developer experience while still being entirely configurable.
Internally, the sanitizer has a deep understanding of HTML: it parses the input and create a tree of DOMNode objects, which it uses to keep only the safe elements from the content. By using this technique, it is safe (it works with a strict whitelist), fast and easily extensible.
It also provides useful features such as the possibility to transform images or iframes URLs to HTTPS.
Symfony integration
This library is also available as a Symfony bundle.
Documentation
- Getting started
- Creating an extension to allow custom tags
- Configuration reference
- Comparison with HTMLPurifier
Security Issues
If you discover a security vulnerability within the sanitizer, please follow our disclosure procedure.
Backward Compatibility promise
This library follows the same Backward Compatibility promise as the Symfony framework: https://symfony.com/doc/current/contributing/code/bc.html
Note: many classes in this library are either marked
@finalor@internal.@internalclasses are excluded from any Backward Compatiblity promise (you should not use them in your code) whereas@finalclasses can be used but should not be extended (use composition instead).
Thanks
Many thanks to:
- The Open Web Application Security Project from which many of the tests of this library are extracted (more specifically from OWASP/java-html-sanitizer) ;
- Masterminds/html5-php which is a great HTML5 parser, used by default in this library ;
- The PHP League URI parser which allows this library to filter hosts safely ;
tgalopin/html-sanitizer 适用场景与选型建议
tgalopin/html-sanitizer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.3M 次下载、GitHub Stars 达 365, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tgalopin/html-sanitizer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tgalopin/html-sanitizer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 5.3M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 366
- 点击次数: 24
- 依赖项目数: 9
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04