Skip to content
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

editor.insert could not insert custom html tags #901

Closed
fedot199614 opened this issue Nov 7, 2022 · 4 comments · Fixed by #925
Closed

editor.insert could not insert custom html tags #901

fedot199614 opened this issue Nov 7, 2022 · 4 comments · Fixed by #925
Labels
Milestone

Comments

@fedot199614
Copy link

fedot199614 commented Nov 7, 2022

i try to insert custom html tag <lottie-player>Test</lottie-player> but it inserts only text - Test.
olso i try wysiwygEditorInsertHtml - but no effect.
text area are emty - <p><br></p>
image

@samclarke samclarke added the Bug label Nov 8, 2022
@samclarke samclarke added this to the v3.2.0 milestone Nov 8, 2022
@samclarke
Copy link
Owner

Thanks for reporting!

This is caused by the filtering done to prevent XSS. Before HTML is inserted into the editor it's filtered using DOMPurify. It looks like DOMPurify removes all custom elements by default.

Fixing this will probably require a new configuration option to specify allowed custom elements.

@fedot199614
Copy link
Author

thanks, i add in my SCEditor build new options allowedTags, allowedAttributes
and make something like this
` /**
* Sanitize HTML to avoid XSS
*
* @param {string} html
* @return {string} html
* @Private
*/
function sanitize(html) {

	const allowedTags = ['iframe'].concat(options.allowedTags);
	const allowedAttr = ['allowfullscreen', 'frameborder', 'target']
		.concat(options.allowedAttributes);

	return domPurify.sanitize(html, {
		ADD_TAGS: allowedTags,
		ADD_ATTR: allowedAttr
	});
};`

and it's works

@samclarke
Copy link
Owner

That looks great. If you want to make a PR, it can be merged into the code base.

@codertushar
Copy link
Contributor

codertushar commented Feb 20, 2023

@samclarke @fedot199614 Please review my PR: #925
I need this ASAP. It is breaking my existing functionality when I moved to a newer version of SCEditor.

samclarke added a commit that referenced this issue Feb 20, 2023
Fixes #901

---------

Co-authored-by: Sam <sam@samclarke.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants