Problem/Motivation
The FormattableMarkup::placeholderFormat() doc says about :variable placeholders:
Use when the return value is to be used as a URL value of an HTML attribute. Only the "href" attribute is supported.
[...]
Use this when using the "href" attribute, ensuring the value is always wrapped in quotes.
Is there a reason to restrict it to href attributes?
I think it makes sense to use this kind of placeholder on other attributes containing URLs that could be an XSS vector:
- src attribute on iframe elements
- action attribute on form element
- data attributes that store a URL (that is used later in JS for example)
:variable placeholders are sanitized like this:
- Dangerous protocols are removed.
- The value is HTML escaped.
I think the only reason we don't want use it on any attribute is that step 1 would mangle non-URL attributes containing a : character. But it totally makes sense on any attribute that will always contain a URL.
Steps to reproduce
Proposed resolution
Edit the docblock to be about any attribute containing a URL.
Comments
Comment #2
prudloff commentedComment #3
prudloff commentedJust noticed we give this example in the doc:
While still saying that only href is supported.