symfony/html-sanitizer
Symfony HtmlSanitizer provides an object-oriented API to sanitize untrusted HTML before inserting it into the DOM. Configure allowed/blocked tags and attributes, drop or keep children, force attribute values, enforce HTTPS, and restrict link schemes/hosts to prevent XSS and unsafe behavior.
Enhanced Security for URL-Based Attacks
action, formaction, poster, and cite. Justify upgrading to v8.1.0-BETA3 to block:
\u202E) in URLs, which can bypass sanitizers.<area> tags and host-whitelisted links/media.Roadmap Refinement for High-Risk Features
<img poster>), and interactive elements (e.g., <form action="...">) where URL-based XSS is most prevalent.allowLinkHosts/allowMediaHosts fixes to tighten third-party embeds (e.g., YouTube iframes, custom widgets) by preventing host-bypass exploits.data-* attributes).Performance and Maintainability
Developer Experience (DX) for Security Teams
allowLinkHosts/allowMediaHosts improvements enable fine-grained control over external resources (e.g., restricting media to cdn.example.com).Look Elsewhere If:
javascript:, data:, or custom protocols like app://). This release does not whitelist these by default; explicit configuration is required.filter_var improvements). Test compatibility if using older versions.filter_var with FILTER_VALIDATE_URL).Adopt If:
<a href="...">, <form action="...">, <img src="...">).preg_replace, parse_url) to a maintained solution.*"We’ve identified three critical XSS vulnerabilities in how our app handles URLs—from file uploads to interactive forms—that could let attackers bypass our current sanitization. The latest Symfony HtmlSanitizer v8.1.0-BETA3 patches these gaps with zero configuration changes to our codebase:
- Blocks BiDi override characters (used in phishing attacks).
- Fixes URL parser exploits in links and media embeds.
- Hardens host whitelisting for third-party resources.
This is a direct mitigation for OWASP’s Injection risks and aligns with PCI-DSS. The upgrade is low-risk (backward-compatible) and high-impact—preventing attacks like clickjacking, open redirects, and malicious media loads. Given the CVEs, we should prioritize this as a security hotfix for Q3, with a focus on forms, uploads, and embeds."*
Ask: "Should we treat this as a critical patch (like a dependency update) or defer until our next security sprint?"
*"v8.1.0-BETA3 closes three CVEs targeting URL-based XSS in HTML attributes. Here’s the impact:
- No Breaking Changes: Safe to upgrade; we only need to rebuild dependencies.
- Automated Fixes: Covers edge cases we’d otherwise handle with custom regex (e.g., percent-encoded spaces, BiDi chars).
- Host Whitelisting Improvements: Simplifies securing
<img>,<iframe>, and<a>tags withallowLinkHosts.Proposal:
- Pilot in high-risk areas: Forms (
action,formaction), media (poster,src), and links (href).- Audit third-party embeds: Update
allowMediaHoststo reflect the new URL parser strictness.- Deprecate custom URL sanitizers: Replace any
preg_replace/parse_urlhacks with the component’s built-in validation.Trade-off: If you use non-standard URLs (e.g.,
data:URIs), you’ll need to explicitly configure them. Otherwise, this is a drop-in security win."*
Ask: "Does this align with our secure-by-default initiative? Should we pair it with a URL validation layer for dynamic redirects?"
*"v8.1.0-BETA3 is a security-focused upgrade—here’s what’s changed under the hood:
- URL Attributes Are Now Hardened: No more BiDi exploits or malformed schemes slipping through in
action,href, etc.- Host Whitelisting is Stricter: The
allowLinkHosts/allowMediaHostsrules now parse URLs more rigorously (e.g., rejectshttp://example.com/with a trailing space).- Event-Driven Extensibility: If you need to allow custom URL schemes (e.g.,
app://), use theHtmlSanitizerEvents::PRE_SANITIZEevent.Migration Steps:
- Update
composer.jsontosymfony/html-sanitizer:^8.1.0-BETA3.- No config changes needed unless you rely on edge cases (e.g.,
javascript:links).- Test forms/media uploads: Focus on attributes like
action,src,poster, andcite.Example (New Host Whitelisting):
$config = (new HtmlSanitizerConfig()) ->allowLinkHosts(['https://cdn.example.com', 'https://trusted-api.com']); // Now safely rejects: `<a href="https://cdn.example.com/ ">`Pro Tip: Use
->allowElement('iframe', ['src' => ['allowMediaHosts']])to tie media hosts to iframes explicitly."*
Ask: "Should we add a pre-commit hook to scan for custom URL sanitization code that needs replacement?"
How can I help you explore Laravel packages today?