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

IBX-5054: HTML code gets removed from the Custom tag's string attribute #71

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ class IbexaCustomTagEditing extends Plugin {
const domElement = this.toDomElement(domDocument);

domElement.innerHTML = Object.entries(modelElement.getAttribute('values')).reduce((total, [attribute, value]) => {
const attributeValue = value !== null ? value : '';
// Escaping
// <script>alert("Hello! I am a script!");</script> --> &lt;script&gt;alert("Hello! I am a script!");&lt;/script&gt;
const stringTempNode = domDocument.createElement('div');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about escaping without creating div?

const valueString = value ?? '';
const attributeValue = valueString
	.replace(/&/g, "&amp;")
        .replace(/</g, "&lt;")
        .replace(/>/g, "&gt;")
        .replace(/"/g, "&quot;")
        .replace(/'/g, "&#39;");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Escaping like I currently do seems to be quite common in JS. But if you prefer, I can change it as suggested. However, others have already approved it so not sure what others think of it.

I am not sure either if your suggestion covers all characters that needs to be escaped ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After talking with the frontend team, I approved for your solution :)

stringTempNode.appendChild(domDocument.createTextNode(value !== null ? value : ''));
const attributeValue = stringTempNode.innerHTML;

const ezvalue = `<span data-ezelement="ezvalue" data-ezvalue-key="${attribute}">${attributeValue}</span>`;

return `${total}${ezvalue}`;
Expand Down