stevebauman/purify
Laravel wrapper for HTMLPurifier to sanitize user HTML safely. Clean strings or arrays via the Purify facade, with optional per-call configuration. Publish a config file, tune allowed tags/attributes, and leverage caching for performance.
Strengths:
default, comments, wysiwyg), enabling granular control over sanitization rules per use case.Definition and CssDefinition.Fit for Use Cases:
Dependencies:
Compatibility:
dom, libxml, and filter extensions (common in Laravel deployments).memory_get_usage().HTML.Allowed). Errors may require deep debugging.<script> if misconfigured). Validate with tools like OWASP XSS Tester.purify:clear) must be automated (e.g., post-deployment) to avoid stale definitions.<iframe>)?data-*, aria-*)?text-align: start)?purify:clear)?Purify::clean() integrates natively with Laravel’s facade pattern, reducing coupling.PurifyHtmlOnGet cast enables declarative sanitization in models (e.g., Post::content).App\Http\Middleware\SanitizeInput) or form requests.request()->input('description')).Post) using PurifyHtmlOnGet.HTML.Allowed rules early (e.g., div,p,a[href]).default, wysiwyg) to avoid over-permissive defaults.protected $casts syntax.casts() method in models.TEXT in MySQL).CacheDefinitionCache over FilesystemDefinitionCache for shared environments (e.g., Kubernetes).purify_definitions) to avoid conflicts.composer require stevebauman/purify.php artisan vendor:publish --provider="Stevebauman\Purify\PurifyServiceProvider".config/purify.php with strict defaults (e.g., minimal HTML.Allowed).Purify::clean() with malicious inputs (e.g., <script>, onerror=).php artisan purify:clear post-deploy to invalidate cache.HTMLPurifier_Exception).serializer config).tideways/xhprof or Laravel Debugbar.HTML.Allowed or CSS.AllowedProperties require cache clearing (purify:clear).comments, wysiwyg) in a CONFIGURATION.md.Definition/CssDefinition classes in a separate module (e.g., app/Definitions/).config/purify.php) in Git.'debug' => env('PURIFY_DEBUG', false),
\Log::debug('Sanitized input', ['raw' => $rawInput, 'clean' => $cleaned]);
How can I help you explore Laravel packages today?