-
Notifications
You must be signed in to change notification settings - Fork 823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix wysiwyg sanitisation #11201
Fix wysiwyg sanitisation #11201
Conversation
Also explicitly test both valid_elements and extended_valid_elements
18a835f
to
72692f9
Compare
*/ | ||
protected $settings = [ | ||
private static array $default_options = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've gone with default_options
as the name for this configuration because you usually interact with these by calling setOption()
or setOptions()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good, have tested locally. Having the img tag on valid_elements seems fine, I think part of why it was originally on extended_valid_elements along with iframe rather than valid_elements was that (if my memory serves me correctly), earlier versions of silverstripe would output img tags in some instances when 'Inserting from file', though more recent versions always use an image shortcode
iframe is still used when inserting external media i.e. youtube, so makes sense to keep that the extended elements list
// Default set of valid_elements which apply for all new configurations | ||
'valid_elements' => "@[id|class|style|title],a[id|rel|rev|dir|tabindex|accesskey|type|name|href|target|title" | ||
. "|class],-strong/-b[class],-em/-i[class],-strike[class],-u[class],#p[id|dir|class|align|style],-ol[class]," | ||
. "-ul[class],-li[class],br,img[id|dir|longdesc|usemap|class|src|border|alt=|title|hspace|vspace|width|height|align|name|data*]," |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
. "-ul[class],-li[class],br,img[id|dir|longdesc|usemap|class|src|border|alt=|title|hspace|vspace|width|height|align|name|data*]," | |
. "-ul[class],-li[class],br,img[id|dir|longdesc|usemap|class|src|border|alt|title|hspace|vspace|width|height|align|name|data*]," |
Is that a typo with the = for alt?
Do we want name, hspace, space for the old extended_valid_elements from admin that's being deleted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that a typo with the = for alt?
The =
is correct, as per https://www.tiny.cloud/docs/tinymce/latest/content-filtering/#valid_elements
Basically, it's defaulting to including a blank alt
property for all images which don't have a specific alt text defined for them, which is correct for accessibility.
Do we want name, hspace, space for the old extended_valid_elements from admin that's being deleted?
It's only being deleted because I've moved those here. They seem safe, so I'd be inclined to keep them here. If you have a specific reason not to, I can move them back to extended_valid_elements
in the "cms" config where they have previously lived.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want name, hspace, space for the old extended_valid_elements from admin that's being deleted?
Sorry I'm blind, somehow I managed to not noticed they're copied over. Yes keep them as is in this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just retesting this not working as expected, I feel like I'm doing something wrong here
<?php
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
class Page extends SiteTree
{
private static $db = [
'SomeContent' => 'HTMLText'
];
public function getCMSFields()
{
$fields = parent::getCMSFields();
# doesn't allow any tags except p,ul,li
$h = $fields->dataFieldByName('Content');
$c = $h->getEditorConfig();
$c->setOption('valid_elements', "@[id|class|style|title],a[id|rel|rev|dir|tabindex|accesskey|type|name|href|target|title"
. "|class],-strong/-b[class],-em/-i[class],-strike[class],-u[class],#p[id|dir|class|align|style],-ol[class],"
. "-ul[class],-li[class],br,img[id|dir|longdesc|usemap|class|src|border|alt=|title|width|height|align|data*],"
. "-sub[class],-sup[class],-blockquote[dir|class],-cite[dir|class|id|title],"
. "-table[cellspacing|cellpadding|width|height|class|align|summary|dir|id|style],"
. "-tr[id|dir|class|rowspan|width|height|align|valign|bgcolor|background|bordercolor|style],"
. "tbody[id|class|style],thead[id|class|style],tfoot[id|class|style],"
. "#td[id|dir|class|colspan|rowspan|width|height|align|valign|scope|style],"
. "-th[id|dir|class|colspan|rowspan|width|height|align|valign|scope|style],caption[id|dir|class],"
. "-div[id|dir|class|align|style],-span[class|align|style],-pre[class|align],address[class|align],"
. "-h1[id|dir|class|align|style],-h2[id|dir|class|align|style],-h3[id|dir|class|align|style],"
. "-h4[id|dir|class|align|style],-h5[id|dir|class|align|style],-h6[id|dir|class|align|style],hr[class],"
. "dd[id|class|title|dir],dl[id|class|title|dir],dt[id|class|title|dir]");
$h->setEditorConfig($c);
# works correctly
$h2 = HTMLEditorField::create('SomeContent');
$c2 = $h2->getEditorConfig();
$c2->setOption('valid_elements', 'p,ul,li');
$h2->setEditorConfig($c2);
$fields->addFieldsToTab('Root.Main', [$h2]);
return $fields;
}
}
Looks like you've uncovered a completely new bug 🥳 To test, in a fresh installation without any of these PRs and without your configuration above, add a link to a page and save. Then, add only the second config you have there (i.e. add If you can reproduce that with a fresh installation, it's a separate bug and should be handled in a separate card (and probably fixed in |
Yup validated it's an existing issue, have raised card |
Description
There are multiple commits here since we're doing several related but separate changes:
valid_elements
andextended_valid_elements
separatelyvalid_elements
set would result in skipping validation entirely.valid_elements
settings for any new TinyMCE config instancesIssues
extended_valid_elements
on a custom Config. #11141