Whilst discussing #2506195: Remove SafeMarkup::set() from Xss::filter() it became obvious that if we are relying on Twig's auto-escaping for security then any other theme engine will need to implement logic to escape unsafe html before printing.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | document_that_alternate-2528284-11.patch | 831 bytes | cilefen |
| #11 | interdiff.txt | 695 bytes | cilefen |
| #9 | document_that_alternate-2528284-9.patch | 833 bytes | cilefen |
| #7 | 2528284-7.patch | 837 bytes | dawehner |
Comments
Comment #1
alexpottComment #2
cilefen commentedComment #3
star-szrDefinitely, thanks for this.
Comment #4
xjmComment #5
David_Rothstein commented@corbacho in #1537050-53: [meta] Should we keep / improve multiple theme engine functionality? points out that:
I think it would make sense for core to add a simple handy procedural wrapper, something like:
That way all it takes for an alternative theme engine such as PHPTemplate to be safe is to do this everywhere in the template:
print safe($variable);rather than:
print $variable;Of course the wrapper isn't strictly necessary, but it's a good place to document things, and asking people to deal with namespaces in a .tpl.php file would be painful. It's similar to how Drupal 7 introduced functions like hide(), show(), and render() to make life a little easier on themers.
Comment #6
David_Rothstein commentedComment #7
dawehnerJust a bit of a start
Comment #8
joelpittetComment #9
cilefen commentedComment #10
star-szrGreat start thanks @cilefen!
This is \Drupal\Component\Render\MarkupInterface now as of #2576533: Rename SafeStringInterface to MarkupInterface and move related classes.
Comment #11
cilefen commentedComment #12
dawehnerI'm curious whether we could point to the nyan cat test one as an example?
Comment #13
lauriiiNyan cat engine is simple example how to implement auto escape. I was wondering, maybe we could add some extra docs there and then use it as reference.
Comment #15
fabianx commentedBump
Comment #16
nikhilesh gupta commentedComment #21
markhalliwellLGTM
Comment #22
alexpott#12 and #13 haven't been answered? I looked at
nyan_cat_render_template()- I'm not sure though there is that much to be gained though since the docs added point totheme_render_and_autoescape()and that's really all thatnyan_cat_render_template()calls. I'll ping @dawehner and @lauriii.Comment #23
dawehnerWhile I get your point I think seeing that implementing auto-escaping would actually not be hard on a real instance might be motivating for people to do so. On the other hand, yeah, I'm totally fine with not adding the pointer.
Comment #24
alexpott@lauriii pinged me in slack and said +1 to commit... so...
Committed and pushed 4105b5560b to 8.6.x and 5b8696b263 to 8.5.x. Thanks!