Skip to content

Reusable shared utility package for sanitize html functionality - #34933

Open
rbondesson wants to merge 19 commits into
element-hq:developfrom
ZacksBot:feature/shared-utils
Open

Reusable shared utility package for sanitize html functionality#34933
rbondesson wants to merge 19 commits into
element-hq:developfrom
ZacksBot:feature/shared-utils

Conversation

@rbondesson

@rbondesson rbondesson commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Checklist

  • I have read through review guidelines and CONTRIBUTING.md.
  • I have linked the PR to an issue that describes what needs changing.
  • I have written tests for new code (and old code if feasible).
  • I have ensured new or updated public/exported symbols have accurate TSDoc documentation.
  • I have confirmed linter and other CI checks pass.
  • I have have included screenshots if what the user sees will change
  • I have licensed the changes to Element by completing the Contributor License Agreement (CLA)
  • I will no longer force push to this branch

Summary

Implements a shared utility package, https://github.com/element-hq/integrations-internal/issues/76

Changes

  • Added the new published package @element-hq/element-web-shared-utils.
  • Extracted Matrix-compatible HTML sanitization and permitted URL validation from Element Web.
  • Refactored Element Web HTML consumers to use the shared package while retaining app-specific linkification and rendering transforms.
  • Added the package to Element Web dependencies and the npm publish workflow.

@rbondesson rbondesson self-assigned this Sep 4, 2026
@rbondesson rbondesson added the T-Task Tasks for the team like planning label Sep 4, 2026
// rather than applying the message MXC-only transform.
"img",
// Disable the default transformer as it forbids inline styles
// Embedded pages intentionally retain inline styles.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment changes look a bit odd?

@rbondesson rbondesson Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since the objectExluding was redundant the comments have been moved and updated. Better now?

@Half-Shot Half-Shot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks all okay to me

Comment on lines +142 to +143
"img": (tagName: string, attribs: HtmlSanitizeAttributes) => ({ tagName, attribs }),
"*": (tagName: string, attribs: HtmlSanitizeAttributes) => ({ tagName, attribs }),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we have the objectExcluding call above if we just overwrite them anyway?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the redundant objectExcluding and updated the comments.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why was this change necessary at all, why did objectExcluding not work?

@rbondesson rbondesson Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The extracted shared sanitizer now has resctrictive defaults, compared to before. Using objectExcluding would now mean “use shared defaults,” not “disable transforms” as it did before. Added a comment about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-Task Tasks for the team like planning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants