Render echarts tooltips with Lit templates#52235
Open
MindFreeze wants to merge 7 commits into
Open
Conversation
Replace raw HTML string interpolation in echarts tooltip formatters with Lit templates so user-controlled fields (entity friendly_name, device names, node labels) are auto-escaped instead of relying on per-string filterXSS. ha-chart-base now wraps any function tooltip.formatter into a stable per-formatter container and handles Lit TemplateResult / nothing / null returns; the public HaECOption type lets charts express Lit-returning formatters without per-callsite casts.
Resolve conflicts in ha-chart-base (_getSeries keeps log-scale handling and processSeriesTooltipFormatter) and energy-chart-options (compare suggestedMax extension from dev with HaECOption types).
bramkragten
reviewed
May 27, 2026
bramkragten
reviewed
May 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed change
Replace raw HTML string interpolation in every echarts tooltip formatter with Lit templates. User-controlled fields (entity
friendly_name, device names, node labels) now flow as Lit text expressions and are auto-escaped, removing the need for per-stringfilterXSS. statistics-chart.ts (the chart that prompted this) previously interpolatedparam.seriesNameinto HTML without any sanitization — that XSS vector is closed here.ha-chart-base.ts gains a central wrap pass: any function
tooltip.formatterit finds in the options or in series is wrapped so it can returnTemplateResult | typeof nothing | null, with the wrapper rendering into a stable per-formatter container and forwardingnull/nothingas a tooltip-suppress signal. New typed helpers in src/resources/echarts/ha-ec-option.ts (HaECOption,HaECSeries,HaTooltipOption,LitTooltipFormatter) let charts express Lit-returning formatters without per-callsiteas anycasts.Charts migrated: statistics, both state-history charts, sunburst, sankey, network-graph (and its bluetooth/zwave/zha callers), and all energy graph cards.
Screenshots
Type of change
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed:
To help with the load of incoming pull requests: