fossar/htmlawed
Fork of kesar/HTMLawed maintained by selfoss and wallabag. A single-file (~45KB) PHP HTML filter/sanitizer that secures and tidies user input, making it standards-compliant for HTML/XHTML/XML, with extensive customization options.
Purpose Alignment (Updated)
<details> Element Support: PR #19 allows flow content (e.g., <summary>, <p>) inside <details>, aligning with modern web standards. This is a game-changer for Laravel apps using collapsible sections (e.g., FAQs, accordions).<img/>, <br/>), reducing XSS risks in malformed HTML. This is proactive security for user-generated content.kesar/HTMLawed v1.2.15 (PR #17) suggests ongoing maintenance, though contributor activity (@Kdecherf, @j0k3r) remains limited to 2 developers.Laravel-Specific Synergy
<details> Support: Enable rich interactive content in Blade templates without escaping:
<details>
<summary>Click for details</summary>
<p>{{ $htmlawed->sanitize($userComment) }}</p>
</details>
<img/> from old CMS exports).<details> and stricter tag validation:
Rule::macro('sanitized_html', function (array $allowedTags = ['details', 'summary']) {
// ...
});
Backward Compatibility
<details> and <summary> if used:
$htmlawed->allowTags(['details', 'summary']);
<img/>), which may require updating existing whitelists.Laravel 11+ Readiness
kesar/HTMLawed v1.2.15.<details>-related attributes (e.g., open):
$htmlawed->allowAttributes(['details' => ['open']]);
Maintenance Risk (Reduced)
@j0k3r (new contributor) suggest growing community interest, but still no formal governance.kesar/HTMLawed stalls (last release: 2021). Mitigate by:
@Kdecherf’s activity drops.fossar/htmlawed to ^1.3.4 in composer.json to avoid auto-updates.Functional Risk (Low)
<br/>). Audit:
<img/> or <br/> tags.<details> Quirks: Ensure nested content (e.g., <details><p>{{ $unsafe }}</p></details>) doesn’t trigger false positives.Security Risk (Improved)
<script/> or <iframe/> (should still be blocked).<svg/> tags are not allowed by default (they should be explicitly whitelisted).<details> Security: Ensure no event handlers (e.g., ondetailschange) are accidentally allowed.HTML5 Compatibility Needs
<details>/<summary> for interactive content? If yes, this release directly enables it.<img/>)? Plan for sanitization failures during migration.Validation Rule Updates
sanitized_html macro to include:
$htmlawed->allowTags(['details', 'summary']);
$htmlawed->allowAttributes(['details' => ['open']]);
<details>
<summary>Nested Example</summary>
<p>{{ $userInput }}</p>
</details>
Legacy HTML Migration
SELECT * FROM posts WHERE content LIKE '%<img/%' OR content LIKE '%<br/%';
$content = str_replace(['<img/', '<br/'], ['<img ', '<br>'], $content);
Performance Impact
<details> parsing in high-volume contexts (e.g., 10K+ comments). Use Laravel’s bench():
$htmlawed->bench(function () {
$htmlawed->sanitize($largeHtmlString);
});
Long-Term Viability
@Kdecherf or @j0k3r for critical updates.sanitizeHtml(): Now supports <details> but lacks attribute control.PHP/Laravel Ecosystem (Expanded)
<details>/<summary> (e.g., documentation, FAQs).<p>, <a>, and <img> (no <details>), the benefits are marginal.Dependency Synergy
sanitized_html rule to support <details>:
Rule::macro('sanitized_html', function (array $allowedTags = ['details', 'summary']) {
$htmlawed = new \htmlawed\HTMLawed();
$htmlawed->allowTags($allowedTags);
return function ($attribute, $value, $fail) use ($htmlawed) {
if ($htmlawed->sanitize($value) !== $value) {
$fail("The {$attribute} field contains unsafe HTML.");
}
};
});
<details>-safe content:
Blade::directive('details', function ($expression) {
return "<?php echo (new \htmlawed\HTMLawed())->sanitize({$expression}); ?>";
});
Usage:
@details($userComment)
Pilot: <details> Support
<details> and <summary> in a non-critical section (e.g., blog footer FAQ):
$htmlawed = new \htmlawed\HTMLawed();
$htmlawed->allowTags(['details', 'summary']);
$htmlawed->allowAttributes(['details' => ['open']]);
**Phase 2: Self-Cl
How can I help you explore Laravel packages today?