joomla/filter
Joomla Filter provides input sanitization and filtering utilities for PHP apps. Use InputFilter to allow/block specific HTML tags and attributes, and OutputFilter for safe output helpers like URL-safe strings. Composer installable, lightweight, framework-ready.
Illuminate\Validation (built-in sanitization rules like sanitize).e() helper (HTML entity encoding).htmlpurifier/htmlpurifier for advanced HTML filtering).OutputFilter::stringURLSafe requires Joomla\Language), creating friction in Laravel’s dependency graph.FilterServiceProvider) to expose InputFilter as a singleton or per-request binding.$this->app->bind('joomla.filter', function () {
return new \Joomla\Filter\InputFilter([], [], InputFilter::ONLY_ALLOW_DEFINED_TAGS);
});
SanitizeInputMiddleware) to filter $request->input() before validation.handle():
public function handle()
{
$this->merge([
'cleaned_content' => InputFilter::clean($this->input('content'), 'html'),
]);
}
Illuminate\Validation\Rules\Rule to encapsulate InputFilter logic:
class SanitizeHtml implements Rule {
public function passes($attribute, $value) {
return InputFilter::clean($value, 'html') !== false;
}
}
| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Security Vulnerabilities | CVE-2022-23800 (fixed in v1.4.4+) and XSS evasion bypasses in older versions. | Pin to v4.0.2+ (latest stable) and audit against OWASP XSS Filter Evasion. |
| Maintenance Status | Last release: 2026-05-26 (active but niche). 0 dependents; Joomla’s shift to PHP 8.3+ suggests focus on CMS, not standalone. | Monitor GitHub issues for breaking changes. Prefer semver-pinned dependencies (^4.0). |
| Architectural Drift | Assumes Joomla’s event system (e.g., onFilter). Laravel’s event system is incompatible. |
Abstract Joomla-specific logic into adapters (e.g., JoomlaFilterAdapter for Laravel events). |
| Performance | No benchmarks, but DOM parsing (e.g., stripImages) may be slower than DOMDocument. |
Profile with laravel-debugbar and compare against htmlpurifier. |
| PHP Version Lock-in | v4.x requires PHP 8.3; v3.x requires 8.1. | Use runtime version checks (e.g., if (PHP_VERSION_ID < 80300) throw new \RuntimeException(...)). |
htmlpurifier?)<script> tags, SVG XSS)?| Laravel Component | Integration Strategy | Example Implementation |
|---|---|---|
| Request Handling | Middleware to filter $request->all() or $request->input(). |
```php |
public function handle($request, Closure $next) {
$request->merge([
'safe_content' => InputFilter::clean($request->input('content'), 'html'),
]);
return $next($request);
}
``` |
| Validation | Custom validation rules (e.g., SanitizeHtml). | php 'content' => ['required', new SanitizeHtml], |
| Forms/Requests | Override handle() in FormRequest to sanitize before validation. | php public function rules() { return ['content' => 'required|sanitize_html']; } protected function prepareForValidation() { $this->merge(['content' => InputFilter::clean($this->content, 'html')]); } |
| Blade Templates | Use {{ $safeHtml }} (auto-escaped) or @php($filtered = InputFilter::clean($html, 'html')). | blade {!! $filtered !!} <!-- Safe if filtered with ONLY_ALLOW_DEFINED_TAGS --> |
| API Responses | Filter data before JSON serialization (e.g., in AppServiceProvider). | php Event::listen('illuminate.query.executed', function ($query) { if ($query->getQuery()->from === 'posts') { $query->selectRaw('InputFilter::clean(body, "html") as safe_body'); } }); |
| Database Storage | Use database observers or model events to sanitize before save(). | php protected static function booted() { static::saving(function ($model) { $model->content = InputFilter::clean($model->content, 'html'); }); } |
Pilot Phase (Low Risk)
composer require joomla/filter:^4.0 --dev
<script>alert(1)</script>).<iframe>, SVG vectors).e() and strip_tags() for regressions.Gradual Rollout (Medium Risk)
strip_tags() in non-critical paths (e.g., user profiles).SanitizeHtml).Full Adoption (High Risk)
OutputFilter).InputFilter to support Laravel events (e.g., illuminate.events).vendor/laravel-filter) for maintainability.How can I help you explore Laravel packages today?