sanitize_html 包是一个 Dart 工具,旨在通过过滤掉潜在危险的元素和属性来安全地清理 HTML 内容,防止 XSS 攻击。它允许开发者定义一个安全的 HTML 标签和属性子集,确保仅渲染受信任的内容。适用于处理用户生成内容的应用程序,支持所有主要平台,包括 Web、移动和桌面。该包由 Google 维护,并可与 Flutter 项目无缝集成。
适合场景
处理用户生成的内容
安全地渲染富文本
防止 Web 视图中的 XSS
保护表单输入
显示来自不受信任源的markdown或HTML
主要特点
安全的 HTML 过滤
可自定义的允许标签和属性
跨平台支持
轻量且高效
由 Google 维护
适合对象
带有用户输入的网页和移动应用
内容管理系统
聊天或评论区域
教育平台
安全文档渲染
使用建议
需要显式定义安全规则
如果过于严格,可能会删除所需的格式
不适用于完整的HTML转换
大型 HTML 字符串的性能影响
仅限清理,不包括解析或渲染
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
Dart Neats
A collection of a small neat packages for dart.
Disclaimer: This is not an officially supported Google product.
This repository is meant as a playground where small neat packages are
cultivated. If package grows too large and complex and needs a dedicated issue
tracker it should be moved to a dedicated repository.
Each folder in this repository contains a neatpub package. This project
aims to use a separate package whenever it makes sense to have an independent
major version. This often means splitting functionality into separate packages,
which can be reused independently.
Utility for vendoring packages into a project and rewriting import/export statements.
Repository Management
Packages in this repository uses pub workspaces
a single dart pub get will resolve dependencies for all of them.
Configuration of Github Actions, issue templates, issue labels, etc is automated
with scripts in tool/.
Contributing
We love patches and contributions, please refer to CONTRIBUTING.md for
technicalities on CLA and community guidelines. As this project aims to
build neat packages using other neat packages we might also accept proposals
for new neat packages, though it's often easier to publish independently.
License
Unless stated otherwise contents in this repository is licensed under
Apache License 2.0, see LICENSE.