elementareteilchen / html-purify
添加html purify功能作为视图助手和服务类
v2.0.0
2024-07-04 09:52 UTC
Requires
- ezyang/htmlpurifier: ^4.17
- typo3/cms-core: ^11.5 || ^12.4
README
净化HTML,以防止XSS攻击或不需要的HTML。
特性
此扩展为您提供了净化特定HTML的机会,这些HTML可能不完全受您控制,以消除可能的跨站脚本(XSS)攻击。
安装
只需使用Composer安装扩展。
composer require elementareteilchen/html-purify
此扩展使用ezyang/htmlpurifier,它被设置为Composer要求以自动加载。
使用方法
视图助手
<hp:purify allowedHtmlTags="strong,em">{someVariableWithPotentialXSS -> f:format.raw()}</hp:purify>
{someVariableWithPotentialXSS -> f:format.raw() -> hp:purify()}
{hp:purify(allowedHtmlTags: 'p,strong', htmlContent: '<p>Text with <strong>HTML</strong> but <em>EM will be removed</em></p>')}
PHP代码中的服务
$purifiedHtml = \ElementareTeilchen\HtmlPurify\Service\PurifyService::purify($htmlContent, $allowedHtmlTags);