-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
html_attr: do not escape colons #3614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 3.x
Are you sure you want to change the base?
Conversation
|
The goal is to escape things like |
|
Good point!
So for some attributes (like |
|
The href attribute is indeed a bit special due to links allowing to execute JS |
|
Even with
{% set attr = "javascript:alert(1)" %}
<a href="{{ attr|e('html_attr') }}">Click</a>will result in: <a href="javascript:alert(1)">Click</a>(https://twigfiddle.com/n1rbba) This is still executable javascript: https://jsfiddle.net/9ekxLy6u/ So I'm still not sure whether the Could also be relevant for #3760. |
e97d0c2 to
543f28c
Compare
|
I am not using Vue.js myself, so I cannot tell for sure, but according to https://v2.vuejs.org/v2/guide/syntax.html#v-bind-Shorthand this might not only affect The HTML 5 spec does not exclude all those characters from attribute names (https://html.spec.whatwg.org/multipage/syntax.html#attributes-2). XML processors will treat the colon as the XML namespace separator. HTML 5 allows XML only on SVG and MathML elements, and only for pre-defined namespace-prefixes (https://developer.mozilla.org/en-US/docs/Web/API/Attr/localName#:~:text=That%20means%20that%20the%20local,different%20from%20the%20qualified%20name). For other According to https://engine.sygnal.com/research/html5-attribute-names, all current browser implementations handle at least the colon fine, and the aforementioned Vue.js documentation suggests that this is also the case for So, if we'd want to support this, I think it should at least be introduced in a BC way, i. e. with a new escaping strategy name that lets users opt into the new mode with less escaped characters. |
Is it necessary to escape the
:inhtml_attrcontext?For example in this code:
{% for key, value in attributes %} {{ key|escape('html_attr') }}="{{ value }}" {% endfor %}I think it should be allowed to use attribute keys like
v-on:submit.prevent.