Polyscope - The agent-first dev environment for Laravel

Purify

stevebauman/purify image

Purify stats

Downloads
2M
Stars
366
Open Issues
0
Forks
33

View on GitHub →

An HTML Purifier / Sanitizer for Laravel

Laravel Purify Package Summary

Laravel Purify is a package that provides a simple Laravel wrapper around the HTMLPurifier library, enabling developers to clean and filter HTML inputs within their Laravel applications effectively.

Key Features:

  • Flexible Cleaning: Purify allows cleaning of individual strings or arrays of HTML content, ensuring that your application is safe from XSS attacks while preserving the necessary HTML tags.
  • Dynamic Configuration: Users can specify different HTMLPurifier configurations on-the-fly, adapting to various content filtering needs across different parts of the application.
  • Custom HTML Definitions: Extend the built-in HTML definitions or create custom definitions to accommodate specific HTML elements and attributes.
  • Caching Mechanisms: Optimizes performance by caching definitions, with support for file-based and cache-based storage mechanisms.
  • Eloquent Model Casting: Utilizes custom casting to sanitize data automatically when retrieving or setting model attributes.
  • Support for HTML5 and Custom Tags: Includes HTML5 support not originally available in HTMLPurifier and allows for the customization to support unique tags like those from the Basecamp Trix editor.

Installation:

To install Purify, use Composer:

composer require stevebauman/purify

After installation, publish the configuration file:

php artisan vendor:publish --provider="Stevebauman\Purify\PurifyServiceProvider"

Usage Examples:

Cleaning a String:

use Stevebauman\Purify\Facades\Purify;
 
$input = '<script>alert("bad");</script> <p>Good</p>';
$cleaned = Purify::clean($input); // Returns '<p>Good</p>'

Cleaning an Array:

$dirtyArray = ['<script>alert("bad");</script>', '<p>Good</p>'];
$cleanedArray = Purify::clean($dirtyArray);

Using Custom Configuration:

$cleaned = Purify::config('custom')->clean($input);

Configuration:

Modify the config/purify.php file to adjust HTMLPurifier settings, define custom rules, or manage caching preferences.

Cache Management:

To clear the HTMLPurifier cache, particularly after configuration changes:

php artisan purify:clear

Upgrading:

Steps are provided within the package's README for upgrading from older versions, ensuring a smooth transition and functionality retention.

Overall, Laravel Purify is an essential tool for developers needing robust HTML sanitization solutions, providing ease of use, configurability, and integration with Laravel's features such as Eloquent models.

stevebauman photo

I like to build things on the web 💻


Stevebauman Purify Related Articles

Filter API Responses with Laravel Purity image

Filter API Responses with Laravel Purity

Read article
Top 10 Laravel Audit Security Issues image

Top 10 Laravel Audit Security Issues

Read article
Commonmark Markdown Parser v2.0 Beta 3 Released image

Commonmark Markdown Parser v2.0 Beta 3 Released

Read article
Parsedown v1.7.0 is released image

Parsedown v1.7.0 is released

Read article
The Artisan Files: Adam Wathan image

The Artisan Files: Adam Wathan

Read article
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media