Problem/Motivation
There are at least 2 aspects that prove that this functionality has never worked as intended (it's broken in such a way that it is very unlikely that anyone has ever used it):
FilterFormat::getHTMLRestrictions()computes the combined HTML restrictions across all filters, but doesn't correctly handle the case of using both theallowed(allowlist) andforbidden_tags(blocklist) aspects ofFilterInterface::getHTMLRestrictions:
👉 #3271698: getHtmlRestrictions() ignores 'allowed_tags' settings if the first filter checked only provides 'forbidden_tags'- The one filter that uses the
forbidden_tagsfunctionality does not actually work and is part of a test module but no test actually uses it to forbid tags:
👉 #3271706: FilterFormat getHtmlRestrictions forbidden_tags expects different structure than the one provided by FilterTestRestrictTagsAndAttributes + #3231331: [PP-1] Generate test data compatible with interface in Drupal\filter_test\Plugin\Filter\FilterTestRestrictTagsAndAttributes::getHTMLRestrictions
Furthermore, a key security best practice to our knowledge is to use allowlists instead of blocklists.
Marked Major
because it impacts the upgrade path from ckeditor.module (CKEditor 4) to ckeditor5.module (CKEditor 5): #3231336: Simplify HtmlRestrictions and FundamentalCompatibilityConstraintValidator now that "forbidden tags" are deprecated.
Proposed resolution
Because of the three points above, @bnjmnm and I wondered if it even makes sense to fix the two three bugs. Clearly nobody is using it.
Therefore we propose to deprecate this (obscure) functionality in Drupal 9.4 and remove it in Drupal 10.0.
This would allow us to close two bugs and be a net win for Drupal's security.
Remaining tasks
- ✅
Ask backend framework manager and release manager @catch for his input.👉 He responded:
@wimleers (he/him) I can't ever remember a filter that only disallows tags, if we want to remove, it's easy to deprecate in 9.4.x and remove in 10.0.x - can't really see a reason not to.
- ✅
Deprecate the returning offorbidden_tagsby a filter'sgetHTMLRestrictions()in 9.4.
👉 #5 - ✅
Remove the "forbidden tags" functionality fromFilterTestRestrictTagsAndAttributesin both Drupal 9.4 and 10.0, because it is not used anyway.
👉 #6
User interface changes
None.
API changes
- Drupal 9.4: any filter plugin's
getHTMLRestrictions()that returns a top-levelforbidden_tagskey will result in a deprecation notice. - Drupal 10.0: any filter plugin's
getHTMLRestrictions()that returns a top-levelforbidden_tagskey will result in an exception.
Data model changes
None.
Release notes snippet
TBD
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | 3272516-removal-D10-24.patch | 18.63 KB | wim leers |
| #24 | interdiff-removal-D10.txt | 5.18 KB | wim leers |
| #21 | 3272516-deprecation-9.4-21.patch | 4.92 KB | wim leers |
| #21 | interdiff-deprecation-9.4-17-21.txt | 1.88 KB | wim leers |
| #17 | 3272516-deprecation-9.4-17.patch | 3.07 KB | wim leers |
Comments
Comment #4
wim leersPaired with @bnjmnm in writing the issue summary! 🚀
Comment #5
wim leersThis is the baseline patch — should work for both 9.4 and 10.0. But for 10.0, we need more changes. That will happen in the next patch.
Comment #6
wim leersThis is what we expect to happen for
10.0.x.Comment #7
wim leersComment #8
wim leersLanguage clarifications.
Comment #9
wim leersFound another bug that we could close thanks to this: #3231331: [PP-1] Generate test data compatible with interface in Drupal\filter_test\Plugin\Filter\FilterTestRestrictTagsAndAttributes::getHTMLRestrictions — this was also filed thanks to the work on CKEditor 5, nobody else had discovered this for nearly a decade. So: doing this will close three bugs now!
Comment #10
yogeshmpawarReroll patch with reroll diff.
Comment #12
yogeshmpawarUpdated FilterAPITest.php as per FilterFormat.php changes.
Comment #13
catch9.4.x patch:
Are there any docs we need to update too or is this an undocumented feature? Also could use a @grou
Is this completely untested then apart from this test code that doesn't look excercised? Was going to say we should add @group legacy coverage, but that might be optional if it's completely untested and undocumented.
Comment #14
catchNeeds a (deprecated) note in the 9.4.x patch.
Comment #15
wim leers#13:
\Drupal\filter\Plugin\FilterInterface::getHTMLRestrictions(). Update docs. And added a deprecation test.And if I'd also enable
filter_htmlfor this test, you'd get anUndefined index: allowedPHP error too 😅Comment #16
wim leers👆 d.o decided to post my comment even though I was just attaching files. 😬
Comment #17
wim leersThat's now been proven by
3272516-deprecation-9.4-16.patchabove 🤓The "removal-10.0" patch from #16 is still relevant, no update needed.
Comment #19
bnjmnmFeedback on the D10 patch 1 of 2. My next step will be applying the patch to core locally and seeing if there's anything additional to remove or rephrase.
This "only supports" clarification is misleading now that 'allowed' is the only supported key.
I noticed
FilterAPITestwas updated to reflect this removal, but should this actually be removed? It's a condition that is true when$restrictions['forbidden_tags']is not present, so wouldn't we just remove the<code>isset($restrictions['forbidden_tags'])in the condition chain, but otherwise keep this the sameIt could be argued 'allowed' is still *optional*, because there won't be an error if it isn't present. That's not particularly helpful, though. It should communicate that 'allowed' needs to be present for the filter to be of any use.
Comment #20
bnjmnmD10 patch review 2 of 2, while installed on local core:
\Drupal\ckeditor\Plugin\CKEditorPlugin\Internalhas forbidden tags logicIt looks like this might suggest an even larger LOC-removal opportunity in this class?
generateACFSettingsmight have it's return structure changed?\Drupal\editor\EditorXssFilter\Standard::filterXssreferences 'forbidden' in a manner that is no longer accurate since a text format does not forbid tags anymore:\Drupal\filter_test\Plugin\Filter\FilterTestRestrictTagsAndAttributesis still there. It seems like it (and its corresponding schema) is quite removable since it is not actually used by tests in 9.x either.Comment #21
wim leers#17 failed because there's a test case in
ValidatorsTesttriggering the deprecation. I think it's reasonable to just remove it.Comment #22
bnjmnmSetting to "Needs work" for visibility #21 fixes a test failure, but the feedback in #19-#20 needs to be addressed. (at least according to the interdiff)
Comment #23
wim leersLost track of this 🙈 On it now.
Comment #24
wim leers#19:
#20:
forbidden_tagsaspect of it. Removed those aspects. Theallowedaspect of it is being used in the following tests:\Drupal\Tests\ckeditor\Kernel\CKEditorTest::testGetJSSettings(),\Drupal\Tests\filter\Kernel\FilterAPITest::testFilterFormatAPI(),\Drupal\Tests\filter\Kernel\FilterAPITest::testDependencyRemoval()Comment #25
bnjmnm#19 and #20 are either addressed or theres a good explanation as to why not. Lets move this to the next stage.
Comment #27
catchCommitted/pushed the respective patches to to 10.x and 9.4.x, thanks!
Comment #29
martijn de witThink this can also be commit in 9.5.x :)
Comment #30
wim leersClosed #3271698: #3271698-6: getHtmlRestrictions() ignores 'allowed_tags' settings if the first filter checked only provides 'forbidden_tags'.
I think this also needs a change record. Did that: https://www.drupal.org/node/3278325.
Comment #31
wim leers@Martijn: 9.5.x has not yet been opened yet!
Comment #33
catch@Wim Leers: yes it has! But I forgot - first commit since it opened and the muscle memory for 10.0.x -> 9.4.x is still there. Cherry-picked there too.
Comment #34
wim leers:O I actually went and checked the Gitlab UI and it didn't list it 🤔