Problem/Motivation
Xss::filterAdmin() is used in several places to filter admin-trusted text (for example, Views token/rewrite output via HandlerBase and PluginBase). filterAdmin() always strips the "style" attribute, even though the text being filtered is authored by a trusted admin user. This makes it impossible for a site builder to use inline styles in an admin-authored Views "rewrite the output of this field" token value or similar admin-trusted text, without switching to a much more permissive filter.
Proposed resolution
Add a new static method Xss::filterAdminWithStyles() alongside the existing filterAdmin(). It behaves exactly like filterAdmin() (same allowed tag list, same protections) except that it does not strip the "style" attribute. Internally this is implemented with a protected static flag that filterAdmin()'s underlying attribute-skip logic checks, so the change is additive and filterAdmin() itself is unaffected.
Update the Views token rewriting call sites that currently call Xss::filterAdmin() on admin-authored text (PluginBase::tokenizeValue() and HandlerBase::render_text) to call Xss::filterAdminWithStyles() instead, so inline styles in admin-authored rewrite tokens are preserved.
Two patches attached: one adding filterAdminWithStyles() to Xss.php, and one switching the Views PluginBase/HandlerBase call sites to use it.
Remaining tasks
Discuss whether this should be opt-in via a new token/filter format instead of changing the existing Views rewrite behavior; add test coverage.
| Comment | File | Size | Author |
|---|---|---|---|
| views-token-allow-style-attributes.patch | 876 bytes | burcu.sogut@drupart.com.tr | |
| xss-allow-style-in-filter-admin.patch | 1.49 KB | burcu.sogut@drupart.com.tr |
Comments
Comment #2
larowlanThis feels like won't fix to me
There are many other ways to add CSS to a site
We shouldn't encourage bad practices