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.

Comments

burcu.sogut@drupart.com.tr created an issue.

larowlan’s picture

This feels like won't fix to me

There are many other ways to add CSS to a site

We shouldn't encourage bad practices