Discovered in #2560863: #options for radios and checkboxes uses SafeMarkup::checkPlain() to escape - use Html::escape() instead
Problem/Motivation
Flipping between auto-escaping and auto XSS admin filtering is really confusing for developers and that is exactly what happens with #options for select (escape), and radios and checkboxes (filter). The admin filtering is applied by template_preprocess_fieldset() and template_preprocess_form_element_label().
Proposed resolution
Remove the XSS admin filtering and allow twig to auto escape. If calling code wants to support HTML here it should use a render array or mark it safe. The configurable options field is not affected because it use FieldFilteredString for this.
Remaining tasks
Do it
Review
Commit
User interface changes
None
API changes
#options is autoescaped and more tba
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | interdiff.txt | 785 bytes | mr.baileys |
| #14 | autoescape_title_element_in_form-2568647-14.patch | 11.89 KB | mr.baileys |
| #9 | autoescape_title_element_in_form-2568647-9.patch | 11.17 KB | mr.baileys |
| #9 | interdiff.txt | 948 bytes | mr.baileys |
| #6 | autoescape_title_element_in_form-2568647-6.patch | 10.25 KB | mr.baileys |
Comments
Comment #2
mr.baileysWill be working on this during the Barcelona sprints
Comment #3
mr.baileysThis removes the '#markup' from the form #title element in template_preprocess_fieldset() and template_preprocess_form_element_label() so it's no longer admin filtered, but rather falls back on twig auto-escaping.
I'm not sure if we need to add explicit test coverage for this?
Comment #6
mr.baileysThis should take care of most of the failures.
Comment #9
mr.baileysThanks to @lauriii I managed to fix the remaining failure.
Comment #10
lauriiiLooks good for me :)
Comment #11
catchLooks great to me but I either need a second opinion or to take another good look at it before I feel 100% happy committing,
Comment #12
alexpottI really like this change as it brings consistency but it needs a CR.
Comment #13
alexpottAlso need to convert
$role_options = array_map('\Drupal\Component\Utility\Html::escape', user_role_names());in core/modules/views/src/Plugin/views/filter/FilterPluginBase.php - Also with this patch that would by double escaped so we're missing test coverage.Comment #14
mr.baileysI have openend #2579829: Missing test coverage for views exposed filter "remember last selection" to add the missing test coverage for core/modules/views/src/Plugin/views/filter/FilterPluginBase.php
Patch attached fixes #13, I'm working on the CR.
Comment #16
alexpottDiscussed with @xjm, @Cottser, @joelpittet and @laurii. All things should autoescape, support translatable markup, support render arrays. We need to add documentation of the sanitisation behaviour of ALL render elements (and workarounds to change them) to the scope of the docs meta. I proposed resolution to add version key to render arrays as a separate 8.x issue.
Comment #17
alexpottCreated #2722747: Discuss being able to version render API to discuss a possible way to achieve this in D8
Comment #27
larowlanWhat's the next steps here?
Comment #29
xjm