Problem/Motivation

See discussion in #2572929: Document lack of auto-escape in theme functions and add a theme autoescape helper function partially.

In Drupal 7, it was the responsibility of module code to sanitize text. In Drupal 8, module authors are encouraged to rely on the late escaping functionality provided by Twig autoescape. PHPTemplate does not provide autoescaping functionality, which means that in general a theme using PHPTemplate is not safe with Drupal 8 module code.

Proposed resolution

Remaining tasks

  • Review
  • Commit
  • Profit

User interface changes

API changes

Data model changes

Comments

dawehner created an issue. See original summary.

wim leers’s picture

Priority: Normal » Major
xjm’s picture

Title: Discuss whether we want to remove PHPTemplate » Discuss whether we want to deprecate or remove PHPTemplate, or document that it must perform sanitization
Priority: Major » Critical
Issue summary: View changes

Discussed with @alexpott, @stefan.r, @lauriii, @joelittet, and @dawehner. At a minimum, clearly documenting that theme engines are expected to sanitize non-safe text in templates is critical, because module code now often relies on autoescape.

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new1.85 KB

Added a piece of documentation + throwing a deprecation notice.

Status: Needs review » Needs work

The last submitted patch, 4: 2574717-4.patch, failed testing.

stefan.r’s picture

Assigned: Unassigned » stefan.r

Talked with @dawehner and @tim.plunkett and we'll add a hook_requirements() as well as the deprecation in test error handler for the specific test.

eli-t’s picture

+++ b/core/themes/engines/phptemplate/phptemplate.engine
@@ -3,6 +3,15 @@
+ * it, makes it really hard to provide safe output. Instead its highly

Should be "Instead it is highly..." or "Instead it's highly..."

rainbowarray’s picture

Personally I think it's confusing to still include phptemplate in core. Earlier in the D8 cycle, when I spoke to people about using Twig now, I had at least one person say "Sure, but you can still use phptemplate for themes." In reality that's going to be a bucket of pain. We can try to educate people to not use phptemplate through documentation, etc., but I think it would be much better to not provide that in core. If somebody really wants to make use of phptemplate, then taking that on could be a contrib task.

dawehner’s picture

Well, personally for me, its about the communication we agreed on at some point: We won't break any existing functionality anymore, unless really needed.
This here is an API removal, not just an API change. ... but yeah each phptemplate will be drastically unsafe. Especially for themes it just doesn't make sense to straightly convert them,
all variable names / templates changed anyway.

On the other hand IMHO to resolve the critical part of this issue it is simply enough to document and deprecated it. This gives us then an easy way forward to remove it in the future.

hongpong’s picture

It seems wise to remove PHPTemplate if it's missing all these sanitization tools, but really this should have already been decided a couple years ago.

pwolanin’s picture

I think given how much is will admit bad ports from 7 if we leave it, we should remove it.

damontgomery’s picture

pwolanin++

I'm all for removing deprecated options. There are already enough "please don't do this" options in the theming system.

The last submitted patch, 4: 2574717-4.patch, failed testing.

xjm’s picture

I am also leaning toward removing it entirely, FWIW. As I mentioned to @dawehner in IRC, I feel a PHPTemplate theme is practically guaranteed to have an XSS vulnerability at this point, more so than even some of the other things we've made it critical to remove. And while this would totally break any PHPTemplate theme already ported... they are most likely already broken.

It is a big BC break though if you were expecting it to work still in D8. I'd suggest doing the thing we did with checkPlain() where we deprecate and announce the removal because of the late beta BC break, except if we do have an RC soon then it wouldn't be much forewarning anyway. We should have deprecated it a year ago. Oops. =/

Tweeted about the issue to try to get some visibility: https://twitter.com/xjmdrupal/status/647483540104478720

davidhernandez’s picture

I agree it would be hard to even get it to work properly and you'd be in a world of hurt trying to use it to the same degree as Twig. Let that be handled outside of core, if really necessary. And if we leave it, +1 to what pwolanin said. People are going to try to port themes directly, which we don't want. We want them putting the effort into converting to Twig.

mikeker’s picture

Yet another vote for removing it before the RC, even with the BC break @xjm describes in #14. Because if we don't now, we'll be supporting it until 9.0.0. Does anyone want to do that?

A little pain now vs. lots of pain over the next few years...

lauriii’s picture

StatusFileSize
new7.87 KB

The most awesome test in progress.

davidhernandez’s picture

Adding to what Mike said, the real question is are we going to support phptemplate? If a critical problem is found with it, who is going to fix it or care? If it stays we have a responsibility to support it, and I don't think anyone wants any part of that. And if you've been porting a theme to phptemplate in 8, you've literally been ignoring anything and everything everyone has been saying about theming in 8.

stefan.r’s picture

Assigned: stefan.r » Unassigned
dawehner’s picture

StatusFileSize
new16.01 KB

Pair programming

lauriii’s picture

Status: Needs work » Needs review
StatusFileSize
new18.3 KB

Sending first time for the test bot. Removes phptemplate templating engine and replaces it with awesome Nyan cat templating engine!!

webchick’s picture

Discussed with @alexpott, @stefan.r, @dawehner, @Berdir, @pfrenssen, @lauriii.

One of the primary reasons that we focused on removing the ! t() placeholder is because we want to live by the mantra that the theme system auto-escapes for you. Leaving support for PHPTemplate in core leaves a glaring hole in this strategy, and if we don't remove it before RC1, we're stuck supporting it in D8 until Drupal 10.

What we did agree on is that it definitely is required to support multiple theme engines in core (Smarty, et al). So we can remove PHPTemplate as long as we have test coverage to confirm that theme engine support persists.

@stefan.r also brought up the point from @davidhernandez that we don't have the resources to commit to supporting two theme engines in core. I agree; much better to whole-ass Twig. :)

So consider it decided. :) Dawehner and lauriii are working on a patch.

webchick’s picture

Title: Discuss whether we want to deprecate or remove PHPTemplate, or document that it must perform sanitization » Remove PHPTemplate, and add test coverage for multiple theme engine support
xjm’s picture

Issue tags: +Needs change record

We should also document... somewhere that any other templating engine would also need to handle sanitization of variables. And that should probably also get added to the change records, too. Speaking of. :)

xjm’s picture

Does #21 intentionally include the other patch from the other issue?

lauriii’s picture

Yes, its for testing purposes. So this is blocked by that

davidhernandez’s picture

Does this need more than a change record? Its own core announcement or anything?

dawehner’s picture

We should also document... somewhere that any other templating engine would also need to handle sanitization of variables. And that should probably also get added to the change records, too. Speaking of. :)

These parts can be pulled out from the earlier patch.

hussainweb’s picture

StatusFileSize
new955 bytes
new18.36 KB

Just fixing very small nitpicks.

Status: Needs review » Needs work

The last submitted patch, 29: remove_phptemplate-2574717-29.patch, failed testing.

davidhernandez’s picture

Issue tags: -Needs change record

Added change record draft.

The last submitted patch, 29: remove_phptemplate-2574717-29.patch, failed testing.

hussainweb’s picture

Status: Needs work » Needs review
StatusFileSize
new552 bytes
new18.24 KB

Fixing that error. It was a copy/paste issue.

hussainweb’s picture

I agree on removing PHPTemplate. Is the reason to add nyan cat just to allow testing of multiple theme engines? If so, we should document that a bit more clearly.

lauriii’s picture

Its under testing module section so I dont personally see reason to add extra documentation beside what we already have. Anyway if you disagree, maybe you could add some docs?

dawehner’s picture

@hussainweb this was coming from the theme function issue so its not up for this issue to discuss it.

longwave’s picture

@hussainweb: I think that strlen check was there for a reason; consider the case where #markup is '0'.

hussainweb’s picture

StatusFileSize
new554 bytes
new18.27 KB

@lauriii, @dawehner: I just wanted to understand this myself first, that's all. It's true that this being under tests directory is an indication enough. I didn't notice that earlier.

@longwave: You're right. I built a table in my head to see where it could be affected, but missed '0'. Reverting that change now.

pfrenssen’s picture

___━*━___━━___━__*___━_*___┓━╭­­­­­━━━━╮
__*_━━___━━___━━*____━━___┗┓|:­­­­­:::::^-------^
___━━___━*━___━━____━━*___━┗|:­­­­­:::|。◕‿‿­­­­◕。|
___*━__━━_*___━━___*━━___*━━╰O­­­­­--O---O--O

davidhernandez’s picture

Change record updated appropriately.

star-szr’s picture

This is so awesome!

David_Rothstein’s picture

We should also document... somewhere that any other templating engine would also need to handle sanitization of variables.

There's an older issue for that (linked) mentioning at least one more place where it needs documenting.

larowlan’s picture

+++ b/core/modules/language/language.admin.inc
@@ -201,5 +201,5 @@ function template_preprocess_language_content_settings_table(&$variables) {
 function theme_language_content_settings_table($variables) {
...
+  return '<h4>' . theme_escape_and_render($variables['build']['#title']) . '</h4>' . drupal_render($variables['build']);

I think this is asking for trouble - can't the theme system/engine do this for us - i.e. it already knows which theme hooks are functions and which use a template - can't it call theme_escape_and_render on non templates automatically? We don't want to leave it to chance - it will be easy to forget.

larowlan’s picture

xjm’s picture

Status: Needs review » Postponed

Looks like there is a lot of confusion about these two patches' overlap and dependency -- let's postpone this one explicitly.

Thanks for the CR. I'll draft an announcement for g.d.o/core.

dawehner’s picture

We can still review the other bits of the patch.

pwolanin’s picture

Status: Postponed » Needs review
StatusFileSize
new8.76 KB
new8.71 KB

ok, here's a clean patch just for phptemplate removal and addition of the test engine.

I don't think we need to postpone this since is no overlap?

dawehner’s picture

Status: Needs review » Postponed

/me shakes head

pwolanin’s picture

sorry, I didn't realize it uses the new function.

Status: Postponed » Needs work

The last submitted patch, 48: 2574717-48.patch, failed testing.

dawehner’s picture

And I didn't read the code correctly :)

The last submitted patch, 48: 2574717-48.patch, failed testing.

lauriii’s picture

Status: Needs work » Postponed
plach’s picture

xjm’s picture

dawehner’s picture

StatusFileSize
new8.79 KB
new1.2 KB

Just some minimal changes.

dawehner’s picture

Status: Postponed » Needs review
Issue tags: +D8 Accelerate
StatusFileSize
new8.79 KB

Reroll

dawehner’s picture

Issue summary: View changes

Some issue summary update

Status: Needs review » Needs work

The last submitted patch, 58: 2574717-58.patch, failed testing.

dawehner’s picture

Assigned: Unassigned » dawehner

Looking into it

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new8.79 KB
new812 bytes

There we go.

dawehner’s picture

Assigned: dawehner » Unassigned

.

borisson_’s picture

Issue tags: +Needs change record

This needs a change record but otherwise it looks really good.

dawehner’s picture

Thank you @borisson_
working on that now.

davidhernandez’s picture

Issue tags: -Needs change record

There is a change record draft. They are always listed in the sidebar.

dawehner’s picture

Tst tss tsts tsts tststs @borisson_ open your eyes. I could not have created a better change record, this is for sure.

mortendk’s picture

this is überawesome :)

dawehner’s picture

The issue summary got updated in the meantime in #59

The last submitted patch, 58: 2574717-58.patch, failed testing.

stefan.r’s picture

Status: Needs review » Reviewed & tested by the community

Looks great

The last submitted patch, 20: 2574717-18.patch, failed testing.

The last submitted patch, 17: discuss_whether_we_want-2574717-17.patch, failed testing.

The last submitted patch, 57: 2574717-57.patch, failed testing.

The last submitted patch, 20: 2574717-18.patch, failed testing.

lauriii’s picture

RTBC++ & Sorry Drupal, Nyan Cats gonna be in your HEAD till forever!

The last submitted patch, 17: discuss_whether_we_want-2574717-17.patch, failed testing.

The last submitted patch, 57: 2574717-57.patch, failed testing.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

So long and thanks for all the kittens, PHPTemplate.

 ___________________________________________________________________________________________________________________
< Committed 1648376 and pushed to 8.0.x. Thanks! >
 -------------------------------------------------------------------------------------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

  • alexpott committed 1648376 on 8.0.x
    Issue #2574717 by dawehner, hussainweb, lauriii, pwolanin,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.