Skip to content

feat(icon): enable svg icons by default#1508

Open
chintankavathia wants to merge 1 commit intomainfrom
feat/enable/svg
Open

feat(icon): enable svg icons by default#1508
chintankavathia wants to merge 1 commit intomainfrom
feat/enable/svg

Conversation

@chintankavathia
Copy link
Member

BREAKING CHANGE: icons are now rendered as SVG by default instead of icon fonts.

Applications that rely on icon fonts must explicitly opt out by using:

provideIconConfig({ disableSvgIcons: true })

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the default icon rendering to use SVGs and cleans up demo app configuration. While a functional improvement, enabling SVG icons by default introduces a critical Cross-Site Scripting (XSS) vulnerability due to unsanitized SVG content. Furthermore, a critical issue with unit tests needs to be resolved.

const ICON_CONFIG = new InjectionToken<IconConfig>('ICON_CONFIG', {
providedIn: 'root',
factory: () => ({ disableSvgIcons: true })
factory: () => ({ disableSvgIcons: false })
Copy link
Contributor

Choose a reason for hiding this comment

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

security-medium medium

Enabling SVG icons by default exposes a potential Cross-Site Scripting (XSS) vulnerability. The parseDataSvgIcon function in projects/element-ng/icon/si-icons.ts uses DomSanitizer.bypassSecurityTrustHtml on SVG content without sanitization, bypassing Angular's XSS protection. This could allow malicious scripts if icon content originates from untrusted sources. Recommendation: Sanitize the SVG content (e.g., using DOMPurify) before passing it to bypassSecurityTrustHtml in si-icons.ts.

Furthermore, changing the default of disableSvgIcons to false breaks existing unit tests in projects/element-ng/icon/si-icon.component.spec.ts. These tests rely on the old default and need to be updated. Please modify the affected test suite to explicitly provide provideIconConfig({ disableSvgIcons: true }) to correctly test the non-default case.

Copy link
Member Author

Choose a reason for hiding this comment

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

@spike-rabbit @spliffone Do we ignore this?

Copy link
Member

Choose a reason for hiding this comment

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

No, I will provide something. We should have done this a long time ago.

Copy link
Member Author

Choose a reason for hiding this comment

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

Angular doesn't have its own way to sanitize svg content. So we must have to use some other 3rd party like DOMPurify.
Question is do we introduce DOMPurify as peerDep?

Copy link
Member

Choose a reason for hiding this comment

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

This does not work, as we need to support SSR here. In the beginning we werer using the DOMParser (which is basically the DOMPurify approach

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

font-awesome btw just bypasses as well.

Copy link
Member

Choose a reason for hiding this comment

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

based on my understanding of the code, https://github.com/kkomelin/isomorphic-dompurify will always load us JSDom into the browser

Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is a real issue, the majority of users will simply reference an existing icon from our package. In rare cases, the will provide an SVG icon by the self. In such a case we could simply improve the addIcon description that this scenario is risky and might cause potential cross site scripting problems

@chintankavathia chintankavathia force-pushed the feat/enable/svg branch 2 times, most recently from ab857f0 to 0d4293c Compare February 12, 2026 10:29
@github-actions
Copy link

github-actions bot commented Feb 12, 2026

@chintankavathia chintankavathia force-pushed the feat/enable/svg branch 4 times, most recently from 8ad19e0 to 88fb396 Compare February 12, 2026 15:24
@chintankavathia chintankavathia marked this pull request as ready for review February 12, 2026 15:54
@chintankavathia chintankavathia requested review from a team as code owners February 12, 2026 15:54
Copy link
Member

@spike-rabbit spike-rabbit left a comment

Choose a reason for hiding this comment

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

Lets wait if we can have the icons as CSS masks.

BREAKING CHANGE: icons are now rendered as SVG by default instead of icon fonts.

Applications that rely on icon fonts must explicitly opt out by using:
  ```ts
  provideIconConfig({ disableSvgIcons: true })
```
@github-actions
Copy link

Code Coverage

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants