FLUTTER ECOSYSTEM

sanitize_html

Function for sanitizing HTML to prevent XSS by restrict elements and attributes to a safe subset of allowed values.

Latest version
2.1.0
30-day downloads
701.3K
Likes
51
Pub points
160

Package Overview

Selection guidance generated from public package information. For reference only.

Overview

The sanitize_html package is a Dart utility designed to securely sanitize HTML content by filtering out potentially dangerous elements and attributes, preventing XSS attacks. It allows developers to define a safe subset of HTML tags and attributes, ensuring only trusted content is rendered. Ideal for applications that process user-generated content, it supports all major platforms including web, mobile, and desktop. The package is maintained by Google and integrates seamlessly with Flutter projects.

Use cases
  • Processing user-generated content
  • Rendering rich text safely
  • Preventing XSS in web views
  • Securing form inputs
  • Displaying markdown or HTML from untrusted sources
Key features
  • Safe HTML filtering
  • Customizable allowed tags and attributes
  • Cross-platform support
  • Lightweight and efficient
  • Maintained by Google
Suitable for
  • Web and mobile apps with user input
  • Content management systems
  • Chat or comment sections
  • Educational platforms
  • Secure document rendering
Considerations
  • Requires defining safe rules explicitly
  • May strip desired formatting if overly restrictive
  • Not suitable for full HTML transformation
  • Performance impact with large HTML strings
  • Limited to sanitization, not parsing or rendering
Supported platformsAndroidiOSWebmacOSWindowsLinux

Install package

flutter pub add sanitize_html

Categories

Source repository

Related projects