Problem/Motivation
See #2566503: [meta] Replace remaining !placeholder for Non-URL HTML outputs only
Date stuff.
Look out for format_date() and 'date.formatter' => format() and maybe variables assigned with the result of those two values.
Note: Currently the result of that is xss filtered, so actually not marked as safe, mhhh.
Proposed resolution
HTML support in date formats in questionable. Firstly there is the fact that these values are using in attributes. Secondly there is the possibility of adding HTML where it really is not expected.
The one remaining question is do translators have a need to add HTML to a date format string?
Remaining tasks
Agree that removing HTML support makes sense.
User interface changes
None
API changes
Date format strings no longer support adding HTML using the \ escape character.
Data model changes
None
Beta phase evaluation
| Issue category | Bug because at the moment date formats support HTML but it is escaped |
|---|---|
| Issue priority | Major because part of the critical to remove !placeholder |
| Disruption | Disruptive for existing sites that are adding HTML to date formats. If HTML is required in a formatted date then the site should implement a custom field formatter to do this. |
| Comment | File | Size | Author |
|---|---|---|---|
| #45 | remove_html_support-2568613-45.patch | 9.21 KB | lauriii |
| #42 | interdiff.txt | 1.2 KB | lauriii |
| #42 | remove_html_support-2568613-42.patch | 10.49 KB | lauriii |
| #34 | interdiff.txt | 1.74 KB | lauriii |
| #34 | remove_html_support-2568613-34.patch | 10.78 KB | lauriii |
Comments
Comment #2
alexpottComment #3
dawehnerUps.
Comment #4
alexpottHere's a first cut at finding them...
Comment #5
alexpottWhoops
Comment #6
dawehnerI searched using
(yes that is horrible)
Didn't we excluded views?
Comment #7
dawehnerFair point, this is about date formatting, so let's deal with that.
Comment #8
xjmI thought these were the results of a
format_plural(), but the summary indicates otherwise. Can we get some manual testing that the escaping is correct when a date format includes special characters, screenshot, documentation of test coverage?Comment #9
sutharsan commentedThe date format is double escaped in the title tag. See screenshots. Though it is not likely to occur. To reproduce:
Comment #10
alexpottSo I thought I broke this when we removed the SafeMarkup XSS stuff... however this line:
Is from #2003934: Convert format_date to a service and predates safe markup. Ah but I did break it. I broke it when we stopped Xss::filter() from marking things as safe. If we want to be able to put markup in date formats then we need to make this return an object that implements SafeStringInterface. So now the question has to be is there any case for markup. I guess the presence of
Xss::filter()suggests there is. However its not there in D7 ... so what issue introduced it... #1892640: XSS in date formats admin page . Hmm the comment about being clear about whether something has HTML or not is quite pertinent.Comment #11
alexpottHere's an implementation the pushes the XSS security to the correct level and adds a test.
Comment #14
alexpottFixing the tests... looks like Attribute filtering could be important.
Comment #15
alexpottComment #18
alexpottHmmm... I'm really not sure that we should be allowing markup here.
Comment #19
mpdonadioI can see the use case of allowing HTML in custom format strings, eg to allow date and time to be styled separately, but I see this as an edge case and it can also be solved with a custom formatter (which aren't that hard to make in Drupal 8). Site builders may be at a small disadvantage, but I still see this as an edge case.
So, I am totally on board with not allowing HTML here.
Comment #20
larowlanagree, we should filter out markup characters and recommend formatters now that they're a single file plugin (in D7 the effort wasn't worth it)
Comment #21
alexpottYes ordinary text but, no, not HTML :)
Comment #22
alexpottComment #23
alexpottComment #24
alexpottDiscussed with @GaborHojtsy in IRC
And this is coming from a Hungarian which does not have the simplest date format rules...
See https://en.wikipedia.org/wiki/Date_format_by_country
Scanning https://en.wikipedia.org/wiki/Date_format_by_country I can not see any date format there that requires HTML to be achieved on the browser... perhaps Norway's fractional date...
Comment #25
wizonesolutionsI wouldn't say Norway is a consideration for this. As Wikipedia says, the fractional date format is incorrect. On top of that, I can't recall any instances of having seen it in print. I see it handwritten occasionally, probably for brevity, but I don't think any Norwegian developers would be blocked by not being able to do this in core.
Comment #26
eiriksmSecond the comment about the fractional version in Norway. I would say it is exclusively a handwriting thing in Norway, and I have never seen it used on a screen like that. Although d/m would be a common use, which would still work nicely.
Comment #27
alexpottThis is part of the critical meta.
Comment #28
dawehnerAs long we can make things swappable so in case someone really wants to, they could return a SafeStringInterface, I think its fair to remove the support for it in core.
Comment #29
joelpittetWhat tags are we expecting that this needs to be stripped? Why not let them escape to leave this alone?
@dawehner re #28 That sounds like a nice idea. Can we currently swap this out now or do we need to convert DrupalDateTime to a service to make it swappable? In that case we'd need a CR, I'd expect?
@lauriii was mentioning to me that it's a value object and shouldn't be a service so I don't know how we would make this swappable? Any suggestions, maybe a hook in format?
Comment #30
dawehner@joelpittet
Well, DrupalDateTime is both a value object and it contains the logic to actually render the thing. You know, this is why I was pushing against putting logic into the TranslationWrapper for example. The value object (whether we use it in the strict sense or not) is there to provide a schematic helpful piece of information.
PS: DateTimePlus has a protected
render()method, that conflicts with the method in theToStringTraitComment #31
pwolanin commentedLet me do some work on this.
Comment #32
pwolanin commentedI agree with @joelpittet that we should not stip tags, but rather let them be escaped. Discussed with @alexpott too.
I don't think we need to make the patch more complex, but I did also fix the bug dawehner mentioned where we were showing a PHP error by trying to override a public method to protected.
I don't think adding more swappability is in scope for this issue. Sounds like 8.1.
Comment #33
xanoIf we want to allow (and not implement) returning
SafeStringInterfaceany time during the D8 lifecycle, we must document it before 8.0.0 comes out, or it will be a BC break.If we want to allow (and not implement) returning
SafeStringInterfaceany time during the D8 lifecycle, we must document it before 8.0.0 comes out, or it will be a BC break.Empty comment.
Comment #34
lauriiiComment #35
cpj commentedComment #36
cpj commentedI've reviewed the changes and it looks fine to me. So I'm going to mark it RTBC
Comment #37
dawehnerIMHO this is still kinda a lie, isn't it? DateTimePlus always returns a string due to the usage of
$value = preg_replace_callback('/\xEF([AaeDlMTF]?)(.*?)\xFF/', $translation_callback, $format);Does someone mind giving some extra lights for me why this happens?
Comment #38
alexpott@dawehner it was because what @Xano wrote in #33. Personally I think those changes should be rolled back. The returns should not specify something they do not do.
Comment #39
alexpottCan someone create a followup to implement a DateFormatterInterface so that the DateFormatter service is at least swappable.
Comment #40
mpdonadioCreated #2571647: Create DateFormatterInterface. I'll have a patch ready tonight or tomorrow, and will handle any re-rolls of it b/c doc changes here.
Comment #41
vijaycs85#39: Created
#2571657: Create DateFormatterInterface so that core DateFormatter is swappable.#2571647: Create DateFormatterInterfaceComment #42
lauriiiComment #43
dawehnerThank you @lauriii
Comment #45
lauriiiRerolled the patch
Comment #46
stefan.r commentedchecked the interdiff and reroll looks good
Comment #48
effulgentsia commentedPushed to 8.0.x, but I'm not sure if this needs a change record. I think this restores 8.0.x to the same behavior with respect to date formats that 7.x has. And I don't know when the last time HTML in date formats actually worked in D8 HEAD, but it might be worth searching through existing change records to see if HTML-in-date-formats was ever mentioned, and at least correcting that. And maybe a new CR explicitly mentioning the change here makes sense too. Setting to "needs review" rather than "needs work", since I don't know if any changes or a new CR is needed.
Comment #49
alexpottThere is no harm in having a CR to say this is no longer supported - created https://www.drupal.org/node/2572299